Permalink
Browse files

Fix NullPointerException when emiting event using UIManagerModule

Reviewed By: achen1

Differential Revision: D8321766

fbshipit-source-id: ae5052c83f46e08d540b90bf5b71c68f354c566d
  • Loading branch information...
mdvacca authored and facebook-github-bot committed Jun 8, 2018
1 parent e5aa5b7 commit 291c01f4ffe614760852e36b05d78b42cb4271df
@@ -96,13 +96,14 @@ public int compare(Event lhs, Event rhs) {
private Event[] mEventsToDispatch = new Event[16];
private int mEventsToDispatchSize = 0;
private volatile @Nullable ReactEventEmitter mReactEventEmitter = new ReactEventEmitter();
private volatile ReactEventEmitter mReactEventEmitter;
private short mNextEventTypeId = 0;
private volatile boolean mHasDispatchScheduled = false;
public EventDispatcher(ReactApplicationContext reactContext) {
mReactContext = reactContext;
mReactContext.addLifecycleEventListener(this);
mReactEventEmitter = new ReactEventEmitter(mReactContext);
}
/**
@@ -12,6 +12,7 @@
import android.util.Log;
import android.util.SparseArray;
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;
@@ -24,8 +25,11 @@
private static final String TAG = ReactEventEmitter.class.getSimpleName();
private final SparseArray<RCTEventEmitter> mEventEmitters = new SparseArray<>();
private final ReactApplicationContext mReactContext;
public ReactEventEmitter() { }
public ReactEventEmitter(ReactApplicationContext reactContext) {
mReactContext = reactContext;
}
public void register(@UIManagerType int uiManagerType, RCTEventEmitter eventEmitter) {
mEventEmitters.put(uiManagerType, eventEmitter);
@@ -48,12 +52,16 @@ public void receiveTouches(
Assertions.assertCondition(touches.size() > 0);
int targetReactTag = touches.getMap(0).getInt(TARGET_KEY);
getEventEmitter(targetReactTag).receiveTouches(eventName, touches, changedIndices);
int reactTag = touches.getMap(0).getInt(TARGET_KEY);
getEventEmitter(reactTag).receiveTouches(eventName, touches, changedIndices);
}
private RCTEventEmitter getEventEmitter(int reactTag) {
int type = ViewUtil.getUIManagerType(reactTag);
return mEventEmitters.get(type);
RCTEventEmitter eventEmitter = mEventEmitters.get(type);
if (eventEmitter == null) {
eventEmitter = mReactContext.getJSModule(RCTEventEmitter.class);
}
return eventEmitter;
}
}

0 comments on commit 291c01f

Please sign in to comment.