Restore usage of launch-args lib (#4060)

* Restore usage of launch-args lib, stable in newer RN's

* Integrate launch-arguments into inner screens

* Work-around rn-launch-args import issues by require()-ing form componentDidMount()

* Fix a subtle launch-args migration issue in launch-args e2e test

* Improve warning comment over early usage of rn-launch-args

* Intergate react-native-launch-arguments@next
This commit is contained in:
d4vidi
2023-05-29 14:48:37 +03:00
committed by GitHub
parent a820840247
commit 6841b9cb3f
9 changed files with 42 additions and 57 deletions
+1
View File
@@ -98,6 +98,7 @@ dependencies {
implementation project(':react-native-community-checkbox')
implementation project(':react-native-community-geolocation')
implementation project(':react-native-datetimepicker')
implementation project(':react-native-launcharguments')
androidTestImplementation(project(path: ':detox'))
androidTestImplementation 'com.linkedin.testbutler:test-butler-library:2.2.1'
@@ -11,37 +11,39 @@ import com.reactnativecommunity.geolocation.GeolocationPackage;
import com.reactnativecommunity.slider.ReactSliderPackage;
import com.reactnativecommunity.webview.RNCWebViewPackage;
import com.reactcommunity.rndatetimepicker.RNDateTimePickerPackage;
import com.reactnativelauncharguments.LaunchArgumentsPackage;
import java.util.Arrays;
import java.util.List;
class DetoxRNHost extends ReactNativeHost {
protected DetoxRNHost(Application application) {
super(application);
}
protected DetoxRNHost(Application application) {
super(application);
}
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
// TurboModules must also be loaded here providing a valid TurboReactPackage implementation:
// packages.add(new TurboReactPackage() { ... });
// If you have custom Fabric Components, their ViewManagers should also be loaded here
// inside a ReactPackage.
return Arrays.asList(
new MainReactPackage(),
new ReactSliderPackage(),
new GeolocationPackage(),
new RNCWebViewPackage(),
new NativeModulePackage(),
new AsyncStoragePackage(),
new ReactCheckBoxPackage(),
new RNDateTimePickerPackage()
);
}
@Override
protected List<ReactPackage> getPackages() {
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
// TurboModules must also be loaded here providing a valid TurboReactPackage implementation:
// packages.add(new TurboReactPackage() { ... });
// If you have custom Fabric Components, their ViewManagers should also be loaded here
// inside a ReactPackage.
return Arrays.asList(
new MainReactPackage(),
new ReactSliderPackage(),
new GeolocationPackage(),
new RNCWebViewPackage(),
new NativeModulePackage(),
new AsyncStoragePackage(),
new ReactCheckBoxPackage(),
new RNDateTimePickerPackage(),
new LaunchArgumentsPackage()
);
}
}
@@ -19,7 +19,6 @@ import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.WritableMap;
public class NativeModule extends ReactContextBaseJavaModule {
@@ -78,11 +77,6 @@ public class NativeModule extends ReactContextBaseJavaModule {
reactContext.getCurrentActivity().runOnUiThread(() -> {}); // TODO?
}
@ReactMethod
public void getLaunchArguments(Promise promise) {
promise.resolve(parseIntentExtras("launchArgs"));
}
@ReactMethod
public void parseNotificationData(String innerKey, Promise promise) {
Bundle data = getIntentExtras(innerKey);
@@ -122,11 +116,6 @@ public class NativeModule extends ReactContextBaseJavaModule {
rnExtension.toggleNetworkSynchronization(enable);
}
private WritableMap parseIntentExtras(String bundleKey) {
Bundle extras = getIntentExtras(bundleKey);
return Arguments.fromBundle(extras);
}
private Bundle getIntentExtras(String bundleKey) {
final Activity currentActivity = getCurrentActivity();
if (currentActivity == null) {
+4 -1
View File
@@ -40,4 +40,7 @@ include ':@react-native-community_slider'
project(':@react-native-community_slider').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/slider/android')
include ':react-native-datetimepicker'
project(':react-native-datetimepicker').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/datetimepicker/android')
project(':react-native-datetimepicker').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/datetimepicker/android')
include ':react-native-launcharguments'
project(':react-native-launcharguments').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-launch-arguments/android')
+2 -5
View File
@@ -1,12 +1,10 @@
import {
AppRegistry,
NativeModules,
} from 'react-native';
import {LaunchArguments} from 'react-native-launch-arguments';
import example from './src/app';
const { NativeModule } = NativeModules;
class exampleAndroid extends example {
async componentDidMount() {
await super.componentDidMount();
@@ -14,8 +12,7 @@ class exampleAndroid extends example {
}
async _registerEarlyCrashIfNeeded() {
const launchArguments = await NativeModule.getLaunchArguments();
if (launchArguments.simulateEarlyCrash) {
if (LaunchArguments.value().simulateEarlyCrash) {
console.warn('simulateEarlyCrash=true detected: Will crash in a few seconds from now (all-the-while keeping the app busy)...');
this._setupBusyFutureCrash();
}
+3 -6
View File
@@ -1,14 +1,11 @@
import { LogBox, AppRegistry } from 'react-native';
import {LaunchArguments} from 'react-native-launch-arguments';
import example from './src/app';
import { LogBox } from 'react-native';
import {
AppRegistry,
} from 'react-native';
import example from './src/app';
class exampleIos extends example {}
if (LaunchArguments.value().simulateEarlyCrash) { // TODO integrate this into iOS' NativeModule and lose react-native-launch-arguments
if (LaunchArguments.value().simulateEarlyCrash) {
throw new Error('Simulating early crash');
}
+1 -1
View File
@@ -42,7 +42,7 @@
"react": "18.1.0",
"react-native": "0.70.7",
"react-native-gradle-plugin": "^0.0.7",
"react-native-launch-arguments": "^3.1.0",
"react-native-launch-arguments": "next",
"react-native-webview": "^11.18.1"
},
"devDependencies": {
@@ -51,7 +51,7 @@ export default class AbstractArgsListScreen extends Component {
renderArgsList() {
return _.reduce(this.state.argsList, (result, argValue, argName) => {
const _argValue = (_.isArray(argValue) || _.isObject(argValue) ? JSON.stringify(argValue) : argValue);
const _argValue = (_.isArray(argValue) || _.isObject(argValue) ? JSON.stringify(argValue) : argValue.toString());
const itemId = `${this.contextName}-${argName}`;
const nameId = itemId + '.name';
const valueId = itemId + '.value';
+2 -6
View File
@@ -1,18 +1,14 @@
import React from 'react';
import {
NativeModules,
} from 'react-native';
import {LaunchArguments} from 'react-native-launch-arguments';
import AbstractArgsListScreen from './AbstractArgsListScreen';
const { NativeModule } = NativeModules;
export default class LaunchArgsScreen extends AbstractArgsListScreen {
constructor(props) {
super(props, 'launchArg');
}
async readArguments() {
return await NativeModule.getLaunchArguments();
return LaunchArguments.value();
}
getTitle() {