react-native-config 1.5.1 → 1.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -6
- package/android/build.gradle +21 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/lugg/RNCConfig/RNCConfigModule.java +30 -35
- package/android/src/main/java/com/lugg/RNCConfig/RNCConfigPackage.java +4 -6
- package/package.json +5 -4
- package/react-native-config.podspec +2 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Config variables for React Native apps
|
|
2
2
|
|
|
3
|
-
Module to expose config variables to your javascript code in React Native, supporting iOS, Android and Windows.
|
|
3
|
+
Module to expose config variables to your javascript code in React Native, supporting iOS, Android, macOS and Windows.
|
|
4
4
|
|
|
5
5
|
Bring some [12 factor](http://12factor.net/config) love to your mobile apps!
|
|
6
6
|
|
|
@@ -49,12 +49,12 @@ if cocoapods are used in the project then pod has to be installed as well:
|
|
|
49
49
|
(cd ios; pod install)
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
- Manual Link (iOS)
|
|
52
|
+
- Manual Link (iOS / macOS)
|
|
53
53
|
|
|
54
54
|
1. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]`
|
|
55
|
-
2. Go to `node_modules` ➜ `react-native-config` and add `ReactNativeConfig.xcodeproj`
|
|
55
|
+
2. Go to `node_modules` ➜ `react-native-config` ➜ `ios` and add `ReactNativeConfig.xcodeproj`
|
|
56
56
|
3. Expand the `ReactNativeConfig.xcodeproj` ➜ `Products` folder
|
|
57
|
-
4. In the project navigator, select your project. Add `
|
|
57
|
+
4. In the project navigator, select your project. Add `libRNCConfig.a` to your project's `Build Phases` ➜ `Link Binary With Libraries`
|
|
58
58
|
5. And go the Build Settings tab. Make sure All is toggled on (instead of Basic)
|
|
59
59
|
6. Look for Header Search Paths and add `$(SRCROOT)/../node_modules/react-native-config/ios/**` as `non-recursive`
|
|
60
60
|
|
|
@@ -136,6 +136,28 @@ defaultConfig {
|
|
|
136
136
|
}
|
|
137
137
|
```
|
|
138
138
|
|
|
139
|
+
## TypeScript declaration for your .env file
|
|
140
|
+
|
|
141
|
+
If you want to get autocompletion and typesafety for your .env files. Create a file named `react-native-config.d.ts` in the same directory where you put your type declarations, and add the following contents:
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
declare module 'react-native-config' {
|
|
145
|
+
export interface NativeConfig {
|
|
146
|
+
HOSTNAME?: string;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export const Config: NativeConfig
|
|
150
|
+
export default Config
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Then when you want to use it, you just write:
|
|
155
|
+
|
|
156
|
+
```
|
|
157
|
+
import Config from 'react-native-config';
|
|
158
|
+
console.log(Config.HOSTNAME);
|
|
159
|
+
```
|
|
160
|
+
|
|
139
161
|
## Native Usage
|
|
140
162
|
|
|
141
163
|
### Android
|
|
@@ -173,7 +195,7 @@ versionCode project.env.get("VERSION_CODE").toInteger()
|
|
|
173
195
|
|
|
174
196
|
Once again, remember variables stored in `.env` are published with your code, so **DO NOT put anything sensitive there like your app `signingConfigs`.**
|
|
175
197
|
|
|
176
|
-
### iOS
|
|
198
|
+
### iOS / macOS
|
|
177
199
|
|
|
178
200
|
Read variables declared in `.env` from your Obj-C classes like:
|
|
179
201
|
|
|
@@ -269,6 +291,10 @@ The same environment variable can be used to assemble releases with a different
|
|
|
269
291
|
```
|
|
270
292
|
$ cd android && ENVFILE=.env.staging ./gradlew assembleRelease
|
|
271
293
|
```
|
|
294
|
+
Note: When trying to release the bundle you need to export with a different config
|
|
295
|
+
```
|
|
296
|
+
$ cd android && export ENVFILE=.env.staging ./gradlew bundleRelease
|
|
297
|
+
```
|
|
272
298
|
|
|
273
299
|
Alternatively, you can define a map in `build.gradle` associating builds with env files. Do it before the `apply from` call, and use build cases in lowercase, like:
|
|
274
300
|
|
|
@@ -286,7 +312,7 @@ Also note that besides requiring lowercase, the matching is done with `buildFlav
|
|
|
286
312
|
|
|
287
313
|
<a name="ios-multi-scheme"></a>
|
|
288
314
|
|
|
289
|
-
#### iOS
|
|
315
|
+
#### iOS / macOS
|
|
290
316
|
|
|
291
317
|
The basic idea in iOS is to have one scheme per environment file, so you can easily alternate between them.
|
|
292
318
|
|
package/android/build.gradle
CHANGED
|
@@ -15,7 +15,28 @@ def safeExtGet(prop, fallback) {
|
|
|
15
15
|
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
def supportsNamespace() {
|
|
19
|
+
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.');
|
|
20
|
+
def major = parsed[0].toInteger();
|
|
21
|
+
def minor = parsed[1].toInteger();
|
|
22
|
+
|
|
23
|
+
// Namespace support was added in 7.3.0
|
|
24
|
+
if (major == 7 && minor >= 3) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return major >= 8;
|
|
29
|
+
}
|
|
30
|
+
|
|
18
31
|
android {
|
|
32
|
+
if(supportsNamespace()) {
|
|
33
|
+
namespace = "com.lugg.RNCConfig"
|
|
34
|
+
sourceSets {
|
|
35
|
+
main {
|
|
36
|
+
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
19
40
|
compileSdkVersion rootProject.ext.compileSdkVersion
|
|
20
41
|
|
|
21
42
|
defaultConfig {
|
|
@@ -3,10 +3,8 @@ package com.lugg.RNCConfig;
|
|
|
3
3
|
import android.content.Context;
|
|
4
4
|
import android.content.res.Resources;
|
|
5
5
|
import android.util.Log;
|
|
6
|
-
|
|
7
6
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
8
7
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
9
|
-
|
|
10
8
|
import java.lang.ClassNotFoundException;
|
|
11
9
|
import java.lang.IllegalAccessException;
|
|
12
10
|
import java.lang.reflect.Field;
|
|
@@ -14,43 +12,40 @@ import java.util.Map;
|
|
|
14
12
|
import java.util.HashMap;
|
|
15
13
|
|
|
16
14
|
public class RNCConfigModule extends ReactContextBaseJavaModule {
|
|
17
|
-
public RNCConfigModule(ReactApplicationContext reactContext) {
|
|
18
|
-
super(reactContext);
|
|
19
|
-
}
|
|
20
15
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
16
|
+
public RNCConfigModule(ReactApplicationContext reactContext) {
|
|
17
|
+
super(reactContext);
|
|
18
|
+
}
|
|
25
19
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
@Override
|
|
21
|
+
public String getName() {
|
|
22
|
+
return "RNCConfigModule";
|
|
23
|
+
}
|
|
29
24
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
String className;
|
|
34
|
-
try {
|
|
35
|
-
className = context.getString(resId);
|
|
36
|
-
} catch (Resources.NotFoundException e) {
|
|
37
|
-
className = getReactApplicationContext().getApplicationContext().getPackageName();
|
|
38
|
-
}
|
|
39
|
-
Class clazz = Class.forName(className + ".BuildConfig");
|
|
40
|
-
Field[] fields = clazz.getDeclaredFields();
|
|
41
|
-
for(Field f: fields) {
|
|
25
|
+
@Override
|
|
26
|
+
public Map<String, Object> getConstants() {
|
|
27
|
+
final Map<String, Object> constants = new HashMap<>();
|
|
42
28
|
try {
|
|
43
|
-
|
|
29
|
+
Context context = getReactApplicationContext();
|
|
30
|
+
int resId = context.getResources().getIdentifier("build_config_package", "string", context.getPackageName());
|
|
31
|
+
String className;
|
|
32
|
+
try {
|
|
33
|
+
className = context.getString(resId);
|
|
34
|
+
} catch (Resources.NotFoundException e) {
|
|
35
|
+
className = getReactApplicationContext().getApplicationContext().getPackageName();
|
|
36
|
+
}
|
|
37
|
+
Class clazz = Class.forName(className + ".BuildConfig");
|
|
38
|
+
Field[] fields = clazz.getDeclaredFields();
|
|
39
|
+
for (Field f : fields) {
|
|
40
|
+
try {
|
|
41
|
+
constants.put(f.getName(), f.get(null));
|
|
42
|
+
} catch (IllegalAccessException e) {
|
|
43
|
+
Log.d("ReactNative", "ReactConfig: Could not access BuildConfig field " + f.getName());
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
} catch (ClassNotFoundException e) {
|
|
47
|
+
Log.d("ReactNative", "ReactConfig: Could not find BuildConfig class");
|
|
44
48
|
}
|
|
45
|
-
|
|
46
|
-
Log.d("ReactNative", "ReactConfig: Could not access BuildConfig field " + f.getName());
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
catch (ClassNotFoundException e) {
|
|
51
|
-
Log.d("ReactNative", "ReactConfig: Could not find BuildConfig class");
|
|
49
|
+
return constants;
|
|
52
50
|
}
|
|
53
|
-
|
|
54
|
-
return constants;
|
|
55
|
-
}
|
|
56
51
|
}
|
|
@@ -5,21 +5,19 @@ import com.facebook.react.bridge.JavaScriptModule;
|
|
|
5
5
|
import com.facebook.react.bridge.NativeModule;
|
|
6
6
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
7
7
|
import com.facebook.react.uimanager.ViewManager;
|
|
8
|
-
|
|
9
8
|
import java.util.Arrays;
|
|
10
9
|
import java.util.Collections;
|
|
11
10
|
import java.util.List;
|
|
12
11
|
|
|
13
12
|
public class RNCConfigPackage implements ReactPackage {
|
|
13
|
+
|
|
14
14
|
@Override
|
|
15
15
|
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
|
16
|
-
return Arrays.<NativeModule>asList(
|
|
17
|
-
new RNCConfigModule(reactContext)
|
|
18
|
-
);
|
|
16
|
+
return Arrays.<NativeModule>asList(new RNCConfigModule(reactContext));
|
|
19
17
|
}
|
|
20
18
|
|
|
21
|
-
public List<Class<? extends JavaScriptModule>> createJSModules() {
|
|
22
|
-
return Collections.emptyList();
|
|
19
|
+
public List<Class<? extends JavaScriptModule>> createJSModules() {
|
|
20
|
+
return Collections.emptyList();
|
|
23
21
|
}
|
|
24
22
|
|
|
25
23
|
@Override
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-config",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.3",
|
|
4
4
|
"description": "Expose config variables to React Native apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"env",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
],
|
|
15
15
|
"homepage": "https://github.com/luggit/react-native-config",
|
|
16
16
|
"contributors": [
|
|
17
|
-
"Luan Curti <luancurti@gmail.com> (https://github.com/luancurti)"
|
|
17
|
+
"Luan Curti <luancurti@gmail.com> (https://github.com/luancurti)",
|
|
18
|
+
"Amer Lotfi Orimi <amerllica@gmail.com> (https://github.com/amerllica)"
|
|
18
19
|
],
|
|
19
20
|
"repository": {
|
|
20
21
|
"type": "git",
|
|
@@ -34,8 +35,8 @@
|
|
|
34
35
|
"types": "./index.d.ts",
|
|
35
36
|
"license": "MIT",
|
|
36
37
|
"devDependencies": {
|
|
37
|
-
"@semantic-release/git": "^
|
|
38
|
-
"semantic-release": "^
|
|
38
|
+
"@semantic-release/git": "^10.0.1",
|
|
39
|
+
"semantic-release": "^19.0.5"
|
|
39
40
|
},
|
|
40
41
|
"peerDependencies": {
|
|
41
42
|
"react-native-windows": ">=0.61"
|
|
@@ -15,6 +15,8 @@ Pod::Spec.new do |s|
|
|
|
15
15
|
s.license = 'MIT'
|
|
16
16
|
s.ios.deployment_target = '9.0'
|
|
17
17
|
s.tvos.deployment_target = '9.0'
|
|
18
|
+
s.macos.deployment_target = '10.15'
|
|
19
|
+
s.visionos.deployment_target = '1.0'
|
|
18
20
|
|
|
19
21
|
s.source = { git: 'https://github.com/luggit/react-native-config.git', tag: "v#{s.version.to_s}" }
|
|
20
22
|
s.script_phase = {
|