Java Code Examples for com.facebook.react.bridge.ReactApplicationContext#initializeWithInstance()

The following examples show how to use com.facebook.react.bridge.ReactApplicationContext#initializeWithInstance() . 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: ReactTextInputPropertyTest.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Before
public void setup() {
  mContext = new ReactApplicationContext(RuntimeEnvironment.application);
  mCatalystInstanceMock = ReactTestHelper.createMockCatalystInstance();
  mContext.initializeWithInstance(mCatalystInstanceMock);
  mThemedContext = new ThemedReactContext(mContext, mContext);
  mManager = new ReactTextInputManager();
  DisplayMetricsHolder.setWindowDisplayMetrics(new DisplayMetrics());
}
 
Example 2
Source File: ReactSliderPropertyTest.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Before
public void setup() {
  ReactApplicationContext mContext = new ReactApplicationContext(RuntimeEnvironment.application);
  CatalystInstance mCatalystInstanceMock = ReactTestHelper.createMockCatalystInstance();
  mContext.initializeWithInstance(mCatalystInstanceMock);
  mThemedContext = new ThemedReactContext(mContext, mContext);
  mManager = new ReactSliderManager();
}
 
Example 3
Source File: ReactImagePropertyTest.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Before
public void setup() {
  SoLoader.setInTestMode();
  mContext = new ReactApplicationContext(RuntimeEnvironment.application);
  mCatalystInstanceMock = ReactTestHelper.createMockCatalystInstance();
  mContext.initializeWithInstance(mCatalystInstanceMock);
  mThemeContext = new ThemedReactContext(mContext, mContext);
  Fresco.initialize(mContext);
  DisplayMetricsHolder.setWindowDisplayMetrics(new DisplayMetrics());
}
 
Example 4
Source File: FabricUIManagerTest.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  mNextReactTag = 2;
  ReactApplicationContext reactContext = new ReactApplicationContext(RuntimeEnvironment.application);
  reactContext.initializeWithInstance(ReactTestHelper.createMockCatalystInstance());
  mThemedReactContext = new ThemedReactContext(reactContext, reactContext);

  List<ViewManager> viewManagers =
      Arrays.<ViewManager>asList(
          new ReactViewManager(), new ReactTextViewManager(), new ReactRawTextManager());
  ViewManagerRegistry viewManagerRegistry = new ViewManagerRegistry(viewManagers);
  JavaScriptContextHolder jsContext = mock(JavaScriptContextHolder.class);
  EventDispatcher eventDispatcher = mock(EventDispatcher.class);
  mFabricUIManager = new FabricUIManager(reactContext, viewManagerRegistry, jsContext, eventDispatcher);
}
 
Example 5
Source File: FabricReconcilerTest.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Before
public void setUp() {
  CatalystInstance catalystInstance = ReactTestHelper.createMockCatalystInstance();
  ReactApplicationContext reactContext =
      new ReactApplicationContext(RuntimeEnvironment.application);
  reactContext.initializeWithInstance(catalystInstance);
  List<ViewManager> viewManagers = new ArrayList<>();
  ViewManagerRegistry viewManagerRegistry = new ViewManagerRegistry(viewManagers);
  JavaScriptContextHolder jsContext = mock(JavaScriptContextHolder.class);
  EventDispatcher eventDispatcher = mock(EventDispatcher.class);
  mFabricUIManager = new FabricUIManager(reactContext, viewManagerRegistry, jsContext, eventDispatcher);
  mMockUIViewOperationQueue = new MockUIViewOperationQueue(reactContext);
  mFabricReconciler = new FabricReconciler(mMockUIViewOperationQueue);
}
 
Example 6
Source File: SimpleViewPropertyTest.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Before
public void setup() {
  mContext = new ReactApplicationContext(RuntimeEnvironment.application);
  mCatalystInstanceMock = ReactTestHelper.createMockCatalystInstance();
  mContext.initializeWithInstance(mCatalystInstanceMock);
  mThemedContext = new ThemedReactContext(mContext, mContext);
  mManager = new ConcreteViewManager();
}
 
Example 7
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;
}