From 5957c8b370fd44fd0439461dee1e7d9eab806866 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Wed, 26 Dec 2018 21:12:16 -0800 Subject: [PATCH] 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 --- .../react/uimanager/events/EventDispatcher.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcher.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcher.java index 646438e763c306..70e66c2935dd1b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcher.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcher.java @@ -125,6 +125,14 @@ public void dispatchEvent(Event event) { 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 void dispatchEvent(Event event) { } } - public void dispatchAllEvents() { - mCurrentFrameCallback.maybePostFromNonUI(); - } - /** * Add a listener to this EventDispatcher. */