initialize the context when the module is initialized

This commit is contained in:
Ari Lazier 2016-01-05 20:34:50 -08:00
parent e90d2c514b
commit 9a15ef4c87
4 changed files with 17 additions and 12 deletions

View File

@ -10,6 +10,7 @@ import java.util.Map;
import java.util.HashMap;
import android.widget.Toast;
import com.facebook.react.bridge.Callback;
import android.util.Log;
public class RealmReactAndroid extends ReactContextBaseJavaModule {
private static final String DURATION_SHORT_KEY = "SHORT";
@ -20,6 +21,11 @@ public class RealmReactAndroid extends ReactContextBaseJavaModule {
ReLinker.loadLibrary(reactContext, "realmreact");
}
@Override
public void initialize() {
Log.w("RealmReactAndroid", injectRealmJsContext());
}
@Override
public String getName() {
return "RealmReactAndroid";

View File

@ -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::stringstream msg;
msg << "Got the globalContext map, size=" << s_globalContextRefToJSCExecutor.size();
for (auto pair : s_globalContextRefToJSCExecutor) {
RJSInitializeInContext(pair.first);
}
return env->NewStringUTF(msg.str().c_str());
} else {
return env->NewStringUTF("Cannot find symbol get_jsc_context");
}
// for (auto pair : s_globalContextRefToJSCExecutor) {
// RJSInitializeInContext(pair.first);
// }
}

View File

@ -14,18 +14,15 @@ var {
} = React;
var RealmReactAndroid = require('NativeModules').RealmReactAndroid;
//var Realm = require('realm');
//var RealmTests = require('realm-tests');
var Demo = React.createClass({
render: function() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Trying to inject Realm JS Context:
{
RealmReactAndroid.resultOfJsContextInjection((msg) => {
RealmReactAndroid.show(msg, RealmReactAndroid.LONG)
})
}
Trying to inject Realm JS Context
</Text>
</View>
);

View File

@ -6,6 +6,8 @@
"start": "react-native start"
},
"dependencies": {
"react-native": "^0.16.0"
"react-native": "^0.16.0",
"realm": "file:../..",
"realm-tests": "file:../lib"
}
}