diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcher.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcher.java index 37fcadda30a..507d32223de 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcher.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcher.java @@ -115,7 +115,7 @@ public class EventDispatcher implements LifecycleEventListener { for (EventDispatcherListener listener : mListeners) { listener.onEventDispatch(event); } - + synchronized (mEventsStagingLock) { mEventStaging.add(event); Systrace.startAsyncFlow( @@ -135,6 +135,10 @@ public class EventDispatcher implements LifecycleEventListener { } } + public void dispatchAllEvents() { + mCurrentFrameCallback.maybePostFromNonUI(); + } + /** * Add a listener to this EventDispatcher. */ @@ -276,7 +280,7 @@ public class EventDispatcher implements LifecycleEventListener { try { moveStagedEventsToDispatchQueue(); - if (mEventsToDispatchSize > 0 && !mHasDispatchScheduled) { + if (!mHasDispatchScheduled) { mHasDispatchScheduled = true; Systrace.startAsyncFlow( Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, @@ -337,26 +341,26 @@ public class EventDispatcher implements LifecycleEventListener { mHasDispatchScheduled = false; Assertions.assertNotNull(mReactEventEmitter); synchronized (mEventsToDispatchLock) { - // We avoid allocating an array and iterator, and "sorting" if we don't need to. - // This occurs when the size of mEventsToDispatch is zero or one. - if (mEventsToDispatchSize > 1) { - Arrays.sort(mEventsToDispatch, 0, mEventsToDispatchSize, EVENT_COMPARATOR); - } - for (int eventIdx = 0; eventIdx < mEventsToDispatchSize; eventIdx++) { - Event event = mEventsToDispatch[eventIdx]; - // Event can be null if it has been coalesced into another event. - if (event == null) { - continue; + if (mEventsToDispatchSize > 0) { + // We avoid allocating an array and iterator, and "sorting" if we don't need to. + // This occurs when the size of mEventsToDispatch is zero or one. + if (mEventsToDispatchSize > 1) { + Arrays.sort(mEventsToDispatch, 0, mEventsToDispatchSize, EVENT_COMPARATOR); } - Systrace.endAsyncFlow( - Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, - event.getEventName(), - event.getUniqueID()); - event.dispatch(mReactEventEmitter); - event.dispose(); + for (int eventIdx = 0; eventIdx < mEventsToDispatchSize; eventIdx++) { + Event event = mEventsToDispatch[eventIdx]; + // Event can be null if it has been coalesced into another event. + if (event == null) { + continue; + } + Systrace.endAsyncFlow( + Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, event.getEventName(), event.getUniqueID()); + event.dispatch(mReactEventEmitter); + event.dispose(); + } + clearEventsToDispatch(); + mEventCookieToLastEventIdx.clear(); } - clearEventsToDispatch(); - mEventCookieToLastEventIdx.clear(); } } finally { Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);