Skip to content

Commit

Permalink
fix: height animation with keepViewsMounted
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards1211 committed Apr 11, 2024
1 parent 86e9cac commit 41b35c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion demo/examples/SignupDemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const SignupDemo = ({ classes }: Props): React.Node => {
</Button>
<div className={classes.contentHolder}>
<Paper className={classes.paper}>
<ViewSlider animateHeight spacing={1.2}>
<ViewSlider animateHeight keepViewsMounted spacing={1.2}>
{content}
</ViewSlider>
</Paper>
Expand Down
10 changes: 7 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export default class ViewSlider extends React.Component<Props, State> {
// phase 1: set current height
newState = {
height: this.measureHeight(this.views[this.state.activeView]),
numViews: Math.max(this.state.numViews, activeView + 1),
}
} else if (this.state.height !== undefined && !this.state.transitioning) {
// phase 2: enable transitions
Expand Down Expand Up @@ -253,6 +254,10 @@ export default class ViewSlider extends React.Component<Props, State> {
if (rtl) style.marginRight = `${(spacing - 1) * 100}%`
else style.marginLeft = `${(spacing - 1) * 100}%`
}
if (!transitioning && activeView !== index) {
style.height = 0
style.overflow = 'hidden'
}

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

animateHeight = (): boolean => {
const { animateHeight, fillParent, keepViewsMounted } =
this.getDefaultedProps()
return animateHeight && !fillParent && !keepViewsMounted
const { animateHeight, fillParent } = this.getDefaultedProps()
return animateHeight && !fillParent
}

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

0 comments on commit 41b35c6

Please sign in to comment.