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:
Janic Duplessis 2020-05-04 21:52:35 -07:00 коммит произвёл Facebook GitHub Bot
Родитель bb5d04366a
Коммит 0348953914
2 изменённых файлов: 4 добавлений и 4 удалений

Просмотреть файл

@ -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));
}
}

Просмотреть файл

@ -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));
}
}