Skip to content

Instantly share code, notes, and snippets.

@ryardley
Last active January 5, 2019 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryardley/392b564b7dc6ddc4a1dc709f39c7585c to your computer and use it in GitHub Desktop.
Save ryardley/392b564b7dc6ddc4a1dc709f39c7585c to your computer and use it in GitHub Desktop.
// ./android/app/src/main/java/com/cppreactnative/helloworld/HelloWorldModule.java
package com.cppreactnative.helloworld;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
public class HelloWorldModule extends ReactContextBaseJavaModule {
// Add the following lines
private HelloWorld cppApi; // instance var for our cppApi
static {
System.loadLibrary("helloworld"); // load the "helloworld" JNI module
}
public HelloWorldModule(ReactApplicationContext reactContext) {
super(reactContext);
cppApi = HelloWorld.create(); // create a new instance of our cppApi
}
@Override
public String getName() {
return "HelloWorld";
}
@ReactMethod
public void sayHello(Promise promise) {
// call the "getHelloWorld()" method on our C++ class and get the results.
String myString = cppApi.getHelloWorld();
promise.resolve(myString);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment