Fix dispatching of events when EventDispatcher is not initialized

Summary:
This diff fixes a NPE that can occur when we force the dispatching of events when the EventDispatcher is not initized.

The fix consists on avoid posting the frame callback, if the internals of EventDispatcher are not initialized yet (same behavior used by the dispatchEvent method)

Reviewed By: fkgozali

Differential Revision: D13549147

fbshipit-source-id: ef3baeb536e8772fbd83024352a37af01c21d589
This commit is contained in:
David Vacca 2018-12-26 21:12:16 -08:00 committed by Facebook Github Bot
parent acc2ed2488
commit 5957c8b370
1 changed files with 8 additions and 4 deletions

View File

@ -125,6 +125,14 @@ public class EventDispatcher implements LifecycleEventListener {
event.getEventName(),
event.getUniqueID());
}
maybePostFrameCallbackFromNonUI();
}
public void dispatchAllEvents() {
maybePostFrameCallbackFromNonUI();
}
private void maybePostFrameCallbackFromNonUI() {
if (mReactEventEmitter != null) {
// If the host activity is paused, the frame callback may not be currently
// posted. Ensure that it is so that this event gets delivered promptly.
@ -137,10 +145,6 @@ public class EventDispatcher implements LifecycleEventListener {
}
}
public void dispatchAllEvents() {
mCurrentFrameCallback.maybePostFromNonUI();
}
/**
* Add a listener to this EventDispatcher.
*/