fix ConcurrentModificationException in ReactScrollViewHelper (#45550)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45550

`ConcurrentModificationException` is happening from `emitScrollEvent()`.
This usually happens if we modify the collection (add/remove) while accessing collection in a foreach loop.
Seems likely add/remove is called from a different thread while in the foreach loop.
Converting to list before we do the foreach as a quick fix.

Changelog: [Internal] - quick fix for exception

Issure reported here: https://fb.workplace.com/groups/rn.support/permalink/26557068097248454/

Reviewed By: mdvacca

Differential Revision: D59991739

fbshipit-source-id: a2fcc798430acaadd07561a5be871967cc8f2c3b
This commit is contained in:
Alan Lee
2024-07-19 18:44:48 -07:00
committed by Facebook GitHub Bot
parent aeb020dfa3
commit 3a5eb19731
@@ -113,7 +113,7 @@ public object ReactScrollViewHelper {
return
}
val contentView = scrollView.getChildAt(0) ?: return
for (scrollListener in scrollListeners) {
for (scrollListener in scrollListeners.toList()) {
scrollListener.onScroll(scrollView, scrollEventType, xVelocity, yVelocity)
}
val reactContext = scrollView.context as ReactContext
@@ -146,7 +146,7 @@ public object ReactScrollViewHelper {
/** This is only for Java listeners. onLayout events emitted to JS are handled elsewhere. */
@JvmStatic
public fun emitLayoutEvent(scrollView: ViewGroup) {
for (scrollListener in scrollListeners) {
for (scrollListener in scrollListeners.toList()) {
scrollListener.onLayout(scrollView)
}
}