mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Allow passing partial contentOffset to ScrollView on Android (#28817)
Summary:
Since support for contentOffset was added to horizontal ScrollView on android (30cc158a87) 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: https://github.com/facebook/react-native/pull/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
This commit is contained in:
committed by
Lorenzo Sciandra
parent
2923273bcb
commit
d8cf799a46
+2
-2
@@ -304,8 +304,8 @@ public class ReactHorizontalScrollViewManager extends ViewGroupManager<ReactHori
|
||||
@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;
|
||||
double y = value.hasKey("y") ? value.getDouble("y") : 0;
|
||||
view.reactScrollTo((int) PixelUtil.toPixelFromDIP(x), (int) PixelUtil.toPixelFromDIP(y));
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -308,8 +308,8 @@ 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");
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user