Skip to content

Commit 2efaabc

Browse files
committed
Fix issue with Carousel's containerWidth being reset and throw an exception (#1769)
1 parent 2d3894d commit 2efaabc

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/components/carousel/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,15 +273,19 @@ class Carousel extends Component<CarouselProps, CarouselState> {
273273
layout: {width: containerWidth, height: containerHeight}
274274
}
275275
}: LayoutChangeEvent) => {
276-
const {pageWidth = containerWidth, pageHeight = containerHeight} = this.props;
276+
const {pageWidth = containerWidth, pageHeight = containerHeight, horizontal} = this.props;
277277

278278
const initialOffset = presenter.calcOffset(this.props, {
279279
currentPage: this.state.currentPage,
280280
pageWidth,
281281
pageHeight
282282
});
283283

284-
this.setState({containerWidth, pageWidth, pageHeight, initialOffset});
284+
// NOTE: This is to avoid resetting containerWidth to 0 - an issue that happens
285+
// on Android in some case when onLayout is re-triggered
286+
if ((horizontal && containerWidth) || (!horizontal && containerHeight)) {
287+
this.setState({containerWidth, pageWidth, pageHeight, initialOffset});
288+
}
285289
};
286290

287291
onMomentumScrollEnd = () => {

0 commit comments

Comments
 (0)