Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update height when window is being resized #540

Merged
merged 2 commits into from
Dec 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/react-swipeable-views/src/SwipeableViews.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ class SwipeableViews extends React.Component {

startIndex = 0;

resizeListener = null;

transitionListener = null;

touchMoveListener = null;
Expand Down Expand Up @@ -263,6 +265,15 @@ class SwipeableViews extends React.Component {
}

componentDidMount() {
// Subscribe to resize events and update height if animateHeight param is set.
this.resizeListener = addEventListenerEnhanced(window, 'resize', () => {
if (!this.props.animateHeight) {
return;
}

this.updateHeight();
});

// Subscribe to transition end events.
this.transitionListener = addEventListenerEnhanced(
this.containerNode,
Expand Down Expand Up @@ -326,6 +337,7 @@ class SwipeableViews extends React.Component {
}

componentWillUnmount() {
this.resizeListener.remove();
this.transitionListener.remove();
this.touchMoveListener.remove();
clearTimeout(this.firstRenderTimeout);
Expand Down