Skip to content

Commit

Permalink
Fix issue with Carousel's containerWidth being reset and throw an exc…
Browse files Browse the repository at this point in the history
…eption (#1769)
  • Loading branch information
ethanshar committed Jan 10, 2022
1 parent 2d3894d commit 2efaabc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/components/carousel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,19 @@ class Carousel extends Component<CarouselProps, CarouselState> {
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,
pageWidth,
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 = () => {
Expand Down

0 comments on commit 2efaabc

Please sign in to comment.