@@ -117,7 +117,7 @@ public void dispatchEvent(Event event) {
117
117
for (EventDispatcherListener listener : mListeners ) {
118
118
listener .onEventDispatch (event );
119
119
}
120
-
120
+
121
121
synchronized (mEventsStagingLock ) {
122
122
mEventStaging .add (event );
123
123
Systrace .startAsyncFlow (
@@ -137,6 +137,10 @@ public void dispatchEvent(Event event) {
137
137
}
138
138
}
139
139
140
+ public void dispatchAllEvents () {
141
+ mCurrentFrameCallback .maybePostFromNonUI ();
142
+ }
143
+
140
144
/**
141
145
* Add a listener to this EventDispatcher.
142
146
*/
@@ -286,7 +290,7 @@ public void doFrame(long frameTimeNanos) {
286
290
try {
287
291
moveStagedEventsToDispatchQueue ();
288
292
289
- if (mEventsToDispatchSize > 0 && !mHasDispatchScheduled ) {
293
+ if (!mHasDispatchScheduled ) {
290
294
mHasDispatchScheduled = true ;
291
295
Systrace .startAsyncFlow (
292
296
Systrace .TRACE_TAG_REACT_JAVA_BRIDGE ,
@@ -347,26 +351,26 @@ public void run() {
347
351
mHasDispatchScheduled = false ;
348
352
Assertions .assertNotNull (mReactEventEmitter );
349
353
synchronized (mEventsToDispatchLock ) {
350
- // We avoid allocating an array and iterator, and "sorting" if we don't need to.
351
- // This occurs when the size of mEventsToDispatch is zero or one.
352
- if (mEventsToDispatchSize > 1 ) {
353
- Arrays .sort (mEventsToDispatch , 0 , mEventsToDispatchSize , EVENT_COMPARATOR );
354
- }
355
- for (int eventIdx = 0 ; eventIdx < mEventsToDispatchSize ; eventIdx ++) {
356
- Event event = mEventsToDispatch [eventIdx ];
357
- // Event can be null if it has been coalesced into another event.
358
- if (event == null ) {
359
- continue ;
354
+ if (mEventsToDispatchSize > 0 ) {
355
+ // We avoid allocating an array and iterator, and "sorting" if we don't need to.
356
+ // This occurs when the size of mEventsToDispatch is zero or one.
357
+ if (mEventsToDispatchSize > 1 ) {
358
+ Arrays .sort (mEventsToDispatch , 0 , mEventsToDispatchSize , EVENT_COMPARATOR );
359
+ }
360
+ for (int eventIdx = 0 ; eventIdx < mEventsToDispatchSize ; eventIdx ++) {
361
+ Event event = mEventsToDispatch [eventIdx ];
362
+ // Event can be null if it has been coalesced into another event.
363
+ if (event == null ) {
364
+ continue ;
365
+ }
366
+ Systrace .endAsyncFlow (
367
+ Systrace .TRACE_TAG_REACT_JAVA_BRIDGE , event .getEventName (), event .getUniqueID ());
368
+ event .dispatch (mReactEventEmitter );
369
+ event .dispose ();
360
370
}
361
- Systrace .endAsyncFlow (
362
- Systrace .TRACE_TAG_REACT_JAVA_BRIDGE ,
363
- event .getEventName (),
364
- event .getUniqueID ());
365
- event .dispatch (mReactEventEmitter );
366
- event .dispose ();
371
+ clearEventsToDispatch ();
372
+ mEventCookieToLastEventIdx .clear ();
367
373
}
368
- clearEventsToDispatch ();
369
- mEventCookieToLastEventIdx .clear ();
370
374
}
371
375
for (BatchEventDispatchedListener listener : mPostEventDispatchListeners ) {
372
376
listener .onBatchEventDispatched ();
0 commit comments