From 6efe8e1d814a145b895f868f992bddb844d92252 Mon Sep 17 00:00:00 2001 From: leeight Date: Fri, 9 Sep 2016 08:47:29 -0700 Subject: [PATCH] ViewPagerAndroid: FIX folly::toJson: JSON object value was a NaN or INF Summary: Explain the **motivation** for making this change. What existing problem does the pull request solve? Under certain scenario, `PageScrollEvent.offset` was initialized to `NaN`, which cause `folly::toJson` failed, and FIX #9750 ![image](https://cloud.githubusercontent.com/assets/104052/18266416/2a01f882-744d-11e6-86c4-3a2de3a1ca25.png) **Test plan (required)** Closes https://github.com/facebook/react-native/pull/9755 Differential Revision: D3841674 Pulled By: andreicoman11 fbshipit-source-id: d4cd9f4b2f61daad9005a098161ad7f75555345d --- Libraries/Components/ViewPager/ViewPagerAndroid.android.js | 2 +- .../com/facebook/react/views/viewpager/PageScrollEvent.java | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Libraries/Components/ViewPager/ViewPagerAndroid.android.js b/Libraries/Components/ViewPager/ViewPagerAndroid.android.js index 2a430d46369..07925d69450 100644 --- a/Libraries/Components/ViewPager/ViewPagerAndroid.android.js +++ b/Libraries/Components/ViewPager/ViewPagerAndroid.android.js @@ -141,7 +141,7 @@ class ViewPagerAndroid extends React.Component { }; componentDidMount() { - if (this.props.initialPage) { + if (this.props.initialPage != null) { this.setPageWithoutAnimation(this.props.initialPage); } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/viewpager/PageScrollEvent.java b/ReactAndroid/src/main/java/com/facebook/react/views/viewpager/PageScrollEvent.java index 79a4cca9146..6eeac56d747 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/viewpager/PageScrollEvent.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/viewpager/PageScrollEvent.java @@ -34,7 +34,10 @@ import com.facebook.react.uimanager.events.RCTEventEmitter; protected PageScrollEvent(int viewTag, int position, float offset) { super(viewTag); mPosition = position; - mOffset = offset; + + // folly::toJson default options don't support serialize NaN or Infinite value + mOffset = (Float.isInfinite(offset) || Float.isNaN(offset)) + ? 0.0f : offset; } @Override