-
- All Implemented Interfaces:
-
com.facebook.react.bridge.CatalystInstance
,com.facebook.react.bridge.JSBundleLoaderDelegate
,com.facebook.react.bridge.JSInstance
,com.facebook.react.bridge.MemoryPressureListener
public class CatalystInstanceImpl implements CatalystInstance
This provides an implementation of the public CatalystInstance instance. It is public because it is built by XReactInstanceManager which is in a different package.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public class
CatalystInstanceImpl.PendingJSCall
public class
CatalystInstanceImpl.Builder
-
Method Summary
Modifier and Type Method Description native CallInvokerHolderImpl
getJSCallInvokerHolder()
Returns a hybrid object that contains a pointer to a JS CallInvoker, which is used to schedulework on the JS Thread. native CallInvokerHolderImpl
getNativeCallInvokerHolder()
Returns a hybrid object that contains a pointer to a Native CallInvoker, which is used toschedule work on the NativeModules thread. void
extendNativeModules(NativeModuleRegistry modules)
This method and the native below permits a CatalystInstance to extend the known Native modules.This registry contains only the new modules to load. void
setSourceURLs(String deviceURL, String remoteURL)
This API is used in situations where the JS bundle is being executed not on the device, but ona host machine. void
registerSegment(int segmentId, String path)
This method registers the file path of an additional JS segment by its ID. void
loadScriptFromAssets(AssetManager assetManager, String assetURL, boolean loadSynchronously)
Load a JS bundle from Android assets. void
loadScriptFromFile(String fileName, String sourceURL, boolean loadSynchronously)
Load a JS bundle from the filesystem. void
loadSplitBundleFromFile(String fileName, String sourceURL)
Load a split JS bundle from the filesystem. void
runJSBundle()
boolean
hasRunJSBundle()
String
getSourceURL()
Return the source URL of the JS Bundle that was run, or {@code null}
if no JS bundle has beenrun yet.void
callFunction(String module, String method, NativeArray arguments)
void
callFunction(CatalystInstanceImpl.PendingJSCall function)
void
invokeCallback(int callbackID, NativeArrayInterface arguments)
void
destroy()
Destroys this catalyst instance, waiting for any other threads in ReactQueueConfiguration(besides the UI thread) to finish running. boolean
isDestroyed()
void
initialize()
Initialize all the native modules ReactQueueConfiguration
getReactQueueConfiguration()
<T extends JavaScriptModule> T
getJSModule(Class<T> jsInterface)
<T extends NativeModule> boolean
hasNativeModule(Class<T> nativeModuleInterface)
<T extends NativeModule> T
getNativeModule(Class<T> nativeModuleInterface)
NativeModule
getNativeModule(String moduleName)
Collection<NativeModule>
getNativeModules()
void
handleMemoryPressure(int level)
Called when the system generates a memory warning. void
addBridgeIdleDebugListener(NotThreadSafeBridgeIdleDebugListener listener)
Adds a idle listener for this Catalyst instance. void
removeBridgeIdleDebugListener(NotThreadSafeBridgeIdleDebugListener listener)
Removes a NotThreadSafeBridgeIdleDebugListener previously added with native void
setGlobalVariable(String propName, String jsonValue)
JavaScriptContextHolder
getJavaScriptContextHolder()
Do not use this anymore. native RuntimeExecutor
getRuntimeExecutor()
native RuntimeScheduler
getRuntimeScheduler()
void
addJSIModules(List<JSIModuleSpec> jsiModules)
JSIModule
getJSIModule(JSIModuleType moduleType)
void
setTurboModuleManager(JSIModule module)
For the time being, we want code relying on the old infra to also work with TurboModules.Hence, we must provide the TurboModuleRegistry to CatalystInstance so that getNativeModule,hasNativeModule, and getNativeModules can also return TurboModules. -
Methods inherited from class com.facebook.react.bridge.CatalystInstance
callFunction, getJSCallInvokerHolder, getNativeCallInvokerHolder, invokeCallback, setTurboModuleManager
-
Methods inherited from class com.facebook.react.bridge.JSBundleLoaderDelegate
loadScriptFromAssets
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
getJSCallInvokerHolder
native CallInvokerHolderImpl getJSCallInvokerHolder()
Returns a hybrid object that contains a pointer to a JS CallInvoker, which is used to schedulework on the JS Thread. Required for TurboModuleManager initialization.
-
getNativeCallInvokerHolder
native CallInvokerHolderImpl getNativeCallInvokerHolder()
Returns a hybrid object that contains a pointer to a Native CallInvoker, which is used toschedule work on the NativeModules thread. Required for TurboModuleManager initialization.
-
extendNativeModules
void extendNativeModules(NativeModuleRegistry modules)
This method and the native below permits a CatalystInstance to extend the known Native modules.This registry contains only the new modules to load. The registry
{@code mNativeModuleRegistry}
updates internally to contain all the new modules, and generates the new registry forextracting just the new collections.
-
setSourceURLs
void setSourceURLs(String deviceURL, String remoteURL)
This API is used in situations where the JS bundle is being executed not on the device, but ona host machine. In that case, we must provide two source URLs for the JS bundle: One to be usedon the device, and one to be used on the remote debugging machine.
- Parameters:
deviceURL
- A source URL that is accessible from this device.remoteURL
- A source URL that is accessible from the remote machine executing the JS.
-
registerSegment
void registerSegment(int segmentId, String path)
This method registers the file path of an additional JS segment by its ID.
-
loadScriptFromAssets
void loadScriptFromAssets(AssetManager assetManager, String assetURL, boolean loadSynchronously)
Load a JS bundle from Android assets. See createAssetLoader
-
loadScriptFromFile
void loadScriptFromFile(String fileName, String sourceURL, boolean loadSynchronously)
Load a JS bundle from the filesystem. See createFileLoader and createCachedBundleFromNetworkLoader
-
loadSplitBundleFromFile
void loadSplitBundleFromFile(String fileName, String sourceURL)
-
runJSBundle
void runJSBundle()
-
hasRunJSBundle
boolean hasRunJSBundle()
-
getSourceURL
@Nullable() String getSourceURL()
Return the source URL of the JS Bundle that was run, or
{@code null}
if no JS bundle has beenrun yet.
-
callFunction
void callFunction(String module, String method, NativeArray arguments)
-
callFunction
void callFunction(CatalystInstanceImpl.PendingJSCall function)
-
invokeCallback
void invokeCallback(int callbackID, NativeArrayInterface arguments)
-
destroy
void destroy()
Destroys this catalyst instance, waiting for any other threads in ReactQueueConfiguration(besides the UI thread) to finish running. Must be called from the UI thread so that we canfully shut down other threads.
-
isDestroyed
boolean isDestroyed()
-
initialize
void initialize()
Initialize all the native modules
-
getReactQueueConfiguration
ReactQueueConfiguration getReactQueueConfiguration()
-
getJSModule
<T extends JavaScriptModule> T getJSModule(Class<T> jsInterface)
-
hasNativeModule
<T extends NativeModule> boolean hasNativeModule(Class<T> nativeModuleInterface)
-
getNativeModule
@Nullable() <T extends NativeModule> T getNativeModule(Class<T> nativeModuleInterface)
-
getNativeModule
@Nullable() NativeModule getNativeModule(String moduleName)
-
getNativeModules
Collection<NativeModule> getNativeModules()
-
handleMemoryPressure
void handleMemoryPressure(int level)
Called when the system generates a memory warning.
-
addBridgeIdleDebugListener
void addBridgeIdleDebugListener(NotThreadSafeBridgeIdleDebugListener listener)
Adds a idle listener for this Catalyst instance. The listener will receive notificationswhenever the bridge transitions from idle to busy and vice-versa, where the busy state isdefined as there being some non-zero number of calls to JS that haven't resolved via aonBatchComplete call. The listener should be purely passive and not affect application logic.
-
removeBridgeIdleDebugListener
void removeBridgeIdleDebugListener(NotThreadSafeBridgeIdleDebugListener listener)
-
setGlobalVariable
native void setGlobalVariable(String propName, String jsonValue)
-
getJavaScriptContextHolder
JavaScriptContextHolder getJavaScriptContextHolder()
Do not use this anymore. Use getRuntimeExecutor instead. Get the C pointer (as along) to the JavaScriptCore context associated with this instance.
Use the following pattern to ensure that the JS context is not cleared while you are usingit: JavaScriptContextHolder jsContext = reactContext.getJavaScriptContextHolder()synchronized(jsContext) { nativeThingNeedingJsContext(jsContext.get()); }
-
getRuntimeExecutor
native RuntimeExecutor getRuntimeExecutor()
-
getRuntimeScheduler
native RuntimeScheduler getRuntimeScheduler()
-
addJSIModules
void addJSIModules(List<JSIModuleSpec> jsiModules)
-
getJSIModule
JSIModule getJSIModule(JSIModuleType moduleType)
-
setTurboModuleManager
void setTurboModuleManager(JSIModule module)
For the time being, we want code relying on the old infra to also work with TurboModules.Hence, we must provide the TurboModuleRegistry to CatalystInstance so that getNativeModule,hasNativeModule, and getNativeModules can also return TurboModules.
-
-
-
-