Skip to content

Commit 093579a

Browse files
authored
Merge pull request ptomasroos#764 from chaitanya0bhagvan/patch-1
Fix Detected a division by zero in Animated.divide node
2 parents ff5ccb5 + 2720bb3 commit 093579a

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

index.js

+16-14
Original file line numberDiff line numberDiff line change
@@ -329,21 +329,23 @@ const ScrollableTabView = createReactClass({
329329
_handleLayout(e) {
330330
const { width, } = e.nativeEvent.layout;
331331

332-
if (Math.round(width) !== Math.round(this.state.containerWidth)) {
333-
if (Platform.OS === 'ios') {
334-
const containerWidthAnimatedValue = new Animated.Value(width);
335-
// Need to call __makeNative manually to avoid a native animated bug. See
336-
// https://github.com/facebook/react-native/pull/14435
337-
containerWidthAnimatedValue.__makeNative();
338-
scrollValue = Animated.divide(this.state.scrollXIOS, containerWidthAnimatedValue);
339-
this.setState({ containerWidth: width, scrollValue, });
340-
} else {
341-
this.setState({ containerWidth: width, });
342-
}
343-
this.requestAnimationFrame(() => {
344-
this.goToPage(this.state.currentPage);
345-
});
332+
if (!width || width <= 0 || Math.round(width) === Math.round(this.state.containerWidth)) {
333+
return;
334+
}
335+
336+
if (Platform.OS === 'ios') {
337+
const containerWidthAnimatedValue = new Animated.Value(width);
338+
// Need to call __makeNative manually to avoid a native animated bug. See
339+
// https://github.com/facebook/react-native/pull/14435
340+
containerWidthAnimatedValue.__makeNative();
341+
scrollValue = Animated.divide(this.state.scrollXIOS, containerWidthAnimatedValue);
342+
this.setState({ containerWidth: width, scrollValue, });
343+
} else {
344+
this.setState({ containerWidth: width, });
346345
}
346+
this.requestAnimationFrame(() => {
347+
this.goToPage(this.state.currentPage);
348+
});
347349
},
348350

349351
_children(children = this.props.children) {

0 commit comments

Comments
 (0)