public abstract 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)
).
Ideally, this would be an interface, but because of the API used by earlier versions, it has to
have a static method, and so cannot (in Java < 8), be one.Modifier and Type | Class and Description |
---|---|
static class |
ReactInstanceManager.Builder
Builder class for
ReactInstanceManagerImpl |
static interface |
ReactInstanceManager.ReactInstanceEventListener
Listener interface for react instance events.
|
Constructor and Description |
---|
ReactInstanceManager() |
Modifier and Type | Method and Description |
---|---|
abstract void |
addReactInstanceEventListener(ReactInstanceManager.ReactInstanceEventListener listener)
Add a listener to be notified of react instance events.
|
abstract void |
attachMeasuredRootView(ReactRootView rootView)
Attach given to a catalyst instance manager and start JS application using
JS module provided by
ReactRootView.getJSModuleName() . |
static ReactInstanceManager.Builder |
builder()
Creates a builder that is capable of creating an instance of
ReactInstanceManagerImpl . |
abstract java.util.List<ViewManager> |
createAllViewManagers(ReactApplicationContext catalystApplicationContext)
Uses configured
ReactPackage instances to create all view managers |
abstract void |
createReactContextInBackground()
Trigger react context initialization asynchronously in a background async task.
|
abstract void |
destroy()
Destroy this React instance and the attached JS context.
|
abstract void |
detachRootView(ReactRootView rootView)
Detach given from current catalyst instance.
|
abstract ReactContext |
getCurrentReactContext() |
abstract DevSupportManager |
getDevSupportManager() |
abstract java.lang.String |
getJSBundleFile()
The JS Bundle file that this Instance Manager was constructed with.
|
abstract LifecycleState |
getLifecycleState() |
abstract MemoryPressureRouter |
getMemoryPressureRouter() |
abstract java.lang.String |
getSourceUrl()
Get the URL where the last bundle was loaded from.
|
abstract boolean |
hasStartedCreatingInitialContext() |
abstract void |
onActivityResult(android.app.Activity activity,
int requestCode,
int resultCode,
android.content.Intent data) |
abstract void |
onBackPressed()
This method will give JS the opportunity to consume the back button event.
|
abstract void |
onHostDestroy()
Deprecated.
use
onHostDestroy(Activity) instead |
abstract void |
onHostDestroy(android.app.Activity activity)
Call this from
Activity.onDestroy() . |
abstract void |
onHostPause()
Deprecated.
Use
onHostPause(Activity) instead. |
abstract void |
onHostPause(android.app.Activity activity)
Call this from
Activity.onPause() . |
abstract void |
onHostResume(android.app.Activity activity,
DefaultHardwareBackBtnHandler defaultBackButtonImpl)
Use this method when the activity resumes to enable invoking the back button directly from JS.
|
abstract void |
onNewIntent(android.content.Intent intent)
This method will give JS the opportunity to receive intents via Linking.
|
abstract void |
removeReactInstanceEventListener(ReactInstanceManager.ReactInstanceEventListener listener)
Remove a listener previously added with
addReactInstanceEventListener(com.facebook.react.ReactInstanceManager.ReactInstanceEventListener) . |
abstract void |
showDevOptionsDialog() |
public abstract DevSupportManager getDevSupportManager()
public abstract MemoryPressureRouter getMemoryPressureRouter()
public abstract void createReactContextInBackground()
ReactRootView
is available and measured. This should only be called the first time the
application is set up, which is enforced to keep developers from accidentally creating their
application multiple times without realizing it.
Called from UI thread.public abstract boolean hasStartedCreatingInitialContext()
public abstract void onBackPressed()
public abstract void onNewIntent(android.content.Intent intent)
@Deprecated public abstract void onHostPause()
onHostPause(Activity)
instead.Activity.onPause()
. This notifies any listening modules so they can do
any necessary cleanup.public abstract 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 abstract void onHostResume(android.app.Activity activity, DefaultHardwareBackBtnHandler defaultBackButtonImpl)
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
.@Deprecated public abstract void onHostDestroy()
onHostDestroy(Activity)
insteadActivity.onDestroy()
. This notifies any listening modules so they can do
any necessary cleanup.public abstract 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 abstract void onActivityResult(android.app.Activity activity, int requestCode, int resultCode, android.content.Intent data)
public abstract void showDevOptionsDialog()
public abstract java.lang.String getSourceUrl()
@Nullable public abstract java.lang.String getJSBundleFile()
public abstract void attachMeasuredRootView(ReactRootView rootView)
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 root view will be started asynchronously, i.e this method won't block.
This view will then be tracked by this manager and in case of catalyst instance restart it will
be re-attached.public abstract void detachRootView(ReactRootView rootView)
public abstract void destroy()
public abstract java.util.List<ViewManager> createAllViewManagers(ReactApplicationContext catalystApplicationContext)
ReactPackage
instances to create all view managerspublic abstract void addReactInstanceEventListener(ReactInstanceManager.ReactInstanceEventListener listener)
public abstract void removeReactInstanceEventListener(ReactInstanceManager.ReactInstanceEventListener listener)
addReactInstanceEventListener(com.facebook.react.ReactInstanceManager.ReactInstanceEventListener)
.@Nullable public abstract ReactContext getCurrentReactContext()
public abstract LifecycleState getLifecycleState()
public static ReactInstanceManager.Builder builder()
ReactInstanceManagerImpl
.