Perform cleanup when ReactApplicationContext is destroyed

Summary:
## Description
When we reload the app, `ReactApplicationContext.destroy()` is called. This method calls `CatalystInstanceImpl.destroy()`, which (on the NativeModules thread) calls `NativeModuleRegistry.notifyJSInstanceDestroy()`, which loops over all its `ModuleHolder`s, and calls `ModuleHolder.destroy()`, each of which call their NativeModule's `onCatalystInstanceDestroy()` method.

TurboModuleManager is a `JSIModule`, so it also has its `onCatalystInstanceDestroy()` method called when the `ReactApplicationContext` is destroyed. But `TurboModuleManager.onCatalystInstanceDestroy()` doesn't do anything. Instead, at the very least, it should call `onCatalystInstanceDestroy()` of all NativeModules.

Differential Revision: D16622132

fbshipit-source-id: da29e698b5217232cfaa01e6f817aab18ceb526f
This commit is contained in:
Ramanpreet Nara 2019-08-02 10:04:20 -07:00 коммит произвёл Facebook Github Bot
Родитель 7ab517b5fe
Коммит 29ec6401f6
1 изменённых файлов: 11 добавлений и 1 удалений

Просмотреть файл

@ -91,5 +91,15 @@ public class TurboModuleManager implements JSIModule, TurboModuleRegistry {
public void initialize() {}
@Override
public void onCatalystInstanceDestroy() {}
public void onCatalystInstanceDestroy() {
for (TurboModule turboModule : mTurboModules.values()) {
// TODO(T48014458): Rename this to invalidate()
((NativeModule) turboModule).onCatalystInstanceDestroy();
}
mTurboModules.clear();
// Delete the native part of this hybrid class.
mHybridData.resetNative();
}
}