Java 类com.facebook.react.bridge.ReactContextBaseJavaModule 实例源码

项目:RxRNBridge    文件:RxRNBridge.java   
@NonNull
public static NativeModule newInstance(Class<? extends ReactContextBaseJavaModule> reactModuleClass, ReactApplicationContext reactContext)
        throws IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
    String clsName = reactModuleClass.getName();
    String injectClsName = clsName + GEN_CLASS_SUFFIX;
    Class <? extends ReactContextBaseJavaModule> injectCls = null;
    try {
        injectCls = Class.forName(injectClsName).asSubclass(ReactContextBaseJavaModule.class);
    } catch (ClassNotFoundException e) {
        Log.e(TAG, "Unable to find injectClass - " + injectClsName);
    }

    return (NativeModule) (injectCls != null
            ? injectCls.getDeclaredConstructor(ReactApplicationContext.class).newInstance(reactContext)
            : reactModuleClass.getDeclaredConstructor(ReactApplicationContext.class).newInstance(reactContext));
}