@@ -115,7 +115,7 @@ public void dispatchEvent(Event event) {
115
115
for (EventDispatcherListener listener : mListeners ) {
116
116
listener .onEventDispatch (event );
117
117
}
118
-
118
+
119
119
synchronized (mEventsStagingLock ) {
120
120
mEventStaging .add (event );
121
121
Systrace .startAsyncFlow (
@@ -135,6 +135,10 @@ public void dispatchEvent(Event event) {
135
135
}
136
136
}
137
137
138
+ public void dispatchAllEvents () {
139
+ mCurrentFrameCallback .maybePostFromNonUI ();
140
+ }
141
+
138
142
/**
139
143
* Add a listener to this EventDispatcher.
140
144
*/
@@ -276,7 +280,7 @@ public void doFrame(long frameTimeNanos) {
276
280
try {
277
281
moveStagedEventsToDispatchQueue ();
278
282
279
- if (mEventsToDispatchSize > 0 && !mHasDispatchScheduled ) {
283
+ if (!mHasDispatchScheduled ) {
280
284
mHasDispatchScheduled = true ;
281
285
Systrace .startAsyncFlow (
282
286
Systrace .TRACE_TAG_REACT_JAVA_BRIDGE ,
@@ -337,26 +341,26 @@ public void run() {
337
341
mHasDispatchScheduled = false ;
338
342
Assertions .assertNotNull (mReactEventEmitter );
339
343
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 ();
350
360
}
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 ();
357
363
}
358
- clearEventsToDispatch ();
359
- mEventCookieToLastEventIdx .clear ();
360
364
}
361
365
} finally {
362
366
Systrace .endSection (Systrace .TRACE_TAG_REACT_JAVA_BRIDGE );
0 commit comments