Coder Social home page Coder Social logo

arthurjamain / react-native-native-env Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aksonov/react-native-native-env

0.0 2.0 1.0 108 KB

Providing environment variables from native to js in React Native.

Java 36.87% JavaScript 15.64% Objective-C 39.01% Python 8.48%

react-native-native-env's Introduction

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:

Key Source ( Android ) Source ( iOS )
APPLICATION_ID BuildConfig.APPLICATION_ID CFBundleIdentifier
APPLICATION_NAME PackageManager.getApplicationLabel CFBundleName
VERSION_CODE BuildConfig.VERSION_CODE CFBundleVersion
VERSION_NAME BuildConfig.VERSION_NAME CFBundleShortVersionString
DEBUG BuildConfig.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}];

react-native-native-env's People

Contributors

arthurjamain avatar

Watchers

 avatar  avatar

Forkers

maraujop

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.