From d238da71aa8cdd7ce519de617a9a200406da794c Mon Sep 17 00:00:00 2001 From: Oleksandr Melnykov Date: Fri, 23 Oct 2020 05:07:38 -0700 Subject: [PATCH] Do not crash when ScrollView snapToOffsets is empty Summary: The value of the `ScrollView.snapToOffsets` property can be an empty array (most likely an issue in the product code), which will crash the app. This diff adds a check to prevent crashing in this scenario and falling back to the default snap behaviour. Changelog: [Android][Fixed] - Do not crash when ScrollView snapToOffsets is empty Reviewed By: sammy-SC Differential Revision: D24502365 fbshipit-source-id: c63b8e3b8f2fb323ebd6c962ee628015934d8e11 --- .../facebook/react/views/scroll/ReactHorizontalScrollView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java index b632671b712..57ed5ae6a39 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java @@ -817,7 +817,7 @@ public class ReactHorizontalScrollView extends HorizontalScrollView } // get the nearest snap points to the target offset - if (mSnapOffsets != null) { + if (mSnapOffsets != null && !mSnapOffsets.isEmpty()) { firstOffset = mSnapOffsets.get(0); lastOffset = mSnapOffsets.get(mSnapOffsets.size() - 1);