Skip to content

Commit

Permalink
refactor(Carousel): guard against animated component being unmonted b…
Browse files Browse the repository at this point in the history
…efore its parent

See facebook/react-native#10635
  • Loading branch information
bd-arc committed Sep 22, 2017
1 parent de6588d commit 8b65fb7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/carousel/Carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,14 @@ export default class Carousel extends Component {
animated: false
};

this._flatlist.scrollToOffset({
this._flatlist && this._flatlist.scrollToOffset({
offset: offset + (direction === 'start' ? -1 : 1),
...commonOptions
});

this._hackSlideAnimationTimeout = setTimeout(() => {
this._flatlist.scrollToOffset({
// https://github.com/facebook/react-native/issues/10635
this._flatlist && this._flatlist._listRef && this._flatlist.scrollToOffset({
offset: offset,
...commonOptions
});
Expand Down Expand Up @@ -606,7 +607,7 @@ export default class Carousel extends Component {
const { data, enableMomentum, onSnapToItem } = this.props;
const itemsLength = data.length;

if (!itemsLength || !this._flatlist) {
if (!itemsLength || !this._flatlist || !this._flatlist._listRef) {
return;
}

Expand Down

0 comments on commit 8b65fb7

Please sign in to comment.