2016-02-22 17:28:49 -08:00
2016-02-22 17:28:49 -08:00
2016-02-22 17:21:49 -08:00
2016-02-22 13:06:06 -08:00
2016-02-22 17:27:59 -08:00

Config variables for React Native apps

Module to expose config variables to your javascript code in React Native, supporting both iOS and Android.

Bring some 12 factor love to your mobile apps!

Usage

Declare config variables in .env:

API_URL=https://myapi.com
LOG_ERRORS=true

Then access from your app:

import Config from 'react-native-config'

Config.API_URL     // 'https://myapi.com'
Config.SHOW_ERRORS // 'true'

Setup

Install the package:

$ npm install react-native-config --save

Then follow the platform-specific instructions below:

iOS

Make sure you have rnpm installed:

$ npm install rnpm --global

Then link this package to your project:

$ rnpm link react-native-config

Android

  1. Include this module in android/settings.gradle:
include ':react-native-android-config'
include ':app'

project(':react-native-android-config').projectDir = new File(rootProject.projectDir,
  '../node_modules/react-native-android-config/android')
  1. Apply a plugin and add dependency to your app build, in android/app/build.gradle:
// first line
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"

// down below
dependencies {
    ...
    compile project(':react-native-android-config')
}
  1. Change your main activity to add a new package, in android/app/src/main/.../MainActivity.java:
import com.lugg.ReactConfig.ReactConfigPackage; // add import

public class MainActivity extends ReactActivity {
    // ...

    @Override
    protected List<ReactPackage> getPackages() {
        return Arrays.<ReactPackage>asList(
            new MainReactPackage(),
            new ReactNativeConfigPackage() // add package
        );
    }
Description
Bring some 12 factor love to your mobile apps!
Readme MIT
Languages
Objective-C 28.3%
Java 22.6%
C++ 16.3%
Ruby 15.9%
Starlark 9.4%
Other 7.5%