如何在0.33中获取ReactContext,而不是ReactApplicationContext



  • public class NotificationMessageModule extends ReactContextBaseJavaModule{
    public NotificationMessageModule(ReactApplicationContext reactContext) {
    super(reactContext);
    WritableMap params = Arguments.createMap();
    params.putString("title","title");
    System.out.println("++++"+reactContext+"----");
    sendEvent(reactContext,"keyboardWillShow", params);
    }
    @Override
    public String getName() {
    return "NotificationMessageParameter";
    }

    @ReactMethod
    public void receiverParameter(final Callback callback){
    
    }
    
    
    private void sendEvent(ReactContext reactContext,
                           String eventName,
                           @Nullable WritableMap params) {
        reactContext
                .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                .emit(eventName, params);
    }
    

    }

    但是,使用这样就报错了0_1474616777050_$QS8D2YHDAO5{V8TKKDUFC8.png

    我问过其他人,他们说不是用ReactApplicationContext,而是用ReactContext,但是我把代码改了之后看了,这两个context都可以调起getJsModule方法,代码如下:
    public class NotificationMessageModule extends ReactContextBaseJavaModule{
    public NotificationMessageModule(ReactApplicationContext reactContext) {
    super(reactContext);
    WritableMap params = Arguments.createMap();
    params.putString("title","title");
    System.out.println("++++"+reactContext+"----");
    sendEvent(reactContext,"keyboardWillShow", params);
    }
    @Override
    public String getName() {
    return "NotificationMessageParameter";
    }

    @ReactMethod
    public void receiverParameter(final Callback callback){
    
    }
    
    
    private void sendEvent(ReactApplicationContext reactContext,
                           String eventName,
                           @Nullable WritableMap params) {
        reactContext
                .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                .emit(eventName, params);
    }
    

    }
    报的错误都一样,求大神解答,谢谢。。。。


Log in to reply