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

Remove support of FragmentActivity and related widgets #19950

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
*
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
* directory of this source tree.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
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;
Expand Down Expand Up @@ -47,8 +44,7 @@
import java.util.concurrent.TimeUnit;
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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import java.util.List;

import android.app.DatePickerDialog;
import android.app.DialogFragment;
import android.app.Fragment;
import android.content.DialogInterface;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.widget.DatePicker;

import com.facebook.react.bridge.BaseJavaModule;
Expand Down Expand Up @@ -105,7 +105,7 @@ private DialogFragment showDialog(WritableMap options) {
waitForBridgeAndUIIdle();
getInstrumentation().waitForIdleSync();

return (DialogFragment) getActivity().getSupportFragmentManager()
return (DialogFragment) getActivity().getFragmentManager()
.findFragmentByTag(DatePickerDialogModule.FRAGMENT_TAG);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,9 @@

package com.facebook.react.tests;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Instrumentation.ActivityMonitor;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter.MalformedMimeTypeException;
import android.support.v4.app.DialogFragment;

import com.facebook.react.bridge.BaseJavaModule;
import com.facebook.react.testing.ReactInstanceSpecForTest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import java.util.ArrayList;
import java.util.List;

import android.app.DialogFragment;
import android.app.TimePickerDialog;
import android.content.DialogInterface;
import android.support.v4.app.DialogFragment;

import com.facebook.react.bridge.BaseJavaModule;
import com.facebook.react.testing.ReactInstanceSpecForTest;
Expand Down Expand Up @@ -94,7 +94,7 @@ private DialogFragment showDialog(WritableMap options) {
waitForBridgeAndUIIdle();
getInstrumentation().waitForIdleSync();

return (DialogFragment) getActivity().getSupportFragmentManager()
return (DialogFragment) getActivity().getFragmentManager()
.findFragmentByTag(TimePickerDialogModule.FRAGMENT_TAG);
}

Expand Down
1 change: 1 addition & 0 deletions ReactAndroid/src/main/java/com/facebook/react/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
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.v7.app.AppCompatActivity;
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 AppCompatActivity
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 @@ -20,36 +19,27 @@
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
import com.facebook.react.modules.core.PermissionListener;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* Delegate class for {@link ReactActivity} and {@link ReactFragmentActivity}. You can subclass this
* Delegate class for {@link ReactActivity}. You can subclass this
* to provide custom implementations for e.g. {@link #getReactNativeHost()}, if your Application
* class doesn't implement {@link ReactApplication}.
*/
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;

public ReactActivityDelegate(Activity activity, @Nullable String mainComponentName) {
public ReactActivityDelegate(@Nonnull Activity 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() {
Expand Down Expand Up @@ -206,10 +196,7 @@ public void invoke(Object... args) {
}

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

private 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.
* 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 {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ rn_android_library(
name = "blob",
srcs = glob(["**/*.java"]),
provided_deps = [
react_native_dep("third-party/android/support-annotations:android-support-annotations"),
react_native_dep("third-party/android/support/v4:lib-support-v4"),
react_native_dep("third-party/android/support-annotations:android-support-annotations")
],
visibility = [
"PUBLIC",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ load("//ReactNative:DEFS.bzl", "react_native_dep", "react_native_target", "rn_an
rn_android_library(
name = "datepicker",
srcs = glob(["**/*.java"]),
provided_deps = [
react_native_dep("third-party/android/support/v4:lib-support-v4"),
],
visibility = [
"PUBLIC",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

import javax.annotation.Nullable;

import java.util.Map;

import android.app.Activity;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.DialogFragment;
Expand Down Expand Up @@ -127,41 +125,21 @@ public void open(@Nullable final ReadableMap options, Promise promise) {
"Tried to open a DatePicker dialog while not attached to an Activity");
return;
}
// We want to support both android.app.Activity and the pre-Honeycomb FragmentActivity
// (for apps that use it for legacy reasons). This unfortunately leads to some code duplication.
if (activity instanceof android.support.v4.app.FragmentActivity) {
android.support.v4.app.FragmentManager fragmentManager =
((android.support.v4.app.FragmentActivity) activity).getSupportFragmentManager();
android.support.v4.app.DialogFragment oldFragment =
(android.support.v4.app.DialogFragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG);
if (oldFragment != null) {
oldFragment.dismiss();
}
SupportDatePickerDialogFragment fragment = new SupportDatePickerDialogFragment();
if (options != null) {
final Bundle args = createFragmentArguments(options);
fragment.setArguments(args);
}
final DatePickerDialogListener listener = new DatePickerDialogListener(promise);
fragment.setOnDismissListener(listener);
fragment.setOnDateSetListener(listener);
fragment.show(fragmentManager, FRAGMENT_TAG);
} else {
FragmentManager fragmentManager = activity.getFragmentManager();
DialogFragment oldFragment = (DialogFragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG);
if (oldFragment != null) {
oldFragment.dismiss();
}
DatePickerDialogFragment fragment = new DatePickerDialogFragment();
if (options != null) {
final Bundle args = createFragmentArguments(options);
fragment.setArguments(args);
}
final DatePickerDialogListener listener = new DatePickerDialogListener(promise);
fragment.setOnDismissListener(listener);
fragment.setOnDateSetListener(listener);
fragment.show(fragmentManager, FRAGMENT_TAG);

FragmentManager fragmentManager = activity.getFragmentManager();
DialogFragment oldFragment = (DialogFragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG);
if (oldFragment != null) {
oldFragment.dismiss();
}
DatePickerDialogFragment fragment = new DatePickerDialogFragment();
if (options != null) {
final Bundle args = createFragmentArguments(options);
fragment.setArguments(args);
}
final DatePickerDialogListener listener = new DatePickerDialogListener(promise);
fragment.setOnDismissListener(listener);
fragment.setOnDateSetListener(listener);
fragment.show(fragmentManager, FRAGMENT_TAG);
}

private Bundle createFragmentArguments(ReadableMap options) {
Expand Down
Loading