android和ReactNative之间的桥接不起作用

时间:2018-10-04 11:12:14

标签: android react-native react-native-android

我正在尝试使用NativeModules在android和ReactNative之间建立桥梁,但是我无法将Java类中定义的方法访问到我的JavaScript文件中。被引荐的https://hackernoon.com/first-experiences-with-react-native-bridging-an-android-native-module-for-app-authentication-501fec247b2b

MainApplication.java

@Override
        protected List<ReactPackage> getPackages() {
            return Arrays.<ReactPackage>asList(
                    new MainReactPackage(),
                    new BridgePackage()
            );
        }

BridgeModule.java

public class BridgeModule extends ReactContextBaseJavaModule {

    public BridgeModule(ReactApplicationContext reactContext) {
        super(reactContext);
    }

    @Override
    public String getName() {
        return "BridgeModule";
    }

    @ReactMethod
    public void reactNativeModuleTest() {

    }

}

BridgePackage.java

public class BridgePackage implements com.facebook.react.ReactPackage {

    @Override
    public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
        List<NativeModule> modules = new ArrayList<>();
        modules.add(new BridgeModule(reactContext));
        return modules;
    }

    @Override
    public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
        return Collections.emptyList();
    }
}

0 个答案:

没有答案