From bc4df8451992f4b7bb5d2d1c5ac1a84b2403b253 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Thu, 9 Nov 2017 16:48:37 -0500 Subject: [PATCH] RN-471/RN-484 Fixed null pointer exceptions caused by ScrollViews (#1116) * RN-471 Fixed null pointer from Swiper scroll view * RN-484 Added null check to ImagePreview scroll view --- app/components/swiper.js | 6 ++++-- app/screens/image_preview/image_preview.js | 9 +++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/components/swiper.js b/app/components/swiper.js index 72142724f..2a5bc6dfc 100644 --- a/app/components/swiper.js +++ b/app/components/swiper.js @@ -71,9 +71,11 @@ export default class Swiper extends PureComponent { if (this.runOnLayout) { if (Platform.OS === 'ios') { setTimeout(() => { - this.scrollView.scrollTo({x: this.props.width * this.state.index, animated: false}); + if (this.scrollView) { + this.scrollView.scrollTo({x: this.props.width * this.state.index, animated: false}); + } }, 100); - } else { + } else if (this.scrollView) { this.scrollView.setPageWithoutAnimation(this.state.index); } this.runOnLayout = false; diff --git a/app/screens/image_preview/image_preview.js b/app/screens/image_preview/image_preview.js index fbe370d36..aa8333925 100644 --- a/app/screens/image_preview/image_preview.js +++ b/app/screens/image_preview/image_preview.js @@ -91,7 +91,10 @@ export default class ImagePreview extends PureComponent { componentDidMount() { InteractionManager.runAfterInteractions(() => { - this.scrollView.scrollTo({x: (this.state.currentFile) * this.props.deviceWidth, animated: false}); + if (this.scrollView) { + this.scrollView.scrollTo({x: (this.state.currentFile) * this.props.deviceWidth, animated: false}); + } + Animated.timing(this.state.wrapperViewOpacity, { toValue: 1, duration: 100 @@ -102,7 +105,9 @@ export default class ImagePreview extends PureComponent { componentWillReceiveProps(nextProps) { if (this.props.deviceWidth !== nextProps.deviceWidth) { InteractionManager.runAfterInteractions(() => { - this.scrollView.scrollTo({x: (this.state.currentFile * nextProps.deviceWidth), animated: false}); + if (this.scrollView) { + this.scrollView.scrollTo({x: (this.state.currentFile * nextProps.deviceWidth), animated: false}); + } }); }