Skip to content

Commit 18c8417

Browse files
RSNarafacebook-github-bot
authored andcommitted
Deprecate NativeModule.onCatalystInstanceDestroy()
Summary: ## Rationale The CatalystInstance is going away after we delete the bridge. So, we should migrate away from onCatalystInstanceDestroy() to something else: invalidate(). ## Changes - Introduce the NativeModule.invalidate() cleanup hook. - Both the NativeModule and TurboModule infra now call this invalidate() method, **as opposed to** onCatalystInstanceDestroy(), to perform NativeModule cleanup. - **Is this safe?** All our NativeModules extend BaseJavaModule. BaseJavaModule.invalidate() delegates to NativeModule.onCatalystInstanceDestroy(), so NativeModules that implement onCatalystInstanceDestroy(), but not invalidate(), still have their onCatalystInstanceDestroy() method called. Changelog: [Android][Deprecated] - Deprecate NativeModule.onCatalystInstanceDestroy() for NativeModule.invalidate() Reviewed By: JoshuaGross Differential Revision: D26871001 fbshipit-source-id: e3bdfa0cf653ecbfe42791631bc6229af62f4817
1 parent d477f80 commit 18c8417

File tree

5 files changed

+21
-10
lines changed

5 files changed

+21
-10
lines changed

ReactAndroid/src/main/java/com/facebook/react/bridge/BaseJavaModule.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,18 @@ public boolean canOverrideExistingModule() {
6161
}
6262

6363
@Override
64-
public void onCatalystInstanceDestroy() {
65-
// do nothing
66-
}
64+
public void onCatalystInstanceDestroy() {}
6765

6866
public boolean hasConstants() {
6967
return false;
7068
}
7169

72-
// Cleanup Logic for TurboModules
70+
/**
71+
* The CatalystInstance is going away with Venice. Therefore, the TurboModule infra introduces the
72+
* invalidate() method to allow NativeModules to clean up after themselves.
73+
*/
74+
@Override
7375
public void invalidate() {
74-
// Do nothing
76+
onCatalystInstanceDestroy();
7577
}
7678
}

ReactAndroid/src/main/java/com/facebook/react/bridge/CxxModuleWrapperBase.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ public boolean canOverrideExistingModule() {
3838
}
3939

4040
@Override
41-
public void onCatalystInstanceDestroy() {
41+
public void onCatalystInstanceDestroy() {}
42+
43+
@Override
44+
public void invalidate() {
4245
mHybridData.resetNative();
4346
}
4447

ReactAndroid/src/main/java/com/facebook/react/bridge/ModuleHolder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public ModuleHolder(NativeModule nativeModule) {
107107

108108
public synchronized void destroy() {
109109
if (mModule != null) {
110-
mModule.onCatalystInstanceDestroy();
110+
mModule.invalidate();
111111
}
112112
}
113113

ReactAndroid/src/main/java/com/facebook/react/bridge/NativeModule.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ interface NativeMethod {
4747
*/
4848
boolean canOverrideExistingModule();
4949

50-
/** Called before {CatalystInstance#onHostDestroy} */
50+
/**
51+
* Allow NativeModule to clean up. Called before {CatalystInstance#onHostDestroy}
52+
*
53+
* @deprecated use {@link #invalidate()} instead.
54+
*/
5155
void onCatalystInstanceDestroy();
56+
57+
/** Allow NativeModule to clean up. Called before {CatalystInstance#onHostDestroy} */
58+
void invalidate();
5259
}

ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/TurboModuleManager.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,7 @@ public void onCatalystInstanceDestroy() {
326326
final TurboModule turboModule = getModule(moduleName, moduleHolder, false);
327327

328328
if (turboModule != null) {
329-
// TODO(T48014458): Rename this to invalidate()
330-
((NativeModule) turboModule).onCatalystInstanceDestroy();
329+
turboModule.invalidate();
331330
}
332331
}
333332

0 commit comments

Comments
 (0)