Java Code Examples for com.facebook.react.uimanager.UIManagerModule#addRootView()

The following examples show how to use com.facebook.react.uimanager.UIManagerModule#addRootView() . 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: ProgressBarTestCase.java    From progress-bar-android with MIT License 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
  super.setUp();

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

  mInstance = ReactTestHelper.catalystInstanceBuilder(this)
      .addNativeModule(mUIManager)
      .addNativeModule(new AndroidInfoModule(getContext()))
      .addNativeModule(new DeviceInfoModule(getContext()))
      .addNativeModule(new AppStateModule(getContext()))
      .addNativeModule(new FakeWebSocketModule())
      .build();

  mRootView = new ReactRootView(getContext());
  DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
  mRootView.setLayoutParams(
      new FrameLayout.LayoutParams(metrics.widthPixels, metrics.heightPixels));
  int rootTag = mUIManager.addRootView(mRootView);
  mInstance.getJSModule(ProgressBarTestModule.class).renderProgressBarApplication(rootTag);
  waitForBridgeAndUIIdle();
}
 
Example 2
Source File: ProgressBarTestCase.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
  super.setUp();

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

  mInstance = ReactTestHelper.catalystInstanceBuilder(this)
      .addNativeModule(mUIManager)
      .addNativeModule(new AndroidInfoModule(getContext()))
      .addNativeModule(new DeviceInfoModule(getContext()))
      .addNativeModule(new AppStateModule(getContext()))
      .addNativeModule(new FakeWebSocketModule())
      .build();

  mRootView = new ReactRootView(getContext());
  DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
  mRootView.setLayoutParams(
      new FrameLayout.LayoutParams(metrics.widthPixels, metrics.heightPixels));
  int rootTag = mUIManager.addRootView(mRootView);
  mInstance.getJSModule(ProgressBarTestModule.class).renderProgressBarApplication(rootTag);
  waitForBridgeAndUIIdle();
}
 
Example 3
Source File: ViewRenderingTestCase.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
  super.setUp();

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

  mCatalystInstance = ReactTestHelper.catalystInstanceBuilder(this)
      .addNativeModule(uiManager)
      .addNativeModule(new AndroidInfoModule(getContext()))
      .addNativeModule(new DeviceInfoModule(getContext()))
      .addNativeModule(new AppStateModule(getContext()))
      .addNativeModule(new FakeWebSocketModule())
      .build();

  mRootView = new ReactRootView(getContext());
  mRootTag = uiManager.addRootView(mRootView);
}
 
Example 4
Source File: TextInputTest.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Test
public void testPropsApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = new ReactRootView(RuntimeEnvironment.application);
  rootView.setLayoutParams(new ReactRootView.LayoutParams(100, 100));
  int rootTag = uiManager.addRootView(rootView);
  int textInputTag = rootTag + 1;
  final String hintStr = "placeholder text";

  uiManager.createView(
      textInputTag,
      ReactTextInputManager.REACT_CLASS,
      rootTag,
      JavaOnlyMap.of(
          ViewProps.FONT_SIZE, 13.37, ViewProps.HEIGHT, 20.0, "placeholder", hintStr));

  uiManager.manageChildren(
      rootTag,
      null,
      null,
      JavaOnlyArray.of(textInputTag),
      JavaOnlyArray.of(0),
      null);

  uiManager.onBatchComplete();
  executePendingChoreographerCallbacks();

  EditText editText = (EditText) rootView.getChildAt(0);
  assertThat(editText.getHint()).isEqualTo(hintStr);
  assertThat(editText.getTextSize()).isEqualTo((float) Math.ceil(13.37));
  assertThat(editText.getHeight()).isEqualTo(20);
}
 
Example 5
Source File: ReactTextTest.java    From react-native-GPay with MIT License 5 votes vote down vote up
private ReactRootView createText(
    UIManagerModule uiManager,
    JavaOnlyMap textProps,
    JavaOnlyMap rawTextProps) {
  ReactRootView rootView = new ReactRootView(RuntimeEnvironment.application);
  int rootTag = uiManager.addRootView(rootView);
  int textTag = rootTag + 1;
  int rawTextTag = textTag + 1;

  uiManager.createView(
      textTag,
      ReactTextViewManager.REACT_CLASS,
      rootTag,
      textProps);
  uiManager.createView(
      rawTextTag,
      ReactRawTextManager.REACT_CLASS,
      rootTag,
      rawTextProps);

  uiManager.manageChildren(
      textTag,
      null,
      null,
      JavaOnlyArray.of(rawTextTag),
      JavaOnlyArray.of(0),
      null);

  uiManager.manageChildren(
      rootTag,
      null,
      null,
      JavaOnlyArray.of(textTag),
      JavaOnlyArray.of(0),
      null);

  uiManager.onBatchComplete();
  executePendingFrameCallbacks();
  return rootView;
}
 
Example 6
Source File: TextInputTest.java    From react-native-GPay with MIT License 4 votes vote down vote up
@Test
public void testPropsUpdate() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = new ReactRootView(RuntimeEnvironment.application);
  rootView.setLayoutParams(new ReactRootView.LayoutParams(100, 100));
  int rootTag = uiManager.addRootView(rootView);
  int textInputTag = rootTag + 1;
  final String hintStr = "placeholder text";

  uiManager.createView(
      textInputTag,
      ReactTextInputManager.REACT_CLASS,
      rootTag,
      JavaOnlyMap.of(
          ViewProps.FONT_SIZE, 13.37, ViewProps.HEIGHT, 20.0, "placeholder", hintStr));

  uiManager.manageChildren(
      rootTag,
      null,
      null,
      JavaOnlyArray.of(textInputTag),
      JavaOnlyArray.of(0),
      null);
  uiManager.onBatchComplete();
  executePendingChoreographerCallbacks();

  EditText editText = (EditText) rootView.getChildAt(0);
  assertThat(editText.getHint()).isEqualTo(hintStr);
  assertThat(editText.getTextSize()).isEqualTo((float) Math.ceil(13.37));
  assertThat(editText.getHeight()).isEqualTo(20);

  final String hintStr2 = "such hint";
  uiManager.updateView(
      textInputTag,
      ReactTextInputManager.REACT_CLASS,
      JavaOnlyMap.of(
          ViewProps.FONT_SIZE, 26.74, ViewProps.HEIGHT, 40.0, "placeholder", hintStr2));

  uiManager.onBatchComplete();
  executePendingChoreographerCallbacks();

  EditText updatedEditText = (EditText) rootView.getChildAt(0);
  assertThat(updatedEditText.getHint()).isEqualTo(hintStr2);
  assertThat(updatedEditText.getTextSize()).isEqualTo((float) Math.ceil(26.74f));
  assertThat(updatedEditText.getHeight()).isEqualTo(40);
}