use a static react instance holder

Reviewed By: astreet

Differential Revision: D2937867

fb-gh-sync-id: cdda79929fa5993b6ef159aa73922909017c2ded
shipit-source-id: cdda79929fa5993b6ef159aa73922909017c2ded
This commit is contained in:
Felix Oghina
2016-02-19 05:06:15 -08:00
committed by facebook-github-bot-7
parent b516976457
commit 19a1c4c229
7 changed files with 124 additions and 47 deletions

View File

@@ -41,8 +41,8 @@ import com.facebook.react.uimanager.ViewManager;
* The lifecycle of the instance of {@link ReactInstanceManager} should be bound to the activity
* that owns the {@link ReactRootView} that is used to render react application using this
* instance manager (see {@link ReactRootView#startReactApplication}). It's required to pass
* owning activity's lifecycle events to the instance manager (see {@link #onPause},
* {@link #onDestroy} and {@link #onResume}).
* owning activity's lifecycle events to the instance manager (see {@link #onHostPause},
* {@link #onHostDestroy} and {@link #onHostResume}).
*
* 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.
@@ -84,22 +84,32 @@ public abstract class ReactInstanceManager {
* consume the event, mDefaultBackButtonImpl will be invoked at the end of the round trip to JS.
*/
public abstract void onBackPressed();
public abstract void onPause();
/**
* Call this from {@link Activity#onPause()}. This notifies any listening modules so they can do
* any necessary cleanup.
*/
public abstract void onHostPause();
/**
* 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 to pass from the activity instance that owns this particular instance of {@link
* ReactInstanceManager}, so that once this instance receive {@link #onDestroy} event it will
* ReactInstanceManager}, so that once this instance receive {@link #onHostDestroy} event it will
* clear the reference to that defaultBackButtonImpl.
*
* @param defaultBackButtonImpl a {@link DefaultHardwareBackBtnHandler} from an Activity that owns
* this instance of {@link ReactInstanceManager}.
*/
public abstract void onResume(
public abstract void onHostResume(
Activity activity,
DefaultHardwareBackBtnHandler defaultBackButtonImpl);
public abstract void onDestroy();
/**
* Call this from {@link Activity#onDestroy()}. This notifies any listening modules so they can do
* any necessary cleanup.
*/
public abstract void onHostDestroy();
public abstract void onActivityResult(int requestCode, int resultCode, Intent data);
public abstract void showDevOptionsDialog();
@@ -125,6 +135,11 @@ public abstract class ReactInstanceManager {
*/
public abstract void detachRootView(ReactRootView rootView);
/**
* Destroy this React instance and the attached JS context.
*/
public abstract void destroy();
/**
* Uses configured {@link ReactPackage} instances to create all view managers
*/