Skip to content

Commit

Permalink
Refactor ReactEventEmitter to avoid using the method ReactContext.get…
Browse files Browse the repository at this point in the history
…JSModule()

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
  • Loading branch information
mdvacca authored and facebook-github-bot committed Sep 14, 2019
1 parent f1c6029 commit 87af32a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,16 @@
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;
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);
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 87af32a

Please sign in to comment.