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

Recalculate card positions on layout to handle rotation #76

Merged
merged 3 commits into from
Jun 5, 2017
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
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ export default class Carousel extends Component {
oldItemIndex: this._getFirstItem(props.firstItem)
};
this._positions = [];
this._calcCardPositions(props);
this._onTouchStart = this._onTouchStart.bind(this);
this._onScroll = this._onScroll.bind(this);
this._onScrollEnd = this._snapEnabled ? this._onScrollEnd.bind(this) : false;
this._onScrollBegin = this._snapEnabled ? this._onScrollBegin.bind(this) : false;
this._initInterpolators = this._initInterpolators.bind(this);
this._onTouchRelease = this._onTouchRelease.bind(this);
this._onLayout = this._onLayout.bind(this);
// This bool aims at fixing an iOS bug due to scrolTo that triggers onMomentumScrollEnd.
// onMomentumScrollEnd fires this._snapScroll, thus creating an infinite loop.
this._ignoreNextMomentum = false;
Expand Down Expand Up @@ -361,6 +361,11 @@ export default class Carousel extends Component {
}
}

_onLayout (event) {
this._calcCardPositions();
this.snapToItem(this.state.activeItem, false, true, false);
}

_snapScroll (deltaX) {
const { swipeThreshold } = this.props;

Expand Down Expand Up @@ -552,6 +557,7 @@ export default class Carousel extends Component {
onResponderRelease={this._onTouchRelease}
onScroll={this._onScroll}
onTouchStart={this._onTouchStart}
onLayout={this._onLayout}
>
{ this._childSlides() }
</ScrollView>
Expand Down