From 65d41ce9a4fef605706a70892ad3a92776a82496 Mon Sep 17 00:00:00 2001 From: Dulmandakh Date: Thu, 9 Aug 2018 19:00:51 +0800 Subject: [PATCH 1/5] ReactActivity extends AppCompatActivity, and ReactFragmentActivity extends ReactActivity --- .../java/com/facebook/react/testing/BUCK | 1 + .../react/testing/ReactAppTestActivity.java | 7 +- .../java/com/facebook/react/tests/BUCK | 1 + .../src/main/java/com/facebook/react/BUCK | 1 + .../com/facebook/react/ReactActivity.java | 4 +- .../facebook/react/ReactFragmentActivity.java | 117 +----------------- 6 files changed, 8 insertions(+), 123 deletions(-) diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/BUCK b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/BUCK index 8b61c439ef5276..bbbe250659175b 100644 --- a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/BUCK +++ b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/BUCK @@ -13,6 +13,7 @@ rn_android_library( "PUBLIC", ], deps = [ + react_native_dep("third-party/android/support/v7/appcompat-orig:appcompat"), react_native_dep("libraries/soloader/java/com/facebook/soloader:soloader"), react_native_dep("third-party/android/support/v4:lib-support-v4"), react_native_dep("third-party/java/buck-android-support:buck-android-support"), diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactAppTestActivity.java b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactAppTestActivity.java index 91b2c523dbff83..353386d6cc4aae 100644 --- a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactAppTestActivity.java +++ b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactAppTestActivity.java @@ -6,13 +6,10 @@ */ package com.facebook.react.testing; -import static com.facebook.react.bridge.UiThreadUtil.runOnUiThread; - import android.content.Intent; import android.graphics.Bitmap; -import android.os.AsyncTask; import android.os.Bundle; -import android.support.v4.app.FragmentActivity; +import android.support.v7.app.AppCompatActivity; import android.view.View; import android.view.ViewTreeObserver; import android.widget.FrameLayout; @@ -48,7 +45,7 @@ import javax.annotation.Nullable; -public class ReactAppTestActivity extends FragmentActivity +public class ReactAppTestActivity extends AppCompatActivity implements DefaultHardwareBackBtnHandler, PermissionAwareActivity { public static final String EXTRA_IS_FABRIC_TEST = "is_fabric_test"; diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/tests/BUCK b/ReactAndroid/src/androidTest/java/com/facebook/react/tests/BUCK index e39c0147a7cb75..efd71434c7371b 100644 --- a/ReactAndroid/src/androidTest/java/com/facebook/react/tests/BUCK +++ b/ReactAndroid/src/androidTest/java/com/facebook/react/tests/BUCK @@ -7,6 +7,7 @@ rn_android_library( "PUBLIC", ], deps = [ + react_native_dep("third-party/android/support/v7/appcompat-orig:appcompat"), react_native_dep("third-party/android/support/v4:lib-support-v4"), react_native_dep("third-party/java/jsr-305:jsr-305"), react_native_dep("third-party/java/junit:junit"), diff --git a/ReactAndroid/src/main/java/com/facebook/react/BUCK b/ReactAndroid/src/main/java/com/facebook/react/BUCK index 743bb34bb69448..4beafaa8c97bbf 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/BUCK @@ -10,6 +10,7 @@ rn_android_library( "PUBLIC", ], deps = [ + react_native_dep("third-party/android/support/v7/appcompat-orig:appcompat"), react_native_dep("java/com/facebook/systrace:systrace"), react_native_dep("libraries/fbcore/src/main/java/com/facebook/common/logging:logging"), react_native_dep("libraries/soloader/java/com/facebook/soloader:soloader"), diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactActivity.java b/ReactAndroid/src/main/java/com/facebook/react/ReactActivity.java index bbe9cad4473816..c9f178168b4dc6 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactActivity.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactActivity.java @@ -9,9 +9,9 @@ import javax.annotation.Nullable; -import android.app.Activity; import android.content.Intent; import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; import android.view.KeyEvent; import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler; @@ -21,7 +21,7 @@ /** * Base Activity for React Native applications. */ -public abstract class ReactActivity extends Activity +public abstract class ReactActivity extends AppCompatActivity implements DefaultHardwareBackBtnHandler, PermissionAwareActivity { private final ReactActivityDelegate mDelegate; diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactFragmentActivity.java b/ReactAndroid/src/main/java/com/facebook/react/ReactFragmentActivity.java index b104b91e4ef521..b8f311d641b8c0 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactFragmentActivity.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactFragmentActivity.java @@ -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. * 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 { } From 193670662c3c3e35c366a070ce3bcf474f056af3 Mon Sep 17 00:00:00 2001 From: Dulmandakh Date: Thu, 9 Aug 2018 19:36:31 +0800 Subject: [PATCH 2/5] ReactActivityDelegate supports only AppCompatActivity --- .../facebook/react/ReactActivityDelegate.java | 28 +++++-------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java b/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java index c0691c748db507..70a82954863c20 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java @@ -6,12 +6,11 @@ package com.facebook.react; import android.annotation.TargetApi; -import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Build; import android.os.Bundle; -import android.support.v4.app.FragmentActivity; +import android.support.v7.app.AppCompatActivity; import android.view.KeyEvent; import com.facebook.infer.annotation.Assertions; @@ -29,8 +28,7 @@ */ public class ReactActivityDelegate { - private final @Nullable Activity mActivity; - private final @Nullable FragmentActivity mFragmentActivity; + private final @Nullable AppCompatActivity mActivity; private final @Nullable String mMainComponentName; private @Nullable ReactRootView mReactRootView; @@ -38,18 +36,9 @@ public class ReactActivityDelegate { private @Nullable PermissionListener mPermissionListener; private @Nullable Callback mPermissionsCallback; - public ReactActivityDelegate(Activity activity, @Nullable String mainComponentName) { + public ReactActivityDelegate(AppCompatActivity activity, @Nullable String mainComponentName) { mActivity = activity; mMainComponentName = mainComponentName; - mFragmentActivity = null; - } - - public ReactActivityDelegate( - FragmentActivity fragmentActivity, - @Nullable String mainComponentName) { - mFragmentActivity = fragmentActivity; - mMainComponentName = mainComponentName; - mActivity = null; } protected @Nullable Bundle getLaunchOptions() { @@ -62,7 +51,7 @@ protected ReactRootView createRootView() { /** * Get the {@link ReactNativeHost} used by this app. By default, assumes - * {@link Activity#getApplication()} is an instance of {@link ReactApplication} and calls + * {@link AppCompatActivity#getApplication()} is an instance of {@link ReactApplication} and calls * {@link ReactApplication#getReactNativeHost()}. Override this method if your application class * does not implement {@code ReactApplication} or you simply have a different mechanism for * storing a {@code ReactNativeHost}, e.g. as a static field somewhere. @@ -206,13 +195,10 @@ public void invoke(Object... args) { } private Context getContext() { - if (mActivity != null) { - return mActivity; - } - return Assertions.assertNotNull(mFragmentActivity); + return Assertions.assertNotNull(mActivity); } - private Activity getPlainActivity() { - return ((Activity) getContext()); + private AppCompatActivity getPlainActivity() { + return ((AppCompatActivity) getContext()); } } From 3bb3821b006ae1a76ee492804ecd069bef6f98fd Mon Sep 17 00:00:00 2001 From: Dulmandakh Date: Thu, 9 Aug 2018 20:22:43 +0800 Subject: [PATCH 3/5] @NonNull annotation in ReactActivityDelegate constructor --- .../main/java/com/facebook/react/ReactActivityDelegate.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java b/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java index 70a82954863c20..6510649a577a79 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java @@ -10,6 +10,8 @@ import android.content.Intent; import android.os.Build; import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import android.view.KeyEvent; @@ -19,7 +21,6 @@ import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler; import com.facebook.react.modules.core.PermissionListener; -import javax.annotation.Nullable; /** * Delegate class for {@link ReactActivity} and {@link ReactFragmentActivity}. You can subclass this @@ -36,7 +37,7 @@ public class ReactActivityDelegate { private @Nullable PermissionListener mPermissionListener; private @Nullable Callback mPermissionsCallback; - public ReactActivityDelegate(AppCompatActivity activity, @Nullable String mainComponentName) { + public ReactActivityDelegate(@NonNull AppCompatActivity activity, @Nullable String mainComponentName) { mActivity = activity; mMainComponentName = mainComponentName; } From 2a8390bf57251644a01f10bebcc3164a54782a06 Mon Sep 17 00:00:00 2001 From: Dulmandakh Date: Thu, 9 Aug 2018 20:24:27 +0800 Subject: [PATCH 4/5] RNTesterActivity uses AppCompatActivity --- .../java/com/facebook/react/uiapp/RNTesterActivity.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/RNTester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterActivity.java b/RNTester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterActivity.java index 5b55c3b26e5e12..7f8797180daaf4 100644 --- a/RNTester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterActivity.java +++ b/RNTester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterActivity.java @@ -8,21 +8,20 @@ package com.facebook.react.uiapp; -import android.app.Activity; import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; import com.facebook.react.ReactActivity; import com.facebook.react.ReactActivityDelegate; -import javax.annotation.Nullable; - 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 AppCompatActivity mActivity; - public RNTesterActivityDelegate(Activity activity, String mainComponentName) { + public RNTesterActivityDelegate(AppCompatActivity activity, String mainComponentName) { super(activity, mainComponentName); this.mActivity = activity; } From 6a0f8b48d1fa812427e61bf0fa7b8223a95c459c Mon Sep 17 00:00:00 2001 From: Dulmandakh Date: Thu, 9 Aug 2018 20:37:11 +0800 Subject: [PATCH 5/5] remove @Nonull annotation from ReactActivityDelegate constructor --- .../main/java/com/facebook/react/ReactActivityDelegate.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java b/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java index 6510649a577a79..107dae063ce5f4 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java @@ -10,7 +10,6 @@ import android.content.Intent; import android.os.Build; import android.os.Bundle; -import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import android.view.KeyEvent; @@ -37,7 +36,7 @@ public class ReactActivityDelegate { private @Nullable PermissionListener mPermissionListener; private @Nullable Callback mPermissionsCallback; - public ReactActivityDelegate(@NonNull AppCompatActivity activity, @Nullable String mainComponentName) { + public ReactActivityDelegate(AppCompatActivity activity, @Nullable String mainComponentName) { mActivity = activity; mMainComponentName = mainComponentName; }