Skip to content

Commit 0348953

Browse files
janicduplessisfacebook-github-bot
authored andcommitted
Allow passing partial contentOffset to ScrollView on Android (#28817)
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
1 parent bb5d043 commit 0348953

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollViewManager.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ public void setFadingEdgeLength(ReactHorizontalScrollView view, int value) {
304304
@ReactProp(name = "contentOffset")
305305
public void setContentOffset(ReactHorizontalScrollView view, ReadableMap value) {
306306
if (value != null) {
307-
double x = value.getDouble("x");
308-
double y = value.getDouble("y");
307+
double x = value.hasKey("x") ? value.getDouble("x") : 0;
308+
double y = value.hasKey("y") ? value.getDouble("y") : 0;
309309
view.reactScrollTo((int) PixelUtil.toPixelFromDIP(x), (int) PixelUtil.toPixelFromDIP(y));
310310
}
311311
}

ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewManager.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ public void setFadingEdgeLength(ReactScrollView view, int value) {
308308
@ReactProp(name = "contentOffset")
309309
public void setContentOffset(ReactScrollView view, ReadableMap value) {
310310
if (value != null) {
311-
double x = value.getDouble("x");
312-
double y = value.getDouble("y");
311+
double x = value.hasKey("x") ? value.getDouble("x") : 0;
312+
double y = value.hasKey("y") ? value.getDouble("y") : 0;
313313
view.reactScrollTo((int) PixelUtil.toPixelFromDIP(x), (int) PixelUtil.toPixelFromDIP(y));
314314
}
315315
}

0 commit comments

Comments
 (0)