Skip to content

Commit 41b35c6

Browse files
committed
fix: height animation with keepViewsMounted
1 parent 86e9cac commit 41b35c6

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

demo/examples/SignupDemo.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const SignupDemo = ({ classes }: Props): React.Node => {
8282
</Button>
8383
<div className={classes.contentHolder}>
8484
<Paper className={classes.paper}>
85-
<ViewSlider animateHeight spacing={1.2}>
85+
<ViewSlider animateHeight keepViewsMounted spacing={1.2}>
8686
{content}
8787
</ViewSlider>
8888
</Paper>

src/index.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ export default class ViewSlider extends React.Component<Props, State> {
171171
// phase 1: set current height
172172
newState = {
173173
height: this.measureHeight(this.views[this.state.activeView]),
174+
numViews: Math.max(this.state.numViews, activeView + 1),
174175
}
175176
} else if (this.state.height !== undefined && !this.state.transitioning) {
176177
// phase 2: enable transitions
@@ -253,6 +254,10 @@ export default class ViewSlider extends React.Component<Props, State> {
253254
if (rtl) style.marginRight = `${(spacing - 1) * 100}%`
254255
else style.marginLeft = `${(spacing - 1) * 100}%`
255256
}
257+
if (!transitioning && activeView !== index) {
258+
style.height = 0
259+
style.overflow = 'hidden'
260+
}
256261

257262
// when not transitioning, render empty placeholder divs before the active view to push it into the right
258263
// horizontal position
@@ -281,9 +286,8 @@ export default class ViewSlider extends React.Component<Props, State> {
281286
}
282287

283288
animateHeight = (): boolean => {
284-
const { animateHeight, fillParent, keepViewsMounted } =
285-
this.getDefaultedProps()
286-
return animateHeight && !fillParent && !keepViewsMounted
289+
const { animateHeight, fillParent } = this.getDefaultedProps()
290+
return animateHeight && !fillParent
287291
}
288292

289293
rootRef = (node: ?React.ElementRef<'div'>) => {

0 commit comments

Comments
 (0)