Skip to content

Commit 844e119

Browse files
mdvaccafacebook-github-bot
authored andcommitted
Fix dispatch of OnLayout event for first render
Summary: This diff ensures that Events delivered from the C++ side are actually processed. This is done forcing the execution of AsyncEventBeat.beat() in these cases Reviewed By: shergin Differential Revision: D13313955 fbshipit-source-id: b2785647913a640c2d557f4fa08d447845a540e9
1 parent c5b8006 commit 844e119

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

Diff for: ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcher.java

+24-20
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public void dispatchEvent(Event event) {
117117
for (EventDispatcherListener listener : mListeners) {
118118
listener.onEventDispatch(event);
119119
}
120-
120+
121121
synchronized (mEventsStagingLock) {
122122
mEventStaging.add(event);
123123
Systrace.startAsyncFlow(
@@ -137,6 +137,10 @@ public void dispatchEvent(Event event) {
137137
}
138138
}
139139

140+
public void dispatchAllEvents() {
141+
mCurrentFrameCallback.maybePostFromNonUI();
142+
}
143+
140144
/**
141145
* Add a listener to this EventDispatcher.
142146
*/
@@ -286,7 +290,7 @@ public void doFrame(long frameTimeNanos) {
286290
try {
287291
moveStagedEventsToDispatchQueue();
288292

289-
if (mEventsToDispatchSize > 0 && !mHasDispatchScheduled) {
293+
if (!mHasDispatchScheduled) {
290294
mHasDispatchScheduled = true;
291295
Systrace.startAsyncFlow(
292296
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
@@ -347,26 +351,26 @@ public void run() {
347351
mHasDispatchScheduled = false;
348352
Assertions.assertNotNull(mReactEventEmitter);
349353
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();
360370
}
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();
367373
}
368-
clearEventsToDispatch();
369-
mEventCookieToLastEventIdx.clear();
370374
}
371375
for (BatchEventDispatchedListener listener : mPostEventDispatchListeners) {
372376
listener.onBatchEventDispatched();

0 commit comments

Comments
 (0)