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
This commit is contained in:
Joshua Gross authored and Facebook GitHub Bot committed 2020-04-24 22:11:59 -07:00
1 parent aad99607de
commit 30cc158a87
2 files changed
+15 -3

No files matched your search

@@ -303,8 +303,10 @@ public class ReactHorizontalScrollViewManager extends ViewGroupManager<ReactHori
@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));
}
}
}
@@ -13,6 +13,7 @@ import android.view.View;
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 class ReactScrollViewManager extends ViewGroupManager<ReactScrollView>
}
}
@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) {