Permalink
Browse files

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

<https://github.com/android/platform_frameworks_base/blob/e71ecb2c4df15f727f51a0e1b65459f071853e35/core/java/com/android/internal/widget/ViewPager.java#L1689>

![image](https://cloud.githubusercontent.com/assets/104052/18266416/2a01f882-744d-11e6-86c4-3a2de3a1ca25.png)

**Test plan (required)**

<http://stackoverflow.com/questions/39327429/reactnative-viewpagerandroid-rcteventemitter>
Closes #9755

Differential Revision: D3841674

Pulled By: andreicoman11

fbshipit-source-id: d4cd9f4b2f61daad9005a098161ad7f75555345d
  • Loading branch information...
1 parent 68848f8 commit 6efe8e1d814a145b895f868f992bddb844d92252 @leeight leeight committed with Facebook Github Bot 9 Sep 9, 2016
@@ -141,7 +141,7 @@ class ViewPagerAndroid extends React.Component {
};
componentDidMount() {
- if (this.props.initialPage) {
+ if (this.props.initialPage != null) {
this.setPageWithoutAnimation(this.props.initialPage);
}
}
@@ -34,7 +34,10 @@
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

0 comments on commit 6efe8e1

Please sign in to comment.