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
This commit is contained in:
Harrison Healey 2017-11-09 16:48:37 -05:00 committed by enahum
parent aeac45e64e
commit bc4df84519
2 changed files with 11 additions and 4 deletions

View file

@ -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;

View file

@ -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});
}
});
}