public class ReactInstanceManager
extends java.lang.Object
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
ReactRootView.startReactApplication(com.facebook.react.ReactInstanceManager, java.lang.String)
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 ReactRootView.startReactApplication(com.facebook.react.ReactInstanceManager, java.lang.String)
). It's required to pass owning
activity's lifecycle events to the instance manager (see onHostPause()
, onHostDestroy()
and onHostResume(android.app.Activity, com.facebook.react.modules.core.DefaultHardwareBackBtnHandler)
).
To instantiate an instance of this class use builder()
.
Modifier and Type | Class and Description |
---|---|
static interface |
ReactInstanceManager.ReactInstanceEventListener
Listener interface for react instance events.
|
Modifier and Type | Method and Description |
---|---|
void |
addReactInstanceEventListener(ReactInstanceManager.ReactInstanceEventListener listener)
Add a listener to be notified of react instance events.
|
void |
attachRootView(ReactRoot reactRoot)
Attach given to a catalyst instance manager and start JS application using
JS module provided by
ReactRootView.getJSModuleName() . |
static ReactInstanceManagerBuilder |
builder()
Creates a builder that is capable of creating an instance of
ReactInstanceManager . |
void |
createReactContextInBackground()
Trigger react context initialization asynchronously in a background async task.
|
ViewManager |
createViewManager(java.lang.String viewManagerName) |
void |
destroy()
Destroy this React instance and the attached JS context.
|
void |
detachRootView(ReactRoot reactRoot)
Detach given from current catalyst instance.
|
ReactContext |
getCurrentReactContext() |
DevSupportManager |
getDevSupportManager() |
java.lang.String |
getJsExecutorName() |
LifecycleState |
getLifecycleState() |
MemoryPressureRouter |
getMemoryPressureRouter() |
java.util.List<ViewManager> |
getOrCreateViewManagers(ReactApplicationContext catalystApplicationContext)
Uses configured
ReactPackage instances to create all view managers. |
java.util.List<ReactPackage> |
getPackages() |
java.util.List<java.lang.String> |
getViewManagerNames() |
boolean |
hasStartedCreatingInitialContext() |
void |
onActivityResult(android.app.Activity activity,
int requestCode,
int resultCode,
android.content.Intent data) |
void |
onBackPressed()
This method will give JS the opportunity to consume the back button event.
|
void |
onConfigurationChanged(android.content.Context updatedContext,
android.content.res.Configuration newConfig)
Call this from
Activity#onConfigurationChanged() . |
void |
onHostDestroy()
Deprecated.
use
onHostDestroy(Activity) instead |
void |
onHostDestroy(android.app.Activity activity)
Call this from
Activity.onDestroy() . |
void |
onHostPause()
Deprecated.
Use
onHostPause(Activity) instead. |
void |
onHostPause(android.app.Activity activity)
Call this from
Activity.onPause() . |
void |
onHostResume(android.app.Activity activity)
Use this method when the activity resumes.
|
void |
onHostResume(android.app.Activity activity,
DefaultHardwareBackBtnHandler defaultBackButtonImpl)
Use this method when the activity resumes to enable invoking the back button directly from JS.
|
void |
onNewIntent(android.content.Intent intent)
This method will give JS the opportunity to receive intents via Linking.
|
void |
onWindowFocusChange(boolean hasFocus) |
void |
recreateReactContextInBackground()
Recreate the react application and context.
|
void |
removeReactInstanceEventListener(ReactInstanceManager.ReactInstanceEventListener listener)
Remove a listener previously added with
addReactInstanceEventListener(com.facebook.react.ReactInstanceManager.ReactInstanceEventListener) . |
void |
showDevOptionsDialog() |
public static ReactInstanceManagerBuilder builder()
ReactInstanceManager
.public DevSupportManager getDevSupportManager()
public MemoryPressureRouter getMemoryPressureRouter()
public java.util.List<ReactPackage> getPackages()
public void createReactContextInBackground()
ReactRootView
is available and measured.
Called from UI thread.
public void recreateReactContextInBackground()
Called from UI thread.
public boolean hasStartedCreatingInitialContext()
public void onBackPressed()
public void onNewIntent(android.content.Intent intent)
public void onHostPause()
onHostPause(Activity)
instead.Activity.onPause()
. This notifies any listening modules so they can do
any necessary cleanup.public void onHostPause(android.app.Activity activity)
Activity.onPause()
. This notifies any listening modules so they can do
any necessary cleanup. The passed Activity is the current Activity being paused. This will
always be the foreground activity that would be returned by ReactContext.getCurrentActivity()
.activity
- the activity being pausedpublic void onHostResume(android.app.Activity activity, DefaultHardwareBackBtnHandler defaultBackButtonImpl)
This method retains an instance to provided mDefaultBackButtonImpl. Thus it's important to
pass from the activity instance that owns this particular instance of ReactInstanceManager
, so that once this instance receive onHostDestroy()
event it will
clear the reference to that defaultBackButtonImpl.
defaultBackButtonImpl
- a DefaultHardwareBackBtnHandler
from an Activity that owns
this instance of ReactInstanceManager
.public void onHostResume(android.app.Activity activity)
public void onHostDestroy()
onHostDestroy(Activity)
insteadActivity.onDestroy()
. This notifies any listening modules so they can do
any necessary cleanup.public void onHostDestroy(android.app.Activity activity)
Activity.onDestroy()
. This notifies any listening modules so they can do
any necessary cleanup. If the activity being destroyed is not the current activity, no modules
are notified.activity
- the activity being destroyedpublic void destroy()
public void onActivityResult(android.app.Activity activity, int requestCode, int resultCode, android.content.Intent data)
public void onWindowFocusChange(boolean hasFocus)
public void onConfigurationChanged(android.content.Context updatedContext, android.content.res.Configuration newConfig)
Activity#onConfigurationChanged()
.public void showDevOptionsDialog()
public void attachRootView(ReactRoot reactRoot)
ReactRootView.getJSModuleName()
. If the react context is currently
being (re)-created, or if react context has not been created yet, the JS application associated
with the provided reactRoot reactRoot will be started asynchronously, i.e this method won't
block. This reactRoot will then be tracked by this manager and in case of catalyst instance
restart it will be re-attached.public void detachRootView(ReactRoot reactRoot)
public java.util.List<ViewManager> getOrCreateViewManagers(ReactApplicationContext catalystApplicationContext)
ReactPackage
instances to create all view managers.public ViewManager createViewManager(java.lang.String viewManagerName)
public java.util.List<java.lang.String> getViewManagerNames()
public void addReactInstanceEventListener(ReactInstanceManager.ReactInstanceEventListener listener)
public void removeReactInstanceEventListener(ReactInstanceManager.ReactInstanceEventListener listener)
addReactInstanceEventListener(com.facebook.react.ReactInstanceManager.ReactInstanceEventListener)
.public ReactContext getCurrentReactContext()
public LifecycleState getLifecycleState()
public java.lang.String getJsExecutorName()