Back out "[react-native][PR] Android - Add a ReactFragment"

Summary: Original commit changeset: b50b708cde45

Reviewed By: mdvacca

Differential Revision: D14792438

fbshipit-source-id: c5e0b5f7663fe70110f73ae94a6fa99388f87ae3
This commit is contained in:
Emily Janzer
2019-04-04 18:43:01 -07:00
committed by Facebook Github Bot
parent 0f909e3318
commit 7944d47a63
3 changed files with 55 additions and 373 deletions
@@ -15,9 +15,10 @@ import android.view.KeyEvent;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.Callback;
import com.facebook.react.devsupport.DoubleTapReloadRecognizer;
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
import com.facebook.react.modules.core.PermissionListener;
import com.facebook.react.uimanager.RootView;
import javax.annotation.Nullable;
/**
@@ -30,10 +31,10 @@ public class ReactActivityDelegate {
private final @Nullable Activity mActivity;
private final @Nullable String mMainComponentName;
private @Nullable ReactRootView mReactRootView;
private @Nullable DoubleTapReloadRecognizer mDoubleTapReloadRecognizer;
private @Nullable PermissionListener mPermissionListener;
private @Nullable Callback mPermissionsCallback;
private ReactDelegate mReactDelegate;
@Deprecated
public ReactActivityDelegate(Activity activity, @Nullable String mainComponentName) {
@@ -51,7 +52,7 @@ public class ReactActivityDelegate {
}
protected ReactRootView createRootView() {
return mReactDelegate.createRootView();
return new ReactRootView(getContext());
}
/**
@@ -66,7 +67,7 @@ public class ReactActivityDelegate {
}
public ReactInstanceManager getReactInstanceManager() {
return mReactDelegate.getReactInstanceManager();
return getReactNativeHost().getReactInstanceManager();
}
public String getMainComponentName() {
@@ -75,24 +76,36 @@ public class ReactActivityDelegate {
protected void onCreate(Bundle savedInstanceState) {
String mainComponentName = getMainComponentName();
mReactDelegate = new ReactDelegate(getPlainActivity(), getReactNativeHost(), mainComponentName, getLaunchOptions());
if (mMainComponentName != null) {
mReactDelegate.loadApp();
getPlainActivity().setContentView(mReactDelegate.getReactRootView());
if (mainComponentName != null) {
loadApp(mainComponentName);
}
mDoubleTapReloadRecognizer = new DoubleTapReloadRecognizer();
}
protected void loadApp(String appKey) {
mReactDelegate.loadApp(appKey);
getPlainActivity().setContentView(mReactDelegate.getReactRootView());
if (mReactRootView != null) {
throw new IllegalStateException("Cannot loadApp while app is already running.");
}
mReactRootView = createRootView();
mReactRootView.startReactApplication(
getReactNativeHost().getReactInstanceManager(),
appKey,
getLaunchOptions());
getPlainActivity().setContentView(mReactRootView);
}
protected void onPause() {
mReactDelegate.onHostPause();
if (getReactNativeHost().hasInstance()) {
getReactNativeHost().getReactInstanceManager().onHostPause(getPlainActivity());
}
}
protected void onResume() {
mReactDelegate.onHostResume();
if (getReactNativeHost().hasInstance()) {
getReactNativeHost().getReactInstanceManager().onHostResume(
getPlainActivity(),
(DefaultHardwareBackBtnHandler) getPlainActivity());
}
if (mPermissionsCallback != null) {
mPermissionsCallback.invoke();
@@ -101,11 +114,20 @@ public class ReactActivityDelegate {
}
protected void onDestroy() {
mReactDelegate.onHostDestroy();
if (mReactRootView != null) {
mReactRootView.unmountReactApplication();
mReactRootView = null;
}
if (getReactNativeHost().hasInstance()) {
getReactNativeHost().getReactInstanceManager().onHostDestroy(getPlainActivity());
}
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
mReactDelegate.onActivityResult(requestCode, resultCode, data, true);
if (getReactNativeHost().hasInstance()) {
getReactNativeHost().getReactInstanceManager()
.onActivityResult(getPlainActivity(), requestCode, resultCode, data);
}
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
@@ -119,7 +141,19 @@ public class ReactActivityDelegate {
}
public boolean onKeyUp(int keyCode, KeyEvent event) {
return mReactDelegate.shouldShowDevMenuOrReload(keyCode, event);
if (getReactNativeHost().hasInstance() && getReactNativeHost().getUseDeveloperSupport()) {
if (keyCode == KeyEvent.KEYCODE_MENU) {
getReactNativeHost().getReactInstanceManager().showDevOptionsDialog();
return true;
}
boolean didDoubleTapR = Assertions.assertNotNull(mDoubleTapReloadRecognizer)
.didDoubleTapR(keyCode, getPlainActivity().getCurrentFocus());
if (didDoubleTapR) {
getReactNativeHost().getReactInstanceManager().getDevSupportManager().handleReloadJS();
return true;
}
}
return false;
}
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
@@ -133,7 +167,11 @@ public class ReactActivityDelegate {
}
public boolean onBackPressed() {
return mReactDelegate.onBackPressed();
if (getReactNativeHost().hasInstance()) {
getReactNativeHost().getReactInstanceManager().onBackPressed();
return true;
}
return false;
}
public boolean onNewIntent(Intent intent) {