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 8c2b91637ae..ecb72fff787 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 class ReactHorizontalScrollViewManager extends ViewGroupManager } } + @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) {