Skip to content

Commit

Permalink
Fix dispatch of OnLayout event for first render
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mdvacca authored and kelset committed Dec 12, 2018
1 parent 79011d7 commit 3576819
Showing 1 changed file with 24 additions and 20 deletions.
Expand Up @@ -115,7 +115,7 @@ public void dispatchEvent(Event event) {
for (EventDispatcherListener listener : mListeners) {
listener.onEventDispatch(event);
}

synchronized (mEventsStagingLock) {
mEventStaging.add(event);
Systrace.startAsyncFlow(
Expand All @@ -135,6 +135,10 @@ public void dispatchEvent(Event event) {
}
}

public void dispatchAllEvents() {
mCurrentFrameCallback.maybePostFromNonUI();
}

/**
* Add a listener to this EventDispatcher.
*/
Expand Down Expand Up @@ -276,7 +280,7 @@ public void doFrame(long frameTimeNanos) {
try {
moveStagedEventsToDispatchQueue();

if (mEventsToDispatchSize > 0 && !mHasDispatchScheduled) {
if (!mHasDispatchScheduled) {
mHasDispatchScheduled = true;
Systrace.startAsyncFlow(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
Expand Down Expand Up @@ -337,26 +341,26 @@ public void run() {
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);
}
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();
}
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);
Expand Down

0 comments on commit 3576819

Please sign in to comment.