Skip to content

Commit

Permalink
Allow passing partial contentOffset to ScrollView on Android (#28817)
Browse files Browse the repository at this point in the history
Summary:
Since support for contentOffset was added to horizontal ScrollView on android (30cc158) I'm seeing a crash in my app because of a library. What happens is that it passes a partial object for contentOffset so something like `{x: 1}` which causes a crash on Android.

According to the flow types the object should always contain both x and y but I think we should preserve the runtime behaviour and just use 0 like iOS does.

## Changelog

[Android] [Fixed] - Allow passing partial contentOffset to ScrollView on Android
Pull Request resolved: #28817

Test Plan: Tested that passing partial object for contentOffset does not crash.

Reviewed By: JoshuaGross

Differential Revision: D21396319

Pulled By: shergin

fbshipit-source-id: 4b52c868e3bfe183ff7f68a76ac34d1abd5e1069
  • Loading branch information
janicduplessis authored and facebook-github-bot committed May 5, 2020
1 parent bb5d043 commit 0348953
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ public void setFadingEdgeLength(ReactHorizontalScrollView view, int value) {
@ReactProp(name = "contentOffset")
public void setContentOffset(ReactHorizontalScrollView view, ReadableMap value) {
if (value != null) {
double x = value.getDouble("x");
double y = value.getDouble("y");
double x = value.hasKey("x") ? value.getDouble("x") : 0;

This comment has been minimized.

Copy link
@danielgindi

danielgindi Nov 30, 2020

Contributor

I would have thought this will just ignore the undefined axis- not zero it out. If anyone wants to scroll on a specific axis and not affect the other one.
Otherwise what’s the point in this?

double y = value.hasKey("y") ? value.getDouble("y") : 0;
view.reactScrollTo((int) PixelUtil.toPixelFromDIP(x), (int) PixelUtil.toPixelFromDIP(y));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ 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");
double x = value.hasKey("x") ? value.getDouble("x") : 0;
double y = value.hasKey("y") ? value.getDouble("y") : 0;
view.reactScrollTo((int) PixelUtil.toPixelFromDIP(x), (int) PixelUtil.toPixelFromDIP(y));
}
}
Expand Down

0 comments on commit 0348953

Please sign in to comment.