Introduce TurboModule.initialize()

Summary:
NativeModules have an initialize() method that they use to allocate any resources, set up listeners, etc. This diff imports that method into the TurboModule interface. This way, we don't have to cast TurboModules to NativeModules to initialize them. Also, it makes sense to import this initialization mechanism into the TurboModule infra.

Changelog: [Internal]

Reviewed By: JoshuaGross

Differential Revision: D26871552

fbshipit-source-id: b8ae515b22928ed678b4003096e0756e991e10ff
This commit is contained in:
Ramanpreet Nara
2021-03-06 20:30:18 -08:00
committed by Facebook GitHub Bot
parent 3f0df9788b
commit c94ef1e3b3
2 changed files with 5 additions and 6 deletions
@@ -15,7 +15,6 @@ import com.facebook.jni.HybridData;
import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.CxxModuleWrapper;
import com.facebook.react.bridge.JSIModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.RuntimeExecutor;
import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder;
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
@@ -214,7 +213,7 @@ public class TurboModuleManager implements JSIModule, TurboModuleRegistry {
* NativeModules should be initialized after ReactApplicationContext has been set up.
* Therefore, we should initialize on the TurboModule now.
*/
((NativeModule) turboModule).initialize();
turboModule.initialize();
}
TurboModulePerfLogger.moduleCreateSetUpEnd(moduleName, moduleHolder.getModuleId());
@@ -9,9 +9,9 @@ package com.facebook.react.turbomodule.core.interfaces;
/** All turbo modules should inherit from this interface */
public interface TurboModule {
/**
* When CatalystInstance is destroyed, this method will be called. All implementing TurboModules
* can perform cleanup here.
*/
/** Initialize the TurboModule. */
void initialize();
/** Called before React Native is torn down. Clean up after the TurboModule. */
void invalidate();
}