mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-06 09:31:11 +08:00
Fix events not working after closing and navigating back to Fabric screen in FB4A
Reviewed By: fkgozali Differential Revision: D8240344 fbshipit-source-id: 992945f94843589cefdf7ea24da709449ee38778
This commit is contained in:
committed by
Facebook Github Bot
parent
de18dd2648
commit
e95e73aaa7
@@ -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(
|
||||
@@ -81,6 +82,8 @@ public class FabricUIManager implements UIManager, JSHandler {
|
||||
new UIViewOperationQueue(
|
||||
reactContext, mNativeViewHierarchyManager, 0);
|
||||
mFabricReconciler = new FabricReconciler(mUIViewOperationQueue);
|
||||
mFabricEventEmitter =
|
||||
new FabricEventEmitter(mReactApplicationContext, this);
|
||||
mEventDispatcher = eventDispatcher;
|
||||
mJSContext = jsContext;
|
||||
}
|
||||
@@ -537,12 +540,14 @@ public class FabricUIManager implements UIManager, JSHandler {
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -161,7 +161,6 @@ public class EventDispatcher implements LifecycleEventListener {
|
||||
@Override
|
||||
public void onHostDestroy() {
|
||||
stopFrameCallback();
|
||||
mReactEventEmitter.stop();
|
||||
}
|
||||
|
||||
public void onCatalystInstanceDestroyed() {
|
||||
@@ -254,6 +253,10 @@ public class EventDispatcher implements LifecycleEventListener {
|
||||
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;
|
||||
|
||||
@@ -31,6 +31,10 @@ public class ReactEventEmitter implements RCTEventEmitter {
|
||||
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);
|
||||
@@ -52,17 +56,4 @@ public class ReactEventEmitter implements RCTEventEmitter {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user