diff --git a/src/components/carousel/index.tsx b/src/components/carousel/index.tsx index 1d1748da61..2a2d99c70f 100644 --- a/src/components/carousel/index.tsx +++ b/src/components/carousel/index.tsx @@ -273,7 +273,7 @@ class Carousel extends Component { layout: {width: containerWidth, height: containerHeight} } }: LayoutChangeEvent) => { - const {pageWidth = containerWidth, pageHeight = containerHeight} = this.props; + const {pageWidth = containerWidth, pageHeight = containerHeight, horizontal} = this.props; const initialOffset = presenter.calcOffset(this.props, { currentPage: this.state.currentPage, @@ -281,7 +281,11 @@ class Carousel extends Component { pageHeight }); - this.setState({containerWidth, pageWidth, pageHeight, initialOffset}); + // NOTE: This is to avoid resetting containerWidth to 0 - an issue that happens + // on Android in some case when onLayout is re-triggered + if ((horizontal && containerWidth) || (!horizontal && containerHeight)) { + this.setState({containerWidth, pageWidth, pageHeight, initialOffset}); + } }; onMomentumScrollEnd = () => {