mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-05-11 10:38:00 +08:00
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:
committed by
Facebook Github Bot
parent
c5b80062ea
commit
844e11967d
@@ -117,7 +117,7 @@ public class EventDispatcher implements LifecycleEventListener {
|
||||
for (EventDispatcherListener listener : mListeners) {
|
||||
listener.onEventDispatch(event);
|
||||
}
|
||||
|
||||
|
||||
synchronized (mEventsStagingLock) {
|
||||
mEventStaging.add(event);
|
||||
Systrace.startAsyncFlow(
|
||||
@@ -137,6 +137,10 @@ public class EventDispatcher implements LifecycleEventListener {
|
||||
}
|
||||
}
|
||||
|
||||
public void dispatchAllEvents() {
|
||||
mCurrentFrameCallback.maybePostFromNonUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a listener to this EventDispatcher.
|
||||
*/
|
||||
@@ -286,7 +290,7 @@ public class EventDispatcher implements LifecycleEventListener {
|
||||
try {
|
||||
moveStagedEventsToDispatchQueue();
|
||||
|
||||
if (mEventsToDispatchSize > 0 && !mHasDispatchScheduled) {
|
||||
if (!mHasDispatchScheduled) {
|
||||
mHasDispatchScheduled = true;
|
||||
Systrace.startAsyncFlow(
|
||||
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
|
||||
@@ -347,26 +351,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();
|
||||
}
|
||||
for (BatchEventDispatchedListener listener : mPostEventDispatchListeners) {
|
||||
listener.onBatchEventDispatched();
|
||||
|
||||
Reference in New Issue
Block a user