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 facebook-github-bot committed Dec 6, 2018
1 parent c5b8006 commit 844e119
Showing 1 changed file with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void dispatchEvent(Event event) {
for (EventDispatcherListener listener : mListeners) {
listener.onEventDispatch(event);
}

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

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

/**
* Add a listener to this EventDispatcher.
*/
Expand Down Expand Up @@ -286,7 +290,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 @@ -347,26 +351,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();
}
for (BatchEventDispatchedListener listener : mPostEventDispatchListeners) {
listener.onBatchEventDispatched();
Expand Down

0 comments on commit 844e119

Please sign in to comment.