Skip to content

Commit

Permalink
Fix events not working after closing and navigating back to Fabric sc…
Browse files Browse the repository at this point in the history
…reen in FB4A

Reviewed By: fkgozali

Differential Revision: D8240344

fbshipit-source-id: 992945f94843589cefdf7ea24da709449ee38778
  • Loading branch information
mdvacca authored and facebook-github-bot committed Jun 5, 2018
1 parent de18dd2 commit e95e73a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class FabricUIManager implements UIManager, JSHandler {
private final FabricReconciler mFabricReconciler;
private final EventDispatcher mEventDispatcher;
private FabricBinding mBinding;
private final FabricEventEmitter mFabricEventEmitter;
private long mEventHandlerPointer;

public FabricUIManager(
Expand All @@ -81,6 +82,8 @@ public FabricUIManager(
new UIViewOperationQueue(
reactContext, mNativeViewHierarchyManager, 0);
mFabricReconciler = new FabricReconciler(mUIViewOperationQueue);
mFabricEventEmitter =
new FabricEventEmitter(mReactApplicationContext, this);
mEventDispatcher = eventDispatcher;
mJSContext = jsContext;
}
Expand Down Expand Up @@ -537,12 +540,14 @@ public void invoke(long eventTarget, String name, WritableMap params) {
public void initialize() {
FabricEventEmitter eventEmitter =
new FabricEventEmitter(mReactApplicationContext, this);
mEventDispatcher.registerEventEmitter(FABRIC, eventEmitter);
mEventDispatcher.registerEventEmitter(FABRIC, mFabricEventEmitter);
}

@Override
public void onCatalystInstanceDestroy() {
mBinding.releaseEventHandler(mJSContext.get(), mEventHandlerPointer);
mEventDispatcher.unregisterEventEmitter(FABRIC);
mFabricEventEmitter.close();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ public void onHostPause() {
@Override
public void onHostDestroy() {
stopFrameCallback();
mReactEventEmitter.stop();
}

public void onCatalystInstanceDestroyed() {
Expand Down Expand Up @@ -254,6 +253,10 @@ public void registerEventEmitter(@UIManagerType int uiManagerType, RCTEventEmitt
mReactEventEmitter.register(uiManagerType, eventEmitter);
}

public void unregisterEventEmitter(@UIManagerType int uiManagerType) {
mReactEventEmitter.unregister(uiManagerType);
}

private class ScheduleDispatchFrameCallback extends ChoreographerCompat.FrameCallback {
private volatile boolean mIsPosted = false;
private boolean mShouldStop = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public void register(@UIManagerType int uiManagerType, RCTEventEmitter eventEmit
mEventEmitters.put(uiManagerType, eventEmitter);
}

public void unregister(@UIManagerType int uiManagerType) {
mEventEmitters.remove(uiManagerType);
}

@Override
public void receiveEvent(int targetReactTag, String eventName, @Nullable WritableMap event) {
getEventEmitter(targetReactTag).receiveEvent(targetReactTag, eventName, event);
Expand All @@ -52,17 +56,4 @@ private RCTEventEmitter getEventEmitter(int reactTag) {
int type = ViewUtil.getUIManagerType(reactTag);
return mEventEmitters.get(type);
}

public void stop() {
for (int i = 0 ; i < mEventEmitters.size() ; i++) {
RCTEventEmitter eventEmitter = mEventEmitters.valueAt(i);
if (eventEmitter instanceof Closeable) {
try {
((Closeable) eventEmitter).close();
} catch (IOException e) {
Log.i(TAG, "Exception when closing EventEmitter: " + eventEmitter, e);
}
}
}
}
}

0 comments on commit e95e73a

Please sign in to comment.