-
public class ReactInstanceManager
This class is managing instances of CatalystInstance. It exposes a way to configure catalyst instance using ReactPackage and keeps track of the lifecycle of that instance. It also sets up connection between the instance and developers support functionality of the framework.
An instance of this manager is required to start JS application in ReactRootView (see startReactApplication for more info).
The lifecycle of the instance of ReactInstanceManager should be bound to the activity that owns the ReactRootView that is used to render react application using this instance manager (see startReactApplication). It's required to pass owning activity's lifecycle events to the instance manager (see onHostPause, and onHostResume).
To instantiate an instance of this class use builder.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interface
ReactInstanceManager.ReactInstanceEventListener
Listener interface for react instance events. This class extends {@Link * com.facebook.react.ReactInstanceEventListener} as a mitigation for both bridgeless and OSScompatibility: We create a separate ReactInstanceEventListener class to remove dependency onReactInstanceManager which is a bridge-specific class, but in the mean time we have to keepReactInstanceManager.ReactInstanceEventListener so OSS won't break.
-
Method Summary
Modifier and Type Method Description static ReactInstanceManagerBuilder
builder()
Creates a builder that is capable of creating an instance of ReactInstanceManager. synchronized void
setUseFallbackBundle(boolean useFallbackBundle)
DevSupportManager
getDevSupportManager()
MemoryPressureRouter
getMemoryPressureRouter()
List<ReactPackage>
getPackages()
void
handleCxxError(Exception e)
void
registerCxxErrorHandlerFunc()
void
createReactContextInBackground()
Trigger react context initialization asynchronously in a background async task. void
recreateReactContextInBackground()
Recreate the react application and context. boolean
hasStartedCreatingInitialContext()
void
onBackPressed()
This method will give JS the opportunity to consume the back button event. void
onNewIntent(Intent intent)
This method will give JS the opportunity to receive intents via Linking. void
onHostPause()
Call this from onPause. void
onHostPause(@Nullable() Activity activity)
Call this from onPause. void
onHostResume(@Nullable() Activity activity, DefaultHardwareBackBtnHandler defaultBackButtonImpl)
Use this method when the activity resumes to enable invoking the back button directly from JS. void
onHostResume(@Nullable() Activity activity)
Use this method when the activity resumes. void
onHostDestroy()
Call this from onDestroy. void
onHostDestroy(@Nullable() Activity activity)
Call this from onDestroy. void
destroy()
Destroy this React instance and the attached JS context. void
onActivityResult(Activity activity, int requestCode, int resultCode, @Nullable() Intent data)
void
onWindowFocusChange(boolean hasFocus)
void
onConfigurationChanged(Context updatedContext, @Nullable() Configuration newConfig)
Call this from onConfigurationChanged. void
showDevOptionsDialog()
void
attachRootView(ReactRoot reactRoot)
Attach given {@param reactRoot} to a catalyst instance manager and start JS application usingJS module provided by getJSModuleName. void
detachRootView(ReactRoot reactRoot)
Detach given {@param reactRoot} from current catalyst instance. List<ViewManager>
getOrCreateViewManagers(ReactApplicationContext catalystApplicationContext)
Uses configured ReactPackage instances to create all view managers. ViewManager
createViewManager(String viewManagerName)
List<String>
getViewManagerNames()
void
addReactInstanceEventListener(ReactInstanceEventListener listener)
Add a listener to be notified of react instance events. void
removeReactInstanceEventListener(ReactInstanceEventListener listener)
Remove a listener previously added with addReactInstanceEventListener. ReactContext
getCurrentReactContext()
LifecycleState
getLifecycleState()
String
getJsExecutorName()
-
-
Method Detail
-
builder
static ReactInstanceManagerBuilder builder()
Creates a builder that is capable of creating an instance of ReactInstanceManager.
-
setUseFallbackBundle
synchronized void setUseFallbackBundle(boolean useFallbackBundle)
-
getDevSupportManager
DevSupportManager getDevSupportManager()
-
getMemoryPressureRouter
MemoryPressureRouter getMemoryPressureRouter()
-
getPackages
List<ReactPackage> getPackages()
-
handleCxxError
void handleCxxError(Exception e)
-
registerCxxErrorHandlerFunc
void registerCxxErrorHandlerFunc()
-
createReactContextInBackground
void createReactContextInBackground()
Trigger react context initialization asynchronously in a background async task. This enablesapplications to pre-load the application JS, and execute global code before is available and measured.
Called from UI thread.
-
recreateReactContextInBackground
void recreateReactContextInBackground()
Recreate the react application and context. This should be called if configuration has changedor the developer has requested the app to be reloaded. It should only be called after aninitial call to createReactContextInBackground.
Called from UI thread.
-
hasStartedCreatingInitialContext
boolean hasStartedCreatingInitialContext()
-
onBackPressed
void onBackPressed()
This method will give JS the opportunity to consume the back button event. If JS does notconsume the event, mDefaultBackButtonImpl will be invoked at the end of the round trip to JS.
-
onNewIntent
void onNewIntent(Intent intent)
This method will give JS the opportunity to receive intents via Linking.
-
onHostPause
void onHostPause()
Call this from onPause. This notifies any listening modules so they can doany necessary cleanup.
-
onHostPause
void onHostPause(@Nullable() Activity activity)
Call this from onPause. This notifies any listening modules so they can doany necessary cleanup. The passed Activity is the current Activity being paused. This willalways be the foreground activity that would be returned by .
- Parameters:
activity
- the activity being paused
-
onHostResume
void onHostResume(@Nullable() Activity activity, DefaultHardwareBackBtnHandler defaultBackButtonImpl)
Use this method when the activity resumes to enable invoking the back button directly from JS.
This method retains an instance to provided mDefaultBackButtonImpl. Thus it's important topass from the activity instance that owns this particular instance of , so that once this instance receive onHostDestroy event it willclear the reference to that defaultBackButtonImpl.
- Parameters:
defaultBackButtonImpl
- a DefaultHardwareBackBtnHandler from an Activity that ownsthis instance of ReactInstanceManager.
-
onHostResume
void onHostResume(@Nullable() Activity activity)
Use this method when the activity resumes.
-
onHostDestroy
void onHostDestroy()
Call this from onDestroy. This notifies any listening modules so they can doany necessary cleanup.
-
onHostDestroy
void onHostDestroy(@Nullable() Activity activity)
Call this from onDestroy. This notifies any listening modules so they can doany necessary cleanup. If the activity being destroyed is not the current activity, no modulesare notified.
- Parameters:
activity
- the activity being destroyed
-
destroy
void destroy()
Destroy this React instance and the attached JS context.
-
onActivityResult
void onActivityResult(Activity activity, int requestCode, int resultCode, @Nullable() Intent data)
-
onWindowFocusChange
void onWindowFocusChange(boolean hasFocus)
-
onConfigurationChanged
void onConfigurationChanged(Context updatedContext, @Nullable() Configuration newConfig)
Call this from onConfigurationChanged.
-
showDevOptionsDialog
void showDevOptionsDialog()
-
attachRootView
void attachRootView(ReactRoot reactRoot)
Attach given {@param reactRoot} to a catalyst instance manager and start JS application usingJS module provided by getJSModuleName. If the react context is currentlybeing (re)-created, or if react context has not been created yet, the JS application associatedwith the provided reactRoot reactRoot will be started asynchronously, i.e this method won'tblock. This reactRoot will then be tracked by this manager and in case of catalyst instancerestart it will be re-attached.
-
detachRootView
void detachRootView(ReactRoot reactRoot)
Detach given {@param reactRoot} from current catalyst instance. It's safe to call this methodmultiple times on the same {@param reactRoot} - in that case view will be detached with thefirst call.
-
getOrCreateViewManagers
List<ViewManager> getOrCreateViewManagers(ReactApplicationContext catalystApplicationContext)
Uses configured ReactPackage instances to create all view managers.
-
createViewManager
@Nullable() ViewManager createViewManager(String viewManagerName)
-
getViewManagerNames
@Nullable() List<String> getViewManagerNames()
-
addReactInstanceEventListener
void addReactInstanceEventListener(ReactInstanceEventListener listener)
Add a listener to be notified of react instance events.
-
removeReactInstanceEventListener
void removeReactInstanceEventListener(ReactInstanceEventListener listener)
Remove a listener previously added with addReactInstanceEventListener.
-
getCurrentReactContext
@Nullable() ReactContext getCurrentReactContext()
-
getLifecycleState
LifecycleState getLifecycleState()
-
getJsExecutorName
String getJsExecutorName()
-
-
-
-