From 30cc158a875a0414cf53d4d5155410eea5d5aeea Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Fri, 24 Apr 2020 22:09:44 -0700 Subject: [PATCH] ScrollView, HorizontalScrollView: support `null` contentOffset Summary: According to the Flow types, `contentOffset` is nullable. Support that. Changelog: [Internal] Fix to (1) support null contentOffset in ScrollView and HorizontalScrollView, added on Android after the last release. (2) Correctly add support for contentOffset in ScrollView (I missed that when adding it to HorizontalScrollView in the previous diff). Reviewed By: alsun2001 Differential Revision: D21243028 fbshipit-source-id: ebef9a9054a3e4dd88556739e836b7ece48fda12 --- .../views/scroll/ReactHorizontalScrollViewManager.java | 8 +++++--- .../react/views/scroll/ReactScrollViewManager.java | 10 ++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollViewManager.java index 8c2b91637ae1fa..ecb72fff78746f 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollViewManager.java @@ -303,8 +303,10 @@ public void setFadingEdgeLength(ReactHorizontalScrollView view, int value) { @ReactProp(name = "contentOffset") public void setContentOffset(ReactHorizontalScrollView view, ReadableMap value) { - double x = value.getDouble("x"); - double y = value.getDouble("y"); - view.reactScrollTo((int) PixelUtil.toPixelFromDIP(x), (int) PixelUtil.toPixelFromDIP(y)); + if (value != null) { + double x = value.getDouble("x"); + double y = value.getDouble("y"); + view.reactScrollTo((int) PixelUtil.toPixelFromDIP(x), (int) PixelUtil.toPixelFromDIP(y)); + } } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewManager.java index 51dc13166b0952..ed7cd05778836e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewManager.java @@ -13,6 +13,7 @@ import androidx.annotation.Nullable; import androidx.core.view.ViewCompat; import com.facebook.react.bridge.ReadableArray; +import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.RetryableMountingLayerException; import com.facebook.react.common.MapBuilder; import com.facebook.react.module.annotations.ReactModule; @@ -304,6 +305,15 @@ public void setFadingEdgeLength(ReactScrollView view, int value) { } } + @ReactProp(name = "contentOffset") + public void setContentOffset(ReactScrollView view, ReadableMap value) { + if (value != null) { + double x = value.getDouble("x"); + double y = value.getDouble("y"); + view.reactScrollTo((int) PixelUtil.toPixelFromDIP(x), (int) PixelUtil.toPixelFromDIP(y)); + } + } + @Override public Object updateState( ReactScrollView view, ReactStylesDiffMap props, @Nullable StateWrapper stateWrapper) {