예제 #1
0
  @Override
  protected void setUp() throws Exception {
    super.setUp();

    List<ViewManager> viewManagers = Arrays.<ViewManager>asList(new ReactViewManager());
    final UIManagerModule mUIManager =
        new UIManagerModule(
            getContext(), viewManagers, new UIImplementation(getContext(), viewManagers));
    UiThreadUtil.runOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            mUIManager.onHostResume();
          }
        });
    waitForIdleSync();

    mStringRecordingModule = new StringRecordingModule();
    mInstance =
        ReactTestHelper.catalystInstanceBuilder(this)
            .addNativeModule(mStringRecordingModule)
            .addNativeModule(mUIManager)
            .addJSModule(TestJSLocaleModule.class)
            .build();
  }
  public void loadApp(
      String appKey,
      ReactInstanceSpecForTest spec,
      @Nullable Bundle initialProps,
      String bundleName,
      boolean useDevSupport) {

    final CountDownLatch currentLayoutEvent = mLayoutEvent = new CountDownLatch(1);
    mBridgeIdleSignaler = new ReactBridgeIdleSignaler();

    ReactInstanceManager.Builder builder =
        ReactTestHelper.getReactTestFactory()
            .getReactInstanceManagerBuilder()
            .setApplication(getApplication())
            .setBundleAssetName(bundleName)
            // By not setting a JS module name, we force the bundle to be always loaded from
            // assets, not the devserver, even if dev mode is enabled (such as when testing
            // redboxes).
            // This makes sense because we never run the devserver in tests.
            // .setJSMainModuleName()
            .addPackage(
                spec.getAlternativeReactPackageForTest() != null
                    ? spec.getAlternativeReactPackageForTest()
                    : new MainReactPackage())
            .addPackage(new InstanceSpecForTestPackage(spec))
            .setUseDeveloperSupport(useDevSupport)
            .setBridgeIdleDebugListener(mBridgeIdleSignaler)
            .setInitialLifecycleState(mLifecycleState);

    mReactInstanceManager = builder.build();
    mReactInstanceManager.onResume(this, this);

    Assertions.assertNotNull(mReactRootView)
        .getViewTreeObserver()
        .addOnGlobalLayoutListener(
            new ViewTreeObserver.OnGlobalLayoutListener() {
              @Override
              public void onGlobalLayout() {
                currentLayoutEvent.countDown();
              }
            });
    Assertions.assertNotNull(mReactRootView)
        .startReactApplication(mReactInstanceManager, appKey, initialProps);
  }