I have a C++ React Native module derived from facebook::xplat::module::CxxModule
. It is working ok with iOS project but now I'm trying to figure out how to use it from Java. The only documentation I found is the comment in React Native codebase stating that:
NativeModules whose implementation is written in C++ must not provide any Java code (so they can be reused on other platforms), and instead should register themselves using CxxModuleWrapper
My question is how to register C++ module in Java using CxxModuleWrapper
Please check this blog for detail: https://medium.com/@kudochien/how-to-write-a-react-native-cxxmodule-59073259f15d. Snippet from the blog:
extern "C" HelloCxxModule* createHelloCxxModule() { return new HelloCxxModule(); }
public final class HelloCxxPackage implements ReactPackage { @Override public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) { return Arrays.<NativeModule>asList( // I have librnpackage-hellocxx.so the exported createHelloCxxModule() above. CxxModuleWrapper.makeDso("rnpackage-hellocxx", "createHelloCxxModule") ); } @Override public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) { return Collections.emptyList(); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With