Skip to content

Commit

Permalink
ScrollView, HorizontalScrollView: support null contentOffset
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JoshuaGross authored and facebook-github-bot committed Apr 25, 2020
1 parent aad9960 commit 30cc158
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 30cc158

Please sign in to comment.