react-native-launch-arguments
Version:
React Native module for getting launch arguments
33 lines (32 loc) • 1.02 kB
JavaScript
import { NativeModules, Platform } from "react-native";
const LINKING_ERROR = `The package 'react-native-launch-arguments' doesn't seem to be linked. Make sure: \n\n` +
Platform.select({ ios: "- You have run 'pod install'\n", default: "" }) +
"- You rebuilt the app after installing the package\n" +
"- You are not using Expo managed workflow\n";
const LaunchArgumentsModule = NativeModules.LaunchArguments
? NativeModules.LaunchArguments
: new Proxy({}, {
get() {
throw new Error(LINKING_ERROR);
},
});
let parsed = null;
export const LaunchArguments = {
value() {
if (parsed) {
return parsed;
}
parsed = {};
const raw = LaunchArgumentsModule.value;
for (const k in raw) {
const rawValue = raw[k];
try {
parsed[k] = JSON.parse(rawValue);
}
catch {
parsed[k] = rawValue;
}
}
return parsed;
},
};