mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Use getReactApplicationContextIfActiveOrWarn in modules that access JS or Native modules through ReactApplicationContext
Summary: In D18032458 we introduce `getReactApplicationContextIfActiveOrWarn`. In this diff, modules that access a JS or Native module through ReactApplicationContext need to check if the CatalystInstance is still alive before continuing. Changelog: [Internal] Reviewed By: furdei Differential Revision: D18032788 fbshipit-source-id: 5152783afd0b93b8ce0970fe4a509ea71396a54a
This commit is contained in:
committed by
Facebook Github Bot
parent
b12a29cfcb
commit
2ea33044bd
@@ -116,10 +116,14 @@ public class NativeAnimatedModule extends ReactContextBaseJavaModule
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
ReactApplicationContext reactCtx = getReactApplicationContext();
|
||||
UIManagerModule uiManager = reactCtx.getNativeModule(UIManagerModule.class);
|
||||
reactCtx.addLifecycleEventListener(this);
|
||||
uiManager.addUIManagerListener(this);
|
||||
ReactApplicationContext reactApplicationContext =
|
||||
getReactApplicationContextIfActiveOrWarn(NAME, "initialize");
|
||||
|
||||
if (reactApplicationContext != null) {
|
||||
UIManagerModule uiManager = reactApplicationContext.getNativeModule(UIManagerModule.class);
|
||||
reactApplicationContext.addLifecycleEventListener(this);
|
||||
uiManager.addUIManagerListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -175,9 +179,13 @@ public class NativeAnimatedModule extends ReactContextBaseJavaModule
|
||||
|
||||
private NativeAnimatedNodesManager getNodesManager() {
|
||||
if (mNodesManager == null) {
|
||||
UIManagerModule uiManager =
|
||||
getReactApplicationContext().getNativeModule(UIManagerModule.class);
|
||||
mNodesManager = new NativeAnimatedNodesManager(uiManager);
|
||||
ReactApplicationContext reactApplicationContext =
|
||||
getReactApplicationContextIfActiveOrWarn(NAME, "getNodesManager");
|
||||
|
||||
if (reactApplicationContext != null) {
|
||||
UIManagerModule uiManager = reactApplicationContext.getNativeModule(UIManagerModule.class);
|
||||
mNodesManager = new NativeAnimatedNodesManager(uiManager);
|
||||
}
|
||||
}
|
||||
|
||||
return mNodesManager;
|
||||
@@ -219,9 +227,15 @@ public class NativeAnimatedModule extends ReactContextBaseJavaModule
|
||||
WritableMap onAnimatedValueData = Arguments.createMap();
|
||||
onAnimatedValueData.putInt("tag", tag);
|
||||
onAnimatedValueData.putDouble("value", value);
|
||||
getReactApplicationContext()
|
||||
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
||||
.emit("onAnimatedValueUpdate", onAnimatedValueData);
|
||||
|
||||
ReactApplicationContext reactApplicationContext =
|
||||
getReactApplicationContextIfActiveOrWarn(
|
||||
NAME, "startListeningToAnimatedNodeValue.onValueUpdate");
|
||||
if (reactApplicationContext != null) {
|
||||
reactApplicationContext
|
||||
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
||||
.emit("onAnimatedValueUpdate", onAnimatedValueData);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user