Skip to content

Commit

Permalink
Merge pull request facebook#1131 from amgleitman/0.67-merge
Browse files Browse the repository at this point in the history
Merge main branch back in sync with facebook/react-native
  • Loading branch information
amgleitman committed Apr 21, 2022
2 parents 659375d + ff0a182 commit 1b5cf31
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,14 @@ public interface ReactInstanceEventListener {
/* accessed from any thread */
private final JavaScriptExecutorFactory mJavaScriptExecutorFactory;

// See {@code ReactInstanceManagerBuilder} for description of all flags here.
private @Nullable List<String> mViewManagerNames = null;
private final @Nullable JSBundleLoader mBundleLoader;
private final @Nullable String mJSMainModulePath; /* path to JS bundle root on Metro */
private final List<ReactPackage> mPackages;
private final DevSupportManager mDevSupportManager;
private final boolean mUseDeveloperSupport;
private final boolean mRequireActivity;
private @Nullable ComponentNameResolverManager mComponentNameResolverManager;
private @Nullable RuntimeSchedulerManager mRuntimeSchedulerManager;
private final @Nullable NotThreadSafeBridgeIdleDebugListener mBridgeIdleDebugListener;
Expand Down Expand Up @@ -216,6 +218,7 @@ public static ReactInstanceManagerBuilder builder() {
@Nullable String jsMainModulePath,
List<ReactPackage> packages,
boolean useDeveloperSupport,
boolean requireActivity,
@Nullable NotThreadSafeBridgeIdleDebugListener bridgeIdleDebugListener,
LifecycleState initialLifecycleState,
@Nullable UIImplementationProvider mUIImplementationProvider,
Expand All @@ -233,6 +236,7 @@ public static ReactInstanceManagerBuilder builder() {

DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(applicationContext);

// See {@code ReactInstanceManagerBuilder} for description of all flags here.
mApplicationContext = applicationContext;
mCurrentActivity = currentActivity;
mDefaultBackButtonImpl = defaultHardwareBackBtnHandler;
Expand All @@ -241,6 +245,7 @@ public static ReactInstanceManagerBuilder builder() {
mJSMainModulePath = jsMainModulePath;
mPackages = new ArrayList<>();
mUseDeveloperSupport = useDeveloperSupport;
mRequireActivity = requireActivity;
Systrace.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "ReactInstanceManager.initDevSupportManager");
mDevSupportManager =
Expand Down Expand Up @@ -558,16 +563,20 @@ public void onHostPause() {
* @param activity the activity being paused
*/
@ThreadConfined(UI)
public void onHostPause(Activity activity) {
Assertions.assertNotNull(mCurrentActivity);
Assertions.assertCondition(
activity == mCurrentActivity,
"Pausing an activity that is not the current activity, this is incorrect! "
+ "Current activity: "
+ mCurrentActivity.getClass().getSimpleName()
+ " "
+ "Paused activity: "
+ activity.getClass().getSimpleName());
public void onHostPause(@Nullable Activity activity) {
if (mRequireActivity) {
Assertions.assertCondition(mCurrentActivity != null);
}
if (mCurrentActivity != null) {
Assertions.assertCondition(
activity == mCurrentActivity,
"Pausing an activity that is not the current activity, this is incorrect! "
+ "Current activity: "
+ mCurrentActivity.getClass().getSimpleName()
+ " "
+ "Paused activity: "
+ activity.getClass().getSimpleName());
}
onHostPause();
}

Expand All @@ -583,7 +592,8 @@ public void onHostPause(Activity activity) {
* this instance of {@link ReactInstanceManager}.
*/
@ThreadConfined(UI)
public void onHostResume(Activity activity, DefaultHardwareBackBtnHandler defaultBackButtonImpl) {
public void onHostResume(
@Nullable Activity activity, DefaultHardwareBackBtnHandler defaultBackButtonImpl) {
UiThreadUtil.assertOnUiThread();

mDefaultBackButtonImpl = defaultBackButtonImpl;
Expand All @@ -592,7 +602,7 @@ public void onHostResume(Activity activity, DefaultHardwareBackBtnHandler defaul

/** Use this method when the activity resumes. */
@ThreadConfined(UI)
public void onHostResume(Activity activity) {
public void onHostResume(@Nullable Activity activity) {
UiThreadUtil.assertOnUiThread();

mCurrentActivity = activity;
Expand Down Expand Up @@ -631,8 +641,8 @@ public void onViewDetachedFromWindow(View v) {
// activity is attached to window, we can enable dev support immediately
mDevSupportManager.setDevSupportEnabled(true);
}
} else {
// there is no activity, we can enable dev support
} else if (!mRequireActivity) {
// there is no activity, but we can enable dev support
mDevSupportManager.setDevSupportEnabled(true);
}
}
Expand Down Expand Up @@ -666,7 +676,9 @@ public void onHostDestroy() {
* @param activity the activity being destroyed
*/
@ThreadConfined(UI)
public void onHostDestroy(Activity activity) {
public void onHostDestroy(@Nullable Activity activity) {
// In some cases, Activity may (correctly) be null.
// See mRequireActivity flag.
if (activity == mCurrentActivity) {
onHostDestroy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class ReactInstanceManagerBuilder {
private @Nullable NotThreadSafeBridgeIdleDebugListener mBridgeIdleDebugListener;
private @Nullable Application mApplication;
private boolean mUseDeveloperSupport;
private boolean mRequireActivity;
private @Nullable LifecycleState mInitialLifecycleState;
private @Nullable UIImplementationProvider mUIImplementationProvider;
private @Nullable NativeModuleCallExceptionHandler mNativeModuleCallExceptionHandler;
Expand Down Expand Up @@ -171,6 +172,16 @@ public ReactInstanceManagerBuilder setUseDeveloperSupport(boolean useDeveloperSu
return this;
}

/**
* When {@code false}, indicates that correct usage of React Native will NOT involve an Activity.
* For the vast majority of Android apps in the ecosystem, this will not need to change. Unless
* you really know what you're doing, you should probably not change this!
*/
public ReactInstanceManagerBuilder setRequireActivity(boolean requireActivity) {
mRequireActivity = requireActivity;
return this;
}

/**
* Sets the initial lifecycle state of the host. For example, if the host is already resumed at
* creation time, we wouldn't expect an onResume call until we get an onPause call.
Expand Down Expand Up @@ -283,6 +294,7 @@ public ReactInstanceManager build() {
mJSMainModulePath,
mPackages,
mUseDeveloperSupport,
mRequireActivity,
mBridgeIdleDebugListener,
Assertions.assertNotNull(mInitialLifecycleState, "Initial lifecycle state was not set"),
mUIImplementationProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ protected ReactInstanceManager createReactInstanceManager() {
.setApplication(mApplication)
.setJSMainModulePath(getJSMainModuleName())
.setUseDeveloperSupport(getUseDeveloperSupport())
.setRequireActivity(getShouldRequireActivity())
.setRedBoxHandler(getRedBoxHandler())
.setJavaScriptExecutorFactory(getJavaScriptExecutorFactory())
.setUIImplementationProvider(getUIImplementationProvider())
Expand Down Expand Up @@ -124,6 +125,11 @@ protected UIImplementationProvider getUIImplementationProvider() {
return null;
}

/** Returns whether or not to treat it as normal if Activity is null. */
public boolean getShouldRequireActivity() {
return true;
}

/**
* Returns the name of the main module. Determines the URL used to fetch the JS bundle from Metro.
* It is only used when dev support is enabled. This is the first file to be executed once the
Expand Down
12 changes: 12 additions & 0 deletions packages/eslint-config-react-native-community/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,18 @@ has-bigints@^1.0.1:
resolved "https://registry.yarnpkg.com/has-bigints/-/has-bigints-1.0.1.tgz#64fe6acb020673e3b78db035a5af69aa9d07b113"
integrity sha512-LSBS2LjbNBTf6287JEbEzvJgftkF5qFkmCo9hDRpAzKhUOlJ+hx8dd4USs00SgsUNwc4617J9ki5YtEClM2ffA==

globby@^11.0.1:
version "11.0.3"
resolved "https://registry.yarnpkg.com/globby/-/globby-11.0.3.tgz#9b1f0cb523e171dd1ad8c7b2a9fb4b644b9593cb"
integrity sha512-ffdmosjA807y7+lA1NM0jELARVmYul/715xiILEjo3hBLPTcirgQNnXECn5g3mtR8TOLCVbkfua1Hpen25/Xcg==
dependencies:
array-union "^2.1.0"
dir-glob "^3.0.1"
fast-glob "^3.1.1"
ignore "^5.1.4"
merge2 "^1.3.0"
slash "^3.0.0"

has-flag@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"
Expand Down
38 changes: 27 additions & 11 deletions packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,8 @@
isa = PBXNativeTarget;
buildConfigurationList = E7DB20A622B2BA84005AC45F /* Build configuration list for PBXNativeTarget "RNTesterUnitTests" */;
buildPhases = (
1FD7CC5A44DCEE15C8D13E0A /* [CP] Check Pods Manifest.lock */,
0E64AA1E46530FED7A0515F4 /* [CP] Check Pods Manifest.lock */,
1FD7CC5A44DCEE15C8D13E0A /* Start Metro */,
E7DB209B22B2BA84005AC45F /* Sources */,
E7DB209C22B2BA84005AC45F /* Frameworks */,
E7DB209D22B2BA84005AC45F /* Resources */,
Expand Down Expand Up @@ -1018,6 +1019,28 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
0E64AA1E46530FED7A0515F4 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputFileListPaths = (
);
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-RNTesterUnitTests-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
10AB8F2FA248D122E5FC5D4C /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -1057,26 +1080,19 @@
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-RNTester-macOS/Pods-RNTester-macOS-resources.sh\"\n";
showEnvVarsInLog = 0;
};
1FD7CC5A44DCEE15C8D13E0A /* [CP] Check Pods Manifest.lock */ = {
1FD7CC5A44DCEE15C8D13E0A /* Start Metro */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputFileListPaths = (
);
name = "Start Metro";
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-RNTesterUnitTests-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
shellScript = "export RCT_METRO_PORT=\"${RCT_METRO_PORT:=8081}\"\necho \"export RCT_METRO_PORT=${RCT_METRO_PORT}\" > \"${SRCROOT}/../../scripts/.packager.env\"\nif [ -z \"${RCT_NO_LAUNCH_PACKAGER+xxx}\" ] ; then\n if nc -w 5 -z localhost ${RCT_METRO_PORT} ; then\n if ! curl -s \"http://localhost:${RCT_METRO_PORT}/status\" | grep -q \"packager-status:running\" ; then\n echo \"Port ${RCT_METRO_PORT} already in use, packager is either not running or not running correctly\"\n exit 2\n fi\n else\n open \"$SRCROOT/../../scripts/launchPackager.command\" || echo \"Can't start packager automatically\"\n fi\nfi\n";
showEnvVarsInLog = 0;
};
26905525A793EABD06A4E9DD /* Start Metro */ = {
Expand Down
2 changes: 2 additions & 0 deletions template/ios/HelloWorld.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@
"\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"",
"\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"",
"\"$(inherited)\"",
"\"$(SDKROOT)/usr/lib/swift\"",
);
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -497,6 +498,7 @@
"\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"",
"\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"",
"\"$(inherited)\"",
"\"$(SDKROOT)/usr/lib/swift\"",
);
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
Expand Down
Loading

0 comments on commit 1b5cf31

Please sign in to comment.