Skip to content

Commit

Permalink
ReactActivity extends FragmentActivity (#22662)
Browse files Browse the repository at this point in the history
Summary:
In #20602, I tried to make ReactActivity to extend AppCompatActivity per Google recommendation. But import failed, now ReactActivity extends FragmentActivity which is a parent class of AppCompatActivity and step forward to extend AppCompatActivity.
Pull Request resolved: #22662

Reviewed By: mdvacca

Differential Revision: D13505140

Pulled By: hramos

fbshipit-source-id: d4edc8dc5c606c45811c1deddf5727a47ad484d8
  • Loading branch information
dulmandakh authored and facebook-github-bot committed Feb 1, 2019
1 parent 5ee7386 commit dda2b82
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 133 deletions.
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(
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 {
}

0 comments on commit dda2b82

Please sign in to comment.