From 76a13efbaf02cfdf9f157acb43dbbfdab1e96722 Mon Sep 17 00:00:00 2001 From: andy-pope Date: Mon, 5 Jun 2017 06:33:37 +0100 Subject: [PATCH 1/3] Recalculate card positions on layout to handle rotation --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index c6246767c..81ccc9f38 100644 --- a/index.js +++ b/index.js @@ -552,6 +552,7 @@ export default class Carousel extends Component { onResponderRelease={this._onTouchRelease} onScroll={this._onScroll} onTouchStart={this._onTouchStart} + onLayout={this._calcCardPositions()} > { this._childSlides() } From fdbc09b1495daecc0e347aab246e1f10b79ee090 Mon Sep 17 00:00:00 2001 From: andy-pope Date: Mon, 5 Jun 2017 07:10:45 +0100 Subject: [PATCH 2/3] Tidied into separate function and added snapToItem to ensure current position is correct --- index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 81ccc9f38..ab55d5d1d 100644 --- a/index.js +++ b/index.js @@ -153,6 +153,7 @@ export default class Carousel extends Component { 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; @@ -361,6 +362,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; @@ -552,7 +558,7 @@ export default class Carousel extends Component { onResponderRelease={this._onTouchRelease} onScroll={this._onScroll} onTouchStart={this._onTouchStart} - onLayout={this._calcCardPositions()} + onLayout={this._onLayout} > { this._childSlides() } From fdbce54dd9ca3f876e0e65c74d653c85b7eb44ca Mon Sep 17 00:00:00 2001 From: andy-pope Date: Mon, 5 Jun 2017 07:19:47 +0100 Subject: [PATCH 3/3] Initial calculation not needed, handled by onLayout --- index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/index.js b/index.js index ab55d5d1d..9753baa6c 100644 --- a/index.js +++ b/index.js @@ -146,7 +146,6 @@ 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;