initialize the context when the module is initialized
This commit is contained in:
parent
e90d2c514b
commit
9a15ef4c87
|
@ -10,6 +10,7 @@ import java.util.Map;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import com.facebook.react.bridge.Callback;
|
import com.facebook.react.bridge.Callback;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
public class RealmReactAndroid extends ReactContextBaseJavaModule {
|
public class RealmReactAndroid extends ReactContextBaseJavaModule {
|
||||||
private static final String DURATION_SHORT_KEY = "SHORT";
|
private static final String DURATION_SHORT_KEY = "SHORT";
|
||||||
|
@ -20,6 +21,11 @@ public class RealmReactAndroid extends ReactContextBaseJavaModule {
|
||||||
ReLinker.loadLibrary(reactContext, "realmreact");
|
ReLinker.loadLibrary(reactContext, "realmreact");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize() {
|
||||||
|
Log.w("RealmReactAndroid", injectRealmJsContext());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "RealmReactAndroid";
|
return "RealmReactAndroid";
|
||||||
|
|
|
@ -33,14 +33,14 @@ JNIEXPORT jstring JNICALL Java_com_reacttests_RealmReactAndroid_injectRealmJsCon
|
||||||
std::unordered_map<JSContextRef, facebook::react::JSCExecutor*> s_globalContextRefToJSCExecutor = get_jsc_context();
|
std::unordered_map<JSContextRef, facebook::react::JSCExecutor*> s_globalContextRefToJSCExecutor = get_jsc_context();
|
||||||
std::stringstream msg;
|
std::stringstream msg;
|
||||||
msg << "Got the globalContext map, size=" << s_globalContextRefToJSCExecutor.size();
|
msg << "Got the globalContext map, size=" << s_globalContextRefToJSCExecutor.size();
|
||||||
|
|
||||||
|
for (auto pair : s_globalContextRefToJSCExecutor) {
|
||||||
|
RJSInitializeInContext(pair.first);
|
||||||
|
}
|
||||||
|
|
||||||
return env->NewStringUTF(msg.str().c_str());
|
return env->NewStringUTF(msg.str().c_str());
|
||||||
} else {
|
} else {
|
||||||
return env->NewStringUTF("Cannot find symbol get_jsc_context");
|
return env->NewStringUTF("Cannot find symbol get_jsc_context");
|
||||||
}
|
}
|
||||||
|
|
||||||
// for (auto pair : s_globalContextRefToJSCExecutor) {
|
|
||||||
// RJSInitializeInContext(pair.first);
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,18 +14,15 @@ var {
|
||||||
} = React;
|
} = React;
|
||||||
|
|
||||||
var RealmReactAndroid = require('NativeModules').RealmReactAndroid;
|
var RealmReactAndroid = require('NativeModules').RealmReactAndroid;
|
||||||
|
//var Realm = require('realm');
|
||||||
|
//var RealmTests = require('realm-tests');
|
||||||
|
|
||||||
var Demo = React.createClass({
|
var Demo = React.createClass({
|
||||||
render: function() {
|
render: function() {
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<Text style={styles.welcome}>
|
<Text style={styles.welcome}>
|
||||||
Trying to inject Realm JS Context:
|
Trying to inject Realm JS Context
|
||||||
{
|
|
||||||
RealmReactAndroid.resultOfJsContextInjection((msg) => {
|
|
||||||
RealmReactAndroid.show(msg, RealmReactAndroid.LONG)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
"start": "react-native start"
|
"start": "react-native start"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"react-native": "^0.16.0"
|
"react-native": "^0.16.0",
|
||||||
|
"realm": "file:../..",
|
||||||
|
"realm-tests": "file:../lib"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue