Skip to content

Commit

Permalink
Fix NullPointerException when emiting event using UIManagerModule
Browse files Browse the repository at this point in the history
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 291c01f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,8 +25,11 @@ 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() { }
public ReactEventEmitter(ReactApplicationContext reactContext) {
mReactContext = reactContext;
}

public void register(@UIManagerType int uiManagerType, RCTEventEmitter eventEmitter) {
mEventEmitters.put(uiManagerType, eventEmitter);
Expand All @@ -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.