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
This commit is contained in:
David Vacca
2018-12-12 16:58:51 +00:00
committed by Lorenzo Sciandra
parent 79011d77cc
commit 35768190cf
@@ -115,7 +115,7 @@ public class EventDispatcher implements LifecycleEventListener {
for (EventDispatcherListener listener : mListeners) {
listener.onEventDispatch(event);
}
synchronized (mEventsStagingLock) {
mEventStaging.add(event);
Systrace.startAsyncFlow(
@@ -135,6 +135,10 @@ public class EventDispatcher implements LifecycleEventListener {
}
}
public void dispatchAllEvents() {
mCurrentFrameCallback.maybePostFromNonUI();
}
/**
* Add a listener to this EventDispatcher.
*/
@@ -276,7 +280,7 @@ public class EventDispatcher implements LifecycleEventListener {
try {
moveStagedEventsToDispatchQueue();
if (mEventsToDispatchSize > 0 && !mHasDispatchScheduled) {
if (!mHasDispatchScheduled) {
mHasDispatchScheduled = true;
Systrace.startAsyncFlow(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
@@ -337,26 +341,26 @@ public class EventDispatcher implements LifecycleEventListener {
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);
}
Systrace.endAsyncFlow(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
event.getEventName(),
event.getUniqueID());
event.dispatch(mReactEventEmitter);
event.dispose();
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();
}
clearEventsToDispatch();
mEventCookieToLastEventIdx.clear();
}
clearEventsToDispatch();
mEventCookieToLastEventIdx.clear();
}
} finally {
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);