From 145fd041c7afe9a18f08f461487bb515ab2f516a Mon Sep 17 00:00:00 2001 From: Xin Chen Date: Mon, 14 Mar 2022 10:25:00 -0700 Subject: [PATCH] Fix crash on empty snapToOffsets prop to ScrollView Summary: When the `snapToOffsets` prop is empty array, the scroll view would crash unexpectly. This diff fixed that by treating empty array prop as null value for `snapToOffsets`. Changelog: [Android][Fixed] - Fix crash on empty snapToOffsets array Reviewed By: makovkastar Differential Revision: D34802022 fbshipit-source-id: af330512e444081b0cb02b65288ec5cd2bd14205 --- .../react/views/scroll/ReactHorizontalScrollViewManager.java | 2 +- .../com/facebook/react/views/scroll/ReactScrollViewManager.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollViewManager.java index 6d4bd242dd2609..2cdfec69aa1ee8 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollViewManager.java @@ -109,7 +109,7 @@ public void setSnapToAlignment(ReactHorizontalScrollView view, String alignment) @ReactProp(name = "snapToOffsets") public void setSnapToOffsets( ReactHorizontalScrollView view, @Nullable ReadableArray snapToOffsets) { - if (snapToOffsets == null) { + if (snapToOffsets == null || snapToOffsets.size() == 0) { view.setSnapOffsets(null); return; } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewManager.java index 8a3623444be309..d1b32c61d3c96c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewManager.java @@ -102,7 +102,7 @@ public void setSnapToInterval(ReactScrollView view, float snapToInterval) { @ReactProp(name = "snapToOffsets") public void setSnapToOffsets(ReactScrollView view, @Nullable ReadableArray snapToOffsets) { - if (snapToOffsets == null) { + if (snapToOffsets == null || snapToOffsets.size() == 0) { view.setSnapOffsets(null); return; }