react-native-config 1.5.0 → 1.5.2

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 CHANGED
@@ -52,9 +52,9 @@ if cocoapods are used in the project then pod has to be installed as well:
52
52
  - Manual Link (iOS)
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 `libReactNativeConfig.a` to your project's `Build Phases` ➜ `Link Binary With Libraries`
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
 
@@ -78,13 +78,13 @@ if cocoapods are used in the project then pod has to be installed as well:
78
78
  **MainApplication.java**
79
79
 
80
80
  ```diff
81
- + import com.lugg.ReactNativeConfig.ReactNativeConfigPackage;
81
+ + import com.lugg.RNCConfig.RNCConfigPackage;
82
82
 
83
83
  @Override
84
84
  protected List<ReactPackage> getPackages() {
85
85
  return Arrays.asList(
86
86
  new MainReactPackage()
87
- + new ReactNativeConfigPackage()
87
+ + new RNCConfigPackage()
88
88
  );
89
89
  }
90
90
  ```
@@ -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
@@ -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
 
@@ -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
- @Override
22
- public String getName() {
23
- return "RNCConfigModule";
24
- }
16
+ public RNCConfigModule(ReactApplicationContext reactContext) {
17
+ super(reactContext);
18
+ }
25
19
 
26
- @Override
27
- public Map<String, Object> getConstants() {
28
- final Map<String, Object> constants = new HashMap<>();
20
+ @Override
21
+ public String getName() {
22
+ return "RNCConfigModule";
23
+ }
29
24
 
30
- try {
31
- Context context = getReactApplicationContext();
32
- int resId = context.getResources().getIdentifier("build_config_package", "string", context.getPackageName());
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
- constants.put(f.getName(), f.get(null));
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
- catch (IllegalAccessException e) {
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.0",
3
+ "version": "1.5.2",
4
4
  "description": "Expose config variables to React Native apps",
5
5
  "keywords": [
6
6
  "env",
@@ -15,6 +15,7 @@ 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.visionos.deployment_target = '1.0'
18
19
 
19
20
  s.source = { git: 'https://github.com/luggit/react-native-config.git', tag: "v#{s.version.to_s}" }
20
21
  s.script_phase = {
@@ -26,7 +27,7 @@ HOST_PATH="$SRCROOT/../.."
26
27
  ),
27
28
  execution_position: :before_compile,
28
29
  input_files: ['$PODS_TARGET_SRCROOT/ios/ReactNativeConfig/BuildDotenvConfig.rb'],
29
- output_files: ['$BUILD_DIR/GeneratedInfoPlistDotEnv.h']
30
+ output_files: ['$BUILD_DIR/GeneratedInfoPlistDotEnv.h', '$PODS_TARGET_SRCROOT/ios/ReactNativeConfig/GeneratedDotEnv.m']
30
31
  }
31
32
 
32
33
  s.requires_arc = true