Skip to content

Commit 376fd09

Browse files
committed
resolve merge conflicts
2 parents 2616c3b + 6cc34ab commit 376fd09

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

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

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

22
package com.csath;
33

4-
import java.lang.reflect.*;
4+
import android.content.Context;
5+
import android.content.res.Resources;
6+
import android.util.Log;
7+
8+
import java.lang.ClassNotFoundException;
9+
import java.lang.IllegalAccessException;
10+
import java.lang.reflect.Field;
11+
512
import com.facebook.react.bridge.ReactApplicationContext;
613
import com.facebook.react.bridge.ReactContextBaseJavaModule;
714
import com.facebook.react.bridge.ReactMethod;
@@ -13,14 +20,8 @@
1320
import java.util.HashMap;
1421

1522
public class RNConfigReaderModule extends ReactContextBaseJavaModule {
16-
17-
private final ReactApplicationContext reactContext;
18-
private final Class buildConfigClass;
19-
20-
public RNConfigReaderModule(ReactApplicationContext reactContext, Class buildConfigClass) {
23+
public RNConfigReaderModule(ReactApplicationContext reactContext) {
2124
super(reactContext);
22-
this.reactContext = reactContext;
23-
this.buildConfigClass = buildConfigClass;
2425
}
2526

2627
@Override
@@ -31,20 +32,28 @@ public String getName() {
3132
@Override
3233
public Map<String, Object> getConstants() {
3334
final Map<String, Object> constants = new HashMap<>();
34-
Field[] fields = this.buildConfigClass.getDeclaredFields();
35-
for (Field f : fields) {
36-
if (Modifier.isStatic(f.getModifiers())) {
37-
Object value = null;
38-
try{
39-
value = f.get(null);
40-
}
41-
catch(Exception e){
42-
43-
}
44-
finally {
45-
constants.put(f.getName(), value);
46-
}
47-
}
35+
try {
36+
Context context = getReactApplicationContext();
37+
int resId = context.getResources().getIdentifier("rn_config_reader_custom_package", "string", context.getPackageName());
38+
String className;
39+
try {
40+
className = context.getString(resId);
41+
} catch (Resources.NotFoundException e) {
42+
className = getReactApplicationContext().getApplicationContext().getPackageName();
43+
}
44+
Class clazz = Class.forName(className + ".BuildConfig");
45+
Field[] fields = clazz.getDeclaredFields();
46+
for(Field f: fields) {
47+
try {
48+
constants.put(f.getName(), f.get(null));
49+
}
50+
catch (IllegalAccessException e) {
51+
Log.d("ReactNative", "RNConfigReader: Could not access BuildConfig field " + f.getName());
52+
}
53+
}
54+
}
55+
catch (ClassNotFoundException e) {
56+
Log.d("ReactNative", "RNConfigReader: Could not find BuildConfig class");
4857
}
4958
return constants;
5059
}

android/src/main/java/com/csath/RNConfigReaderPackage.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,9 @@
1212
import com.facebook.react.bridge.JavaScriptModule;
1313

1414
public class RNConfigReaderPackage implements ReactPackage {
15-
private final Class buildConfigclass;
16-
17-
public RNConfigReaderPackage(Class buildConfigclass) {
18-
this.buildConfigclass = buildConfigclass;
19-
}
2015
@Override
2116
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
22-
return Arrays.<NativeModule>asList(new RNConfigReaderModule(reactContext, this.buildConfigclass));
17+
return Arrays.<NativeModule>asList(new RNConfigReaderModule(reactContext));
2318
}
2419

2520
// Deprecated from RN 0.47

0 commit comments

Comments
 (0)