Skip to content

Commit

Permalink
Merge pull request #76 from andrewpope/master
Browse files Browse the repository at this point in the history
Recalculate card positions on layout to handle rotation
  • Loading branch information
Benoît Delmaire authored Jun 5, 2017
2 parents 8e8800a + fdbce54 commit 1754783
Showing 1 changed file with 7 additions and 1 deletion.
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

0 comments on commit 1754783

Please sign in to comment.