有关详细信息,请查看此博客:https://medium.com/@kudochien/how-to-write-a-react-native-cxxmodule-59073259f15d。来自博客的片段:
从本机导出
extern "C" HelloCxxModule* createHelloCxxModule() {
return new HelloCxxModule();
}
在java中注册它
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();
}
}