0.0.4 • Published 8 years ago

react-native-native-env v0.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

react-native-native-env

React Native Native Environment module can provide environment variables from native to js

Install

You can use rnpm to install native module easily;

npm install react-native-native-env --save
rnpm link

And in Android, you must change the line in MainActivity :

new RCTNativeEnvPackage()

to

new RCTNativeEnvPackage(BuildConfig.class)

Usage

In js:

import NativeEnv from 'react-native-native-env';

NativeEnv.get("APPLICATION_NAME"); // return application's name
NativeEnv.get("VERSION_NAME");// return application's version name

Yeah, we hava defined some native variables. These're:

KeySource ( Android )Source ( iOS )
APPLICATION_IDBuildConfig.APPLICATION_IDCFBundleIdentifier
APPLICATION_NAMEPackageManager.getApplicationLabelCFBundleName
VERSION_CODEBuildConfig.VERSION_CODECFBundleVersion
VERSION_NAMEBuildConfig.VERSION_NAMECFBundleShortVersionString
DEBUGBuildConfig.DEBUG#ifdef DEBUG

Also, you can add some environment variables before react-native runtime is running.

###For Android Your can send a Map when you init this Module:

HashMap<String, Object> envs = new HashMap();
envs.put("testInfo", "this is a string");
envs.put("testNumber", 23333);
new RCTNativeEnvPackage(BuildConfig.class, envs);

And you can add variables from everywhere before it's inited:

RCTNativeEnv.addEnv(key, value);
RCTNativeEnv.addEnvs(map);

###For iOS Your can just add variables from everywhere before react runtime running.

[LRDRCTNativeEnv addEnv:@"test" value:@"info"];
[LRDRCTNativeEnv addEnvs:@{@"testInfo":@"this is a string",@"testNumber":@23333}];