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
This commit is contained in:
Ramanpreet Nara
2021-03-06 20:30:17 -08:00
committed by Facebook GitHub Bot
parent d477f80113
commit 18c8417290
5 changed files with 21 additions and 10 deletions
@@ -61,16 +61,18 @@ public abstract class BaseJavaModule implements NativeModule {
}
@Override
public void onCatalystInstanceDestroy() {
// do nothing
}
public void onCatalystInstanceDestroy() {}
public boolean hasConstants() {
return false;
}
// Cleanup Logic for TurboModules
/**
* The CatalystInstance is going away with Venice. Therefore, the TurboModule infra introduces the
* invalidate() method to allow NativeModules to clean up after themselves.
*/
@Override
public void invalidate() {
// Do nothing
onCatalystInstanceDestroy();
}
}