类com.facebook.react.bridge.NativeModuleCallExceptionHandler源码实例Demo

下面列出了怎么用com.facebook.react.bridge.NativeModuleCallExceptionHandler的API类实例代码及写法,或者点击链接到github查看源代码。

private NativeModuleCallExceptionHandler createNativeModuleExceptionHandler() {
    return new NativeModuleCallExceptionHandler() {
        @Override
        public void handleException(Exception e) {
            throw new RuntimeException(e);
        }
    };
}
 
private NativeModuleCallExceptionHandler createNativeModuleExceptionHandler() {
    return new NativeModuleCallExceptionHandler() {
        @Override
        public void handleException(Exception e) {
            throw new RuntimeException(e);
        }
    };
}
 
源代码3 项目: react-native-GPay   文件: ReactInstanceManager.java
ReactInstanceManager(
  Context applicationContext,
  @Nullable Activity currentActivity,
  @Nullable DefaultHardwareBackBtnHandler defaultHardwareBackBtnHandler,
  JavaScriptExecutorFactory javaScriptExecutorFactory,
  @Nullable JSBundleLoader bundleLoader,
  @Nullable String jsMainModulePath,
  List<ReactPackage> packages,
  boolean useDeveloperSupport,
  @Nullable NotThreadSafeBridgeIdleDebugListener bridgeIdleDebugListener,
  LifecycleState initialLifecycleState,
  @Nullable UIImplementationProvider mUIImplementationProvider,
  NativeModuleCallExceptionHandler nativeModuleCallExceptionHandler,
  @Nullable RedBoxHandler redBoxHandler,
  boolean lazyViewManagersEnabled,
  @Nullable DevBundleDownloadListener devBundleDownloadListener,
  int minNumShakes,
  int minTimeLeftInFrameForNonBatchedOperationMs,
  @Nullable JSIModulePackage jsiModulePackage,
  @Nullable Map<String, RequestHandler> customPackagerCommandHandlers) {
  Log.d(ReactConstants.TAG, "ReactInstanceManager.ctor()");
  initializeSoLoaderIfNecessary(applicationContext);

  DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(applicationContext);

  mApplicationContext = applicationContext;
  mCurrentActivity = currentActivity;
  mDefaultBackButtonImpl = defaultHardwareBackBtnHandler;
  mJavaScriptExecutorFactory = javaScriptExecutorFactory;
  mBundleLoader = bundleLoader;
  mJSMainModulePath = jsMainModulePath;
  mPackages = new ArrayList<>();
  mUseDeveloperSupport = useDeveloperSupport;
  mDevSupportManager =
      DevSupportManagerFactory.create(
          applicationContext,
          createDevHelperInterface(),
          mJSMainModulePath,
          useDeveloperSupport,
          redBoxHandler,
          devBundleDownloadListener,
          minNumShakes,
          customPackagerCommandHandlers);
  mBridgeIdleDebugListener = bridgeIdleDebugListener;
  mLifecycleState = initialLifecycleState;
  mMemoryPressureRouter = new MemoryPressureRouter(applicationContext);
  mNativeModuleCallExceptionHandler = nativeModuleCallExceptionHandler;
  synchronized (mPackages) {
    PrinterHolder.getPrinter()
        .logMessage(ReactDebugOverlayTags.RN_CORE, "RNCore: Use Split Packages");
    mPackages.add(
        new CoreModulesPackage(
            this,
            new DefaultHardwareBackBtnHandler() {
              @Override
              public void invokeDefaultOnBackPressed() {
                ReactInstanceManager.this.invokeDefaultOnBackPressed();
              }
            },
            mUIImplementationProvider,
            lazyViewManagersEnabled,
            minTimeLeftInFrameForNonBatchedOperationMs));
    if (mUseDeveloperSupport) {
      mPackages.add(new DebugCorePackage());
    }
    mPackages.addAll(packages);
  }
  mJSIModulePackage = jsiModulePackage;

  // Instantiate ReactChoreographer in UI thread.
  ReactChoreographer.initialize();
  if (mUseDeveloperSupport) {
    mDevSupportManager.startInspector();
  }
}
 
源代码4 项目: react-native-GPay   文件: ReactInstanceManager.java
/**
 * @return instance of {@link ReactContext} configured a {@link CatalystInstance} set
 */
private ReactApplicationContext createReactContext(
    JavaScriptExecutor jsExecutor,
    JSBundleLoader jsBundleLoader) {
  Log.d(ReactConstants.TAG, "ReactInstanceManager.createReactContext()");
  ReactMarker.logMarker(CREATE_REACT_CONTEXT_START, jsExecutor.getName());
  final ReactApplicationContext reactContext = new ReactApplicationContext(mApplicationContext);

  NativeModuleCallExceptionHandler exceptionHandler = mNativeModuleCallExceptionHandler != null
      ? mNativeModuleCallExceptionHandler
      : mDevSupportManager;
  reactContext.setNativeModuleCallExceptionHandler(exceptionHandler);

  NativeModuleRegistry nativeModuleRegistry = processPackages(reactContext, mPackages, false);

  CatalystInstanceImpl.Builder catalystInstanceBuilder = new CatalystInstanceImpl.Builder()
    .setReactQueueConfigurationSpec(ReactQueueConfigurationSpec.createDefault())
    .setJSExecutor(jsExecutor)
    .setRegistry(nativeModuleRegistry)
    .setJSBundleLoader(jsBundleLoader)
    .setNativeModuleCallExceptionHandler(exceptionHandler);

  ReactMarker.logMarker(CREATE_CATALYST_INSTANCE_START);
  // CREATE_CATALYST_INSTANCE_END is in JSCExecutor.cpp
  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "createCatalystInstance");
  final CatalystInstance catalystInstance;
  try {
    catalystInstance = catalystInstanceBuilder.build();
  } finally {
    Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
    ReactMarker.logMarker(CREATE_CATALYST_INSTANCE_END);
  }
  if (mJSIModulePackage != null) {
    catalystInstance.addJSIModules(mJSIModulePackage
      .getJSIModules(reactContext, catalystInstance.getJavaScriptContextHolder()));
  }

  if (mBridgeIdleDebugListener != null) {
    catalystInstance.addBridgeIdleDebugListener(mBridgeIdleDebugListener);
  }
  if (Systrace.isTracing(TRACE_TAG_REACT_APPS | TRACE_TAG_REACT_JS_VM_CALLS)) {
    catalystInstance.setGlobalVariable("__RCTProfileIsProfiling", "true");
  }
  ReactMarker.logMarker(ReactMarkerConstants.PRE_RUN_JS_BUNDLE_START);
  catalystInstance.runJSBundle();
  reactContext.initializeWithInstance(catalystInstance);

  return reactContext;
}
 
/**
 * Set the exception handler for all native module calls. If not set, the default
 * {@link DevSupportManager} will be used, which shows a redbox in dev mode and rethrows
 * (crashes the app) in prod mode.
 */
public ReactInstanceManagerBuilder setNativeModuleCallExceptionHandler(
  NativeModuleCallExceptionHandler handler) {
  mNativeModuleCallExceptionHandler = handler;
  return this;
}
 
 同包方法