mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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
This commit is contained in:
committed by
Facebook Github Bot
parent
f1c6029e48
commit
87af32a24c
@@ -102,7 +102,7 @@ public class EventDispatcher implements LifecycleEventListener {
|
||||
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. */
|
||||
|
||||
+2
-7
@@ -11,7 +11,6 @@ import static com.facebook.react.uimanager.events.TouchesHelper.TARGET_KEY;
|
||||
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 @@ import com.facebook.react.uimanager.common.ViewUtil;
|
||||
|
||||
public class ReactEventEmitter implements RCTEventEmitter {
|
||||
|
||||
private static final String TAG = ReactEventEmitter.class.getSimpleName();
|
||||
private final SparseArray<RCTEventEmitter> 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 @@ public class ReactEventEmitter implements RCTEventEmitter {
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user