com.facebook.react.bridge.CatalystInstanceImpl Java Examples

The following examples show how to use com.facebook.react.bridge.CatalystInstanceImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReactInstanceManager.java    From react-native-GPay with MIT License 4 votes vote down vote up
/**
 * @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;
}