Last active
January 5, 2019 09:27
-
-
Save ryardley/392b564b7dc6ddc4a1dc709f39c7585c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ./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