Skip to content

Commit 8f7e7f6

Browse files
committed
added support for fetching configs from android and ios envs
1 parent b0872e3 commit 8f7e7f6

File tree

7 files changed

+65
-6
lines changed

7 files changed

+65
-6
lines changed

android/.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>android</name>
4+
<comment>Project android created by Buildship.</comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
connection.project.dir=
2+
eclipse.preferences.version=1

android/src/main/java/com/reactlibrary/RNConfigReaderModule.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
package com.reactlibrary;
33

4+
import java.lang.reflect.*;
45
import com.facebook.react.bridge.ReactApplicationContext;
56
import com.facebook.react.bridge.ReactContextBaseJavaModule;
67
import com.facebook.react.bridge.ReactMethod;
@@ -19,4 +20,25 @@ public RNConfigReaderModule(ReactApplicationContext reactContext) {
1920
public String getName() {
2021
return "RNConfigReader";
2122
}
23+
24+
@Override
25+
public Map<String, Object> getConstants() {
26+
final Map<String, Object> constants = new HashMap<>();
27+
Field[] fields = BuildConfig.class.getDeclaredFields();
28+
for (Field f : fields) {
29+
if (Modifier.isStatic(f.getModifiers())) {
30+
Object value = null;
31+
try{
32+
value = f.get(null);
33+
}
34+
catch(Exception e){
35+
36+
}
37+
finally {
38+
constants.put(f.getName(), value);
39+
}
40+
}
41+
}
42+
return constants;
43+
}
2244
}

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
import { NativeModules } from 'react-native';
2+
import { NativeModules, Platform } from 'react-native';
33

44
const { RNConfigReader } = NativeModules;
55

6-
export default RNConfigReader;
6+
export default Platform.OS === 'ios' ? RNConfigReader.BuildConfigs : RNConfigReader;

ios/RNConfigReader.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ - (dispatch_queue_t)methodQueue
99
}
1010
RCT_EXPORT_MODULE()
1111

12+
- (NSDictionary *)constantsToExport
13+
{
14+
return @{ @"BuildConfigs": [[NSBundle mainBundle] infoDictionary] };
15+
}
16+
1217
@end
1318

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@
22
{
33
"name": "react-native-config-reader",
44
"version": "1.0.0",
5-
"description": "",
5+
"description": "Simply access android build configs and ios info.plist values in JS",
66
"main": "index.js",
77
"scripts": {
88
"test": "echo \"Error: no test specified\" && exit 1"
99
},
1010
"keywords": [
1111
"react-native"
1212
],
13-
"author": "",
14-
"license": "",
13+
"author": "csath - chanakaathurugiriya@gmail.com",
14+
"license": "MIT",
1515
"peerDependencies": {
1616
"react-native": "^0.41.2",
1717
"react-native-windows": "0.41.0-rc.1"
18-
1918
}
2019
}

windows/RNConfigReader/RNConfigReaderModule.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,19 @@ public override string Name
2929
return "RNConfigReader";
3030
}
3131
}
32+
33+
[Obsolete]
34+
public override IReadOnlyDictionary<string, object> Constants
35+
{
36+
get
37+
{
38+
var constants = new Dictionary<string, object>
39+
{
40+
{ "BuildConfigs", Package.Current.localSettings }
41+
};
42+
43+
return constants;
44+
}
45+
}
3246
}
3347
}

0 commit comments

Comments
 (0)