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
This commit is contained in:
Oleksandr Melnykov
2020-10-23 05:10:54 -07:00
committed by Facebook GitHub Bot
parent 6eed1e4f80
commit d238da71aa
@@ -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);