expo-native-launch-arguments
v5.0.1
Published
Expo module for getting launch arguments
Maintainers
Readme
expo-native-launch-arguments
Note: This repository is a fork of react-native-launch-arguments by @iamolegga. I'm awaiting permission to push a branch and open a PR to the original repository. In the meantime, I created this separate repo to provide New Architecture and Expo managed workflow support. This repository can be deleted if the admin of the original repo requests it.
Expo module to get launch arguments.
Makes passing parameters from testing libraries and debug tools to React Native super easy.
Built with Expo Modules API using Swift and Kotlin.
Install
npm install expo-native-launch-arguments
npx expo prebuildOr with yarn:
yarn add expo-native-launch-arguments
npx expo prebuildRequirements
- Expo SDK 54+
- React Native 0.76+
- iOS 15.1+
Usage
JavaScript
import { LaunchArguments } from "expo-native-launch-arguments";
const args = LaunchArguments.value();
console.log(args); // { myKey: "myValue", myFlag: true }TypeScript
import { LaunchArguments } from "expo-native-launch-arguments";
interface MyExpectedArgs {
authToken?: string;
skipAuth?: boolean;
}
const args = LaunchArguments.value<MyExpectedArgs>();Integrating with End-to-end Testing Tools
The primary use case is with end-to-end testing tools like Detox.
Detox
await device.launchApp({
launchArgs: {
authToken: "test-token-123",
skipOnboarding: true,
},
});- See
device.launchApp({launchArgs:{...}}) - See launch arguments guide for full details.
Appium
capabilities: {
optionalIntentArguments: `--ez myBool true --es myStr 'string text'`, // Android
processArguments: { args: ['-myBool', 'true', '-myStr', 'string text'] }, // iOS
}Maestro
- launchApp:
appId: "com.example.app"
arguments:
foo: "This is a string"
isFooEnabled: false
fooValue: 3.24Xcode
In Xcode, add launch arguments in the Scheme editor:
- Product → Scheme → Edit Scheme... → Run → Arguments tab → Arguments Passed On Launch
- Prefix each argument with
-
-hello "world"This results in { "hello": "world" }.
Platform-specific Notes
iOS
Reads arguments from ProcessInfo.processInfo.arguments.
Verifying on iPhone Simulator
xcrun simctl launch booted com.MyAppBundleId -myKey "myValue"Android
Reads from:
intent.getBundleExtra("launchArgs")for Detoxintent.getExtras()for ADB params
Passing args via ADB
adb shell am start -n com.example/.MainActivity --es myKey "myValue" --ez myBool trueDevelopment
Building the library
npm run buildRunning the example app
cd example
npm install
npx expo prebuild
npm run iosRunning Detox tests
cd example
npm run detox:iosLicense
MIT
