Skip to content

Commit c42e199

Browse files
Inbal-Tishethanshar
authored andcommitted
fix wrong page on orientation change (#604)
1 parent af920fc commit c42e199

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/components/carousel/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ export default class Carousel extends BaseComponent {
107107

108108
onOrientationChanged = () => {
109109
if (!this.props.pageWidth || this.props.loop) {
110+
this.orientationChange = true;
110111
// HACK: setting to containerWidth for Android's call when view disappear
111112
this.setState({pageWidth: this.state.containerWidth || Constants.screenWidth});
112-
this.goToPage(this.state.currentPage, true);
113113
}
114114
};
115115

@@ -205,8 +205,11 @@ export default class Carousel extends BaseComponent {
205205
const offsetX = event.nativeEvent.contentOffset.x;
206206

207207
if (offsetX >= 0) {
208-
const newPage = presenter.calcPageIndex(offsetX, this.props, pageWidth);
209-
this.setState({currentPage: newPage});
208+
if (!this.orientationChange) { // Avoid new calculation on orientation change
209+
const newPage = presenter.calcPageIndex(offsetX, this.props, pageWidth);
210+
this.setState({currentPage: newPage});
211+
}
212+
this.orientationChange = false;
210213
}
211214

212215
if (loop && presenter.isOutOfBounds(offsetX, this.props, pageWidth)) {

0 commit comments

Comments
 (0)