@@ -115,7 +115,7 @@ public void dispatchEvent(Event event) {
115115 for (EventDispatcherListener listener : mListeners ) {
116116 listener .onEventDispatch (event );
117117 }
118-
118+
119119 synchronized (mEventsStagingLock ) {
120120 mEventStaging .add (event );
121121 Systrace .startAsyncFlow (
@@ -135,6 +135,10 @@ public void dispatchEvent(Event event) {
135135 }
136136 }
137137
138+ public void dispatchAllEvents () {
139+ mCurrentFrameCallback .maybePostFromNonUI ();
140+ }
141+
138142 /**
139143 * Add a listener to this EventDispatcher.
140144 */
@@ -276,7 +280,7 @@ public void doFrame(long frameTimeNanos) {
276280 try {
277281 moveStagedEventsToDispatchQueue ();
278282
279- if (mEventsToDispatchSize > 0 && !mHasDispatchScheduled ) {
283+ if (!mHasDispatchScheduled ) {
280284 mHasDispatchScheduled = true ;
281285 Systrace .startAsyncFlow (
282286 Systrace .TRACE_TAG_REACT_JAVA_BRIDGE ,
@@ -337,26 +341,26 @@ public void run() {
337341 mHasDispatchScheduled = false ;
338342 Assertions .assertNotNull (mReactEventEmitter );
339343 synchronized (mEventsToDispatchLock ) {
340- // We avoid allocating an array and iterator, and "sorting" if we don't need to.
341- // This occurs when the size of mEventsToDispatch is zero or one.
342- if (mEventsToDispatchSize > 1 ) {
343- Arrays .sort (mEventsToDispatch , 0 , mEventsToDispatchSize , EVENT_COMPARATOR );
344- }
345- for (int eventIdx = 0 ; eventIdx < mEventsToDispatchSize ; eventIdx ++) {
346- Event event = mEventsToDispatch [eventIdx ];
347- // Event can be null if it has been coalesced into another event.
348- if (event == null ) {
349- continue ;
344+ if (mEventsToDispatchSize > 0 ) {
345+ // We avoid allocating an array and iterator, and "sorting" if we don't need to.
346+ // This occurs when the size of mEventsToDispatch is zero or one.
347+ if (mEventsToDispatchSize > 1 ) {
348+ Arrays .sort (mEventsToDispatch , 0 , mEventsToDispatchSize , EVENT_COMPARATOR );
349+ }
350+ for (int eventIdx = 0 ; eventIdx < mEventsToDispatchSize ; eventIdx ++) {
351+ Event event = mEventsToDispatch [eventIdx ];
352+ // Event can be null if it has been coalesced into another event.
353+ if (event == null ) {
354+ continue ;
355+ }
356+ Systrace .endAsyncFlow (
357+ Systrace .TRACE_TAG_REACT_JAVA_BRIDGE , event .getEventName (), event .getUniqueID ());
358+ event .dispatch (mReactEventEmitter );
359+ event .dispose ();
350360 }
351- Systrace .endAsyncFlow (
352- Systrace .TRACE_TAG_REACT_JAVA_BRIDGE ,
353- event .getEventName (),
354- event .getUniqueID ());
355- event .dispatch (mReactEventEmitter );
356- event .dispose ();
361+ clearEventsToDispatch ();
362+ mEventCookieToLastEventIdx .clear ();
357363 }
358- clearEventsToDispatch ();
359- mEventCookieToLastEventIdx .clear ();
360364 }
361365 } finally {
362366 Systrace .endSection (Systrace .TRACE_TAG_REACT_JAVA_BRIDGE );
0 commit comments