Skip to content

Commit

Permalink
fix ConcurrentModificationException in ReactScrollViewHelper (faceboo…
Browse files Browse the repository at this point in the history
…k#45550)

Summary:
Pull Request resolved: facebook#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
  • Loading branch information
alanleedev authored and facebook-github-bot committed Jul 20, 2024
1 parent aeb020d commit 743eea1
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 743eea1

Please sign in to comment.