Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReactActivity extends FragmentActivity #22662

Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public class RNTesterActivity extends ReactActivity {
public static class RNTesterActivityDelegate extends ReactActivityDelegate {
private static final String PARAM_ROUTE = "route";
private Bundle mInitialProps = null;
private final @Nullable Activity mActivity;
private final @Nullable ReactActivity mActivity;

public RNTesterActivityDelegate(Activity activity, String mainComponentName) {
public RNTesterActivityDelegate(ReactActivity activity, String mainComponentName) {
super(activity, mainComponentName);
this.mActivity = activity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

import javax.annotation.Nullable;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.KeyEvent;

import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
Expand All @@ -21,7 +21,7 @@
/**
* Base Activity for React Native applications.
*/
public abstract class ReactActivity extends Activity
public abstract class ReactActivity extends FragmentActivity
implements DefaultHardwareBackBtnHandler, PermissionAwareActivity {

private final ReactActivityDelegate mDelegate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.KeyEvent;

import com.facebook.infer.annotation.Assertions;
Expand All @@ -30,26 +29,22 @@
public class ReactActivityDelegate {

private final @Nullable Activity mActivity;
private final @Nullable FragmentActivity mFragmentActivity;
private final @Nullable String mMainComponentName;

private @Nullable ReactRootView mReactRootView;
private @Nullable DoubleTapReloadRecognizer mDoubleTapReloadRecognizer;
private @Nullable PermissionListener mPermissionListener;
private @Nullable Callback mPermissionsCallback;

@Deprecated
public ReactActivityDelegate(Activity activity, @Nullable String mainComponentName) {
mActivity = activity;
mMainComponentName = mainComponentName;
mFragmentActivity = null;
}

public ReactActivityDelegate(
hramos marked this conversation as resolved.
Show resolved Hide resolved
FragmentActivity fragmentActivity,
@Nullable String mainComponentName) {
mFragmentActivity = fragmentActivity;
public ReactActivityDelegate(ReactActivity activity, @Nullable String mainComponentName) {
mActivity = activity;
mMainComponentName = mainComponentName;
mActivity = null;
}

protected @Nullable Bundle getLaunchOptions() {
Expand Down Expand Up @@ -206,10 +201,7 @@ public void invoke(Object... args) {
}

protected Context getContext() {
if (mActivity != null) {
return mActivity;
}
return Assertions.assertNotNull(mFragmentActivity);
return Assertions.assertNotNull(mActivity);
}

protected Activity getPlainActivity() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,126 +7,11 @@

package com.facebook.react;

import javax.annotation.Nullable;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.KeyEvent;

import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
import com.facebook.react.modules.core.PermissionAwareActivity;
import com.facebook.react.modules.core.PermissionListener;

/**
* @deprecated
* ReactFragmentActivity will be removed in 0.57 release.
* ReactFragmentActivity will be removed in 0.59 release.
* Use {@link ReactActivity} instead.
*/
@Deprecated
public abstract class ReactFragmentActivity extends FragmentActivity implements
DefaultHardwareBackBtnHandler, PermissionAwareActivity {

private final ReactActivityDelegate mDelegate;

protected ReactFragmentActivity() {
mDelegate = createReactActivityDelegate();
}

/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
* e.g. "MoviesApp"
*/
protected @Nullable String getMainComponentName() {
return null;
}

/**
* Called at construction time, override if you have a custom delegate implementation.
*/
protected ReactActivityDelegate createReactActivityDelegate() {
return new ReactActivityDelegate(this, getMainComponentName());
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mDelegate.onCreate(savedInstanceState);
}

@Override
protected void onPause() {
super.onPause();
mDelegate.onPause();
}

@Override
protected void onResume() {
super.onResume();
mDelegate.onResume();
}

@Override
protected void onDestroy() {
super.onDestroy();
mDelegate.onDestroy();
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
mDelegate.onActivityResult(requestCode, resultCode, data);
}

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
return mDelegate.onKeyUp(keyCode, event) || super.onKeyUp(keyCode, event);
}

@Override
public void onBackPressed() {
if (!mDelegate.onBackPressed()) {
super.onBackPressed();
}
}

@Override
public void invokeDefaultOnBackPressed() {
super.onBackPressed();
}

@Override
public void onNewIntent(Intent intent) {
if (!mDelegate.onNewIntent(intent)) {
super.onNewIntent(intent);
}
}

@Override
public void requestPermissions(
String[] permissions,
int requestCode,
PermissionListener listener) {
mDelegate.requestPermissions(permissions, requestCode, listener);
}

@Override
public void onRequestPermissionsResult(
int requestCode,
String[] permissions,
int[] grantResults) {
mDelegate.onRequestPermissionsResult(requestCode, permissions, grantResults);
}

protected final ReactNativeHost getReactNativeHost() {
return mDelegate.getReactNativeHost();
}

protected final ReactInstanceManager getReactInstanceManager() {
return mDelegate.getReactInstanceManager();
}

protected final void loadApp(String appKey) {
mDelegate.loadApp(appKey);
}
public abstract class ReactFragmentActivity extends ReactActivity {
}