react-native-launch-arguments
react-native-launch-arguments copied to clipboard
Empty set of launch arguments if used in a very early stage (Android)
Hi, Detox maintainer here 👋🏻
I've recently been making usage of this library (great job, BTW!) in Detox's self-test project. We see that quite clearly, on Android at least, if the launch arguments are used in a very early stage (e.g. in the app's index.js
), then intermittently, an empty arguments object is returned.
For example:
import React, {Component} from 'react';
import {
AppRegistry,
} from 'react-native';
import { LaunchArguments } from 'react-native-launch-arguments';
console.warn('DEBUG', LaunchArguments.value());
export default class ExampleApp extends Component {
// ...
}
AppRegistry.registerComponent('example', () => ExampleApp);
If the app is repeatedly launched using device.launchApp({ launchArgs: { 'my': 'arg' } })
, then you would see logs looking somewhere along the lines of:
DEBUG { my: arg }
DEBUG { my: arg }
DEBUG {}
DEBUG { my: arg }
DEBUG { my: arg }
DEBUG { my: arg }
DEBUG {}
Side note: I suppose there's a race condition here, sorting out the arguments into the NativeModule's constants.
@iamolegga do you think there's a way to get this sorted out somehow? Perhaps Detox's implementation could provide a decent alternative, although asynchronous.
@d4vidi sorry, I'm not able to investigate this in the nearest future. But I would be glad to merge fix for this. Maybe in the late 2022 I'll get back to this issue (and all the others) if on my current project we will use this lib
I could provide a fix but best if you give a general approval 😄
PR's are always welcome 🙂
Perhaps Detox's implementation could provide a decent alternative, although asynchronous.
I meant, an approval of this, in particular.
So you want to replace built-in method with the detox's one? Then we need to check that:
- [ ] returned data is consistent between platforms
- [ ] what about appium? maybe detect somehow which framework is installed and then chose the right method to resolve data.
Does getLaunchArguments mentioned in the detox's docs? If this is available for the end user then this library can be deprecated in favor of detox built-in method, right?
It is not a Detox top-level API - Detox never runs inside the app. The Detox code I pointed at was of Detox's self-test app.
The main question is whether you'd be willing to change the API in a breaking way, namely from:
import {LaunchArguments} from 'react-native-launch-arguments';
const args = LaunchArguments.values()
to something along the lines of:
import { NativeModules } from 'react-native';
const { LaunchArguments } = NativeModules;
const args = await LaunchArguments.values();
I believe we can do this inside index.js of this module:
import { NativeModules } from 'react-native';
const { LaunchArguments } = NativeModules;
export { LaunchArguments }
then only asynchrony will changed, and from my point of view that's ok if the bug can be fixed only this way
Cool