From 87af32a24c212407a8533af99954ae96c103c3f1 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Fri, 13 Sep 2019 17:43:56 -0700 Subject: [PATCH] Refactor ReactEventEmitter to avoid using the method ReactContext.getJSModule() Summary: This diff refactors ReactEventEmitter to not use the method ReactContext.getJSModule() Since the initialization of events is performed by UIManagerModule or FabricUIManager classes we don't need to use JSModules as part of this class Reviewed By: ejanzer Differential Revision: D17176948 fbshipit-source-id: 6915a74b486851fbeda24f779d97873df22fd79b --- .../facebook/react/uimanager/events/EventDispatcher.java | 2 +- .../react/uimanager/events/ReactEventEmitter.java | 9 ++------- 2 files changed, 3 insertions(+), 8 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 d72f4b36f41d4a..a738bd2a4cef89 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 @@ -102,7 +102,7 @@ public int compare(Event lhs, Event rhs) { public EventDispatcher(ReactApplicationContext reactContext) { mReactContext = reactContext; mReactContext.addLifecycleEventListener(this); - mReactEventEmitter = new ReactEventEmitter(mReactContext); + mReactEventEmitter = new ReactEventEmitter(); } /** Sends the given Event to JS, coalescing eligible events if JS is backed up. */ diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/ReactEventEmitter.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/ReactEventEmitter.java index 377bb05387c71f..f63d8f4d8bcceb 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/ReactEventEmitter.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/ReactEventEmitter.java @@ -11,7 +11,6 @@ import android.util.SparseArray; import androidx.annotation.Nullable; import com.facebook.infer.annotation.Assertions; -import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.WritableArray; import com.facebook.react.bridge.WritableMap; import com.facebook.react.uimanager.common.UIManagerType; @@ -19,13 +18,9 @@ public class ReactEventEmitter implements RCTEventEmitter { - private static final String TAG = ReactEventEmitter.class.getSimpleName(); private final SparseArray mEventEmitters = new SparseArray<>(); - private final ReactApplicationContext mReactContext; - public ReactEventEmitter(ReactApplicationContext reactContext) { - mReactContext = reactContext; - } + public ReactEventEmitter() {} public void register(@UIManagerType int uiManagerType, RCTEventEmitter eventEmitter) { mEventEmitters.put(uiManagerType, eventEmitter); @@ -54,7 +49,7 @@ private RCTEventEmitter getEventEmitter(int reactTag) { int type = ViewUtil.getUIManagerType(reactTag); RCTEventEmitter eventEmitter = mEventEmitters.get(type); if (eventEmitter == null) { - eventEmitter = mReactContext.getJSModule(RCTEventEmitter.class); + throw new RuntimeException("Unable to find event emitter for type: " + type); } return eventEmitter; }