Skip to content

Commit 5d785e7

Browse files
authored
Update README.md
Added code examples
1 parent 79d6203 commit 5d785e7

File tree

1 file changed

+60
-4
lines changed

1 file changed

+60
-4
lines changed

README.md

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
21
# 🛠 react-native-config-reader
32

4-
react-native-config-reader is a native library which make it easy to access all the native code's build configurations from JS.
3+
A native library to access all the native code's build configurations from JS.
54

65
## Installation
76

@@ -16,11 +15,68 @@ See [manual installation](#manual-installation) below if you have issues with `r
1615
```javascript
1716
import RNConfigReader from 'react-native-config-reader';
1817

19-
RNConfigReader.;
18+
// access any of the defined config variables in andoird build gradle or ios info.plist
19+
const configValue = RNConfigReader.ANY_DEFINED_CONFIG_FIELD;
20+
21+
22+
```
23+
24+
### More examples
25+
26+
Create new build config field inside android `build.gradle` file **(android/app/build.gradle)**
27+
28+
```gradle
29+
android {
30+
31+
defaultConfig {
32+
applicationId "com.react-native.react-native-config-reader"
33+
versionCode 1
34+
versionName "1.0"
35+
36+
buildConfigField "String", "TEST_CONFIG_FIELD", "Hello I'm your test config value"
37+
}
38+
}
39+
2040
```
41+
Create new field inside ios `info.plist` file
42+
43+
```xml
44+
<?xml version="1.0" encoding="UTF-8"?>
45+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
46+
47+
<plist version="1.0">
48+
<dict>
49+
<key>CFBundleDisplayName</key>
50+
<string>com.react-native.react-native-config-reader</string>
51+
52+
<key>TEST_CONFIG_FIELD</key>
53+
<string>"Hello I'm your test config value"</string>
54+
</dict>
55+
</plist>
2156

2257

23-
### Manual installation
58+
```
59+
60+
Now you can acess them inside the JS code
61+
62+
```javascript
63+
import { Platform } from 'react-native';
64+
import RNConfigReader from 'react-native-config-reader';
65+
66+
if(Platform.OS === 'ios') {
67+
const iosBundleDisplayName = RNConfigReader.CFBundleDisplayName;
68+
const testConfigValue = RNConfigReader.TEST_CONFIG_FIELD;
69+
}
70+
71+
if(Platform.OS === 'android') {
72+
const androidApplicationID = RNConfigReader.applicationId;
73+
const testConfigValue = RNConfigReader.TEST_CONFIG_FIELD;
74+
}
75+
76+
77+
```
78+
79+
## Manual installation
2480

2581

2682
#### iOS

0 commit comments

Comments
 (0)