/** * Makes sure replaceExistingNonRootView by replacing a view with a new view that has a background * color set. */ @Test public void testReplaceExistingNonRootView() { UIManagerModule uiManager = getUIManagerModule(); TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager); int newViewTag = 1234; uiManager.createView( newViewTag, ReactViewManager.REACT_CLASS, hierarchy.rootView, JavaOnlyMap.of("backgroundColor", Color.RED)); uiManager.replaceExistingNonRootView(hierarchy.view2, newViewTag); uiManager.onBatchComplete(); executePendingFrameCallbacks(); assertThat(hierarchy.nativeRootView.getChildCount()).isEqualTo(4); assertThat(hierarchy.nativeRootView.getChildAt(2)).isInstanceOf(ReactViewGroup.class); ReactViewGroup view = (ReactViewGroup) hierarchy.nativeRootView.getChildAt(2); assertThat(view.getBackgroundColor()).isEqualTo(Color.RED); }
/** * Makes sure replaceExistingNonRootView by replacing a view with a new view that has a background * color set. */ @Test public void testReplaceExistingNonRootView() { UIManagerModule uiManager = getUIManagerModule(); TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager); int newViewTag = 1234; uiManager.createView( newViewTag, ReactViewManager.REACT_CLASS, hierarchy.rootView, JavaOnlyMap.of("backgroundColor", Color.RED)); uiManager.replaceExistingNonRootView(hierarchy.view2, newViewTag); uiManager.onBatchComplete(); executePendingChoreographerCallbacks(); assertThat(hierarchy.nativeRootView.getChildCount()).isEqualTo(4); assertThat(hierarchy.nativeRootView.getChildAt(2)).isInstanceOf(ReactViewGroup.class); ReactViewGroup view = (ReactViewGroup) hierarchy.nativeRootView.getChildAt(2); assertThat(view.getBackgroundColor()).isEqualTo(Color.RED); }
@Override public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) { return Arrays.<ViewManager>asList( new ReactDrawerLayoutManager(), new ReactHorizontalScrollViewManager(), new ReactImageManager(), new ReactProgressBarViewManager(), new ReactRawTextManager(), new ReactScrollViewManager(), new ReactSwitchManager(), new ReactTextInputManager(), new ReactTextViewManager(), new ReactToolbarManager(), new ReactViewManager(), new ReactViewPagerManager(), new ReactTextInlineImageViewManager(), new ReactVirtualTextViewManager(), new SwipeRefreshLayoutManager(), new ReactWebViewManager()); }
@Override protected void setUp() throws Exception { super.setUp(); List<ViewManager> viewManagers = Arrays.<ViewManager>asList( new ReactViewManager()); final UIManagerModule mUIManager = new UIManagerModule( getContext(), viewManagers, new UIImplementationProvider(), false); UiThreadUtil.runOnUiThread( new Runnable() { @Override public void run() { mUIManager.onHostResume(); } }); waitForIdleSync(); mRecordingTestModule = new RecordingTestModule(); mCatalystInstance = ReactTestHelper.catalystInstanceBuilder(this) .addNativeModule(mRecordingTestModule) .addNativeModule(new AndroidInfoModule()) .addNativeModule(new DeviceInfoModule(getContext())) .addNativeModule(new AppStateModule(getContext())) .addNativeModule(new FakeWebSocketModule()) .addNativeModule(mUIManager) .addJSModule(TestJSToJavaParametersModule.class) .build(); }
@Override protected void setUp() throws Exception { super.setUp(); List<ViewManager> viewManagers = Arrays.<ViewManager>asList( new ReactViewManager(), new ReactProgressBarViewManager()); mUIManager = new UIManagerModule( getContext(), viewManagers, new UIImplementationProvider(), false); UiThreadUtil.runOnUiThread( new Runnable() { @Override public void run() { mUIManager.onHostResume(); } }); waitForIdleSync(); mInstance = ReactTestHelper.catalystInstanceBuilder(this) .addNativeModule(mUIManager) .addNativeModule(new AndroidInfoModule()) .addNativeModule(new DeviceInfoModule(getContext())) .addNativeModule(new AppStateModule(getContext())) .addNativeModule(new FakeWebSocketModule()) .addJSModule(ProgressBarTestModule.class) .build(); mRootView = new ReactRootView(getContext()); DisplayMetrics metrics = getContext().getResources().getDisplayMetrics(); mRootView.setLayoutParams( new FrameLayout.LayoutParams(metrics.widthPixels, metrics.heightPixels)); int rootTag = mUIManager.addMeasuredRootView(mRootView); mInstance.getJSModule(ProgressBarTestModule.class).renderProgressBarApplication(rootTag); waitForBridgeAndUIIdle(); }
@Override protected void setUp() throws Exception { super.setUp(); List<ViewManager> viewManagers = Arrays.<ViewManager>asList(new ReactViewManager()); final UIManagerModule uiManager = new UIManagerModule( getContext(), viewManagers, new UIImplementationProvider(), false); UiThreadUtil.runOnUiThread( new Runnable() { @Override public void run() { uiManager.onHostResume(); } }); waitForIdleSync(); mCatalystInstance = ReactTestHelper.catalystInstanceBuilder(this) .addNativeModule(uiManager) .addNativeModule(new AndroidInfoModule()) .addNativeModule(new DeviceInfoModule(getContext())) .addNativeModule(new AppStateModule(getContext())) .addNativeModule(new FakeWebSocketModule()) .addJSModule(ViewRenderingTestModule.class) .build(); mRootView = new ReactRootView(getContext()); mRootTag = uiManager.addMeasuredRootView(mRootView); }
@Override protected void setUp() throws Exception { super.setUp(); List<ViewManager> viewManagers = Arrays.<ViewManager>asList( new ReactViewManager()); final UIManagerModule mUIManager = new UIManagerModule( getContext(), viewManagers, new UIImplementationProvider(), false); UiThreadUtil.runOnUiThread( new Runnable() { @Override public void run() { mUIManager.onHostResume(); } }); waitForIdleSync(); mAssertModule = new AssertModule(); mInstance = ReactTestHelper.catalystInstanceBuilder(this) .addNativeModule(mAssertModule) .addNativeModule(new DeviceInfoModule(getContext())) .addNativeModule(new AppStateModule(getContext())) .addNativeModule(new FakeWebSocketModule()) .addJSModule(TestJavaToJSArgumentsModule.class) .addNativeModule(mUIManager) .build(); }
@Override protected void setUp() throws Exception { super.setUp(); List<ViewManager> viewManagers = Arrays.<ViewManager>asList( new ReactViewManager()); final UIManagerModule mUIManager = new UIManagerModule( getContext(), viewManagers, new UIImplementationProvider(), false); UiThreadUtil.runOnUiThread( new Runnable() { @Override public void run() { mUIManager.onHostResume(); } }); waitForIdleSync(); mStringRecordingModule = new StringRecordingModule(); mInstance = ReactTestHelper.catalystInstanceBuilder(this) .addNativeModule(mStringRecordingModule) .addNativeModule(mUIManager) .addNativeModule(new DeviceInfoModule(getContext())) .addNativeModule(new AppStateModule(getContext())) .addNativeModule(new FakeWebSocketModule()) .addJSModule(TestJSLocaleModule.class) .build(); }
@Override protected void setUp() throws Exception { super.setUp(); List<ViewManager> viewManagers = Arrays.<ViewManager>asList( new ReactViewManager(), new ReactTextViewManager(), new ReactRawTextManager()); uiManager = new UIManagerModule( getContext(), viewManagers, new UIImplementationProvider(), false); UiThreadUtil.runOnUiThread(new Runnable() { @Override public void run() { uiManager.onHostResume(); } }); waitForIdleSync(); jsModule = ReactTestHelper.catalystInstanceBuilder(this) .addNativeModule(uiManager) .addNativeModule(new AndroidInfoModule()) .addNativeModule(new DeviceInfoModule(getContext())) .addNativeModule(new AppStateModule(getContext())) .addNativeModule(new FakeWebSocketModule()) .addJSModule(UIManagerTestModule.class) .build() .getJSModule(UIManagerTestModule.class); }
@Test public void testLayoutAppliedToNodes() throws Exception { UIManagerModule uiManager = getUIManagerModule(); TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager); int newViewTag = 10000; uiManager.createView( newViewTag, ReactViewManager.REACT_CLASS, hierarchy.rootView, JavaOnlyMap .of("left", 10.0, "top", 20.0, "width", 30.0, "height", 40.0, "collapsable", false)); uiManager.manageChildren( hierarchy.rootView, null, null, JavaOnlyArray.of(newViewTag), JavaOnlyArray.of(4), null); uiManager.onBatchComplete(); executePendingFrameCallbacks(); View newView = hierarchy.nativeRootView.getChildAt(4); assertThat(newView.getLeft()).isEqualTo(10); assertThat(newView.getTop()).isEqualTo(20); assertThat(newView.getWidth()).isEqualTo(30); assertThat(newView.getHeight()).isEqualTo(40); }
/** * This is to make sure we execute enqueued operations in the order given by JS. */ @Test public void testAddUpdateRemoveInSingleBatch() { UIManagerModule uiManager = getUIManagerModule(); TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager); int newViewTag = 10000; uiManager.createView( newViewTag, ReactViewManager.REACT_CLASS, hierarchy.rootView, JavaOnlyMap.of("collapsable", false)); uiManager.manageChildren( hierarchy.rootView, null, null, JavaOnlyArray.of(newViewTag), JavaOnlyArray.of(4), null); uiManager.updateView( newViewTag, ReactViewManager.REACT_CLASS, JavaOnlyMap.of("backgroundColor", Color.RED)); uiManager.manageChildren( hierarchy.rootView, null, null, null, null, JavaOnlyArray.of(4)); uiManager.onBatchComplete(); executePendingFrameCallbacks(); assertThat(hierarchy.nativeRootView.getChildCount()).isEqualTo(4); }
@Test public void testLayoutPropertyUpdatingOnlyOnLayoutChange() { UIManagerModule uiManager = getUIManagerModule(); TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager); // Update layout to some values, this way we can verify it hasn't been updated, because the // update process would normally reset it back to some non-negative value View view0 = hierarchy.nativeRootView.getChildAt(0); view0.layout(1, 2, 3, 4); // verify that X get updated when we update layout properties uiManager.updateView( hierarchy.view0, ReactViewManager.REACT_CLASS, JavaOnlyMap.of("left", 10.0, "top", 20.0, "width", 30.0, "height", 40.0)); uiManager.onBatchComplete(); executePendingFrameCallbacks(); assertThat(view0.getLeft()).isGreaterThan(2); // verify that the layout doesn't get updated when we update style property not affecting the // position (e.g., background-color) view0.layout(1, 2, 3, 4); uiManager.updateView( hierarchy.view0, ReactViewManager.REACT_CLASS, JavaOnlyMap.of("backgroundColor", Color.RED)); uiManager.onBatchComplete(); executePendingFrameCallbacks(); assertThat(view0.getLeft()).isEqualTo(1); }
@Test public void testAddAndRemoveAnimation() { UIManagerModule uiManagerModule = getUIManagerModule(); TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManagerModule); AnimationPropertyUpdater mockPropertyUpdater = mock(AnimationPropertyUpdater.class); Animation mockAnimation = spy(new AnimationStub(1000, mockPropertyUpdater)); Callback callbackMock = mock(Callback.class); int rootTag = hierarchy.rootView; uiManagerModule.createView( hierarchy.rootView, ReactViewManager.REACT_CLASS, rootTag, JavaOnlyMap.of("collapsable", false)); uiManagerModule.registerAnimation(mockAnimation); uiManagerModule.addAnimation(hierarchy.rootView, 1000, callbackMock); uiManagerModule.removeAnimation(hierarchy.rootView, 1000); uiManagerModule.onBatchComplete(); executePendingFrameCallbacks(); verify(callbackMock, times(1)).invoke(false); verify(mockAnimation).run(); verify(mockAnimation).cancel(); }
private UIManagerModule getUIManagerModule() { List<ViewManager> viewManagers = Arrays.<ViewManager>asList( new ReactViewManager(), new ReactTextViewManager(), new ReactRawTextManager()); UIManagerModule uiManagerModule = new UIManagerModule( mReactContext, viewManagers, new UIImplementationProvider(), false); uiManagerModule.onHostResume(); return uiManagerModule; }
@Override public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) { return Arrays.<ViewManager>asList( ARTRenderableViewManager.createARTGroupViewManager(), ARTRenderableViewManager.createARTShapeViewManager(), ARTRenderableViewManager.createARTTextViewManager(), new ARTSurfaceViewManager(), new ReactDialogPickerManager(), new ReactDrawerLayoutManager(), new ReactDropdownPickerManager(), new ReactHorizontalScrollViewManager(), new ReactImageManager(), new ReactProgressBarViewManager(), new ReactRawTextManager(), new ReactScrollViewManager(), new ReactSwitchManager(), new FrescoBasedReactTextInlineImageViewManager(), new ReactTextInputManager(), new ReactTextViewManager(), new ReactToolbarManager(), new ReactViewManager(), new ReactViewPagerManager(), new ReactVirtualTextViewManager(), new ReactWebViewManager(), new RecyclerViewBackedScrollViewManager(), new SwipeRefreshLayoutManager()); }
@Test public void testLayoutAppliedToNodes() throws Exception { UIManagerModule uiManager = getUIManagerModule(); TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager); int newViewTag = 10000; uiManager.createView( newViewTag, ReactViewManager.REACT_CLASS, hierarchy.rootView, JavaOnlyMap .of("left", 10.0, "top", 20.0, "width", 30.0, "height", 40.0, "collapsable", false)); uiManager.manageChildren( hierarchy.rootView, null, null, JavaOnlyArray.of(newViewTag), JavaOnlyArray.of(4), null); uiManager.onBatchComplete(); executePendingChoreographerCallbacks(); View newView = hierarchy.nativeRootView.getChildAt(4); assertThat(newView.getLeft()).isEqualTo(10); assertThat(newView.getTop()).isEqualTo(20); assertThat(newView.getWidth()).isEqualTo(30); assertThat(newView.getHeight()).isEqualTo(40); }
/** * This is to make sure we execute enqueued operations in the order given by JS. */ @Test public void testAddUpdateRemoveInSingleBatch() { UIManagerModule uiManager = getUIManagerModule(); TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager); int newViewTag = 10000; uiManager.createView( newViewTag, ReactViewManager.REACT_CLASS, hierarchy.rootView, JavaOnlyMap.of("collapsable", false)); uiManager.manageChildren( hierarchy.rootView, null, null, JavaOnlyArray.of(newViewTag), JavaOnlyArray.of(4), null); uiManager.updateView( newViewTag, ReactViewManager.REACT_CLASS, JavaOnlyMap.of("backgroundColor", Color.RED)); uiManager.manageChildren( hierarchy.rootView, null, null, null, null, JavaOnlyArray.of(4)); uiManager.onBatchComplete(); executePendingChoreographerCallbacks(); assertThat(hierarchy.nativeRootView.getChildCount()).isEqualTo(4); }
@Test public void testLayoutPropertyUpdatingOnlyOnLayoutChange() { UIManagerModule uiManager = getUIManagerModule(); TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager); // Update layout to some values, this way we can verify it hasn't been updated, because the // update process would normally reset it back to some non-negative value View view0 = hierarchy.nativeRootView.getChildAt(0); view0.layout(1, 2, 3, 4); // verify that X get updated when we update layout properties uiManager.updateView( hierarchy.view0, ReactViewManager.REACT_CLASS, JavaOnlyMap.of("left", 10.0, "top", 20.0, "width", 30.0, "height", 40.0)); uiManager.onBatchComplete(); executePendingChoreographerCallbacks(); assertThat(view0.getLeft()).isGreaterThan(2); // verify that the layout doesn't get updated when we update style property not affecting the // position (e.g., background-color) view0.layout(1, 2, 3, 4); uiManager.updateView( hierarchy.view0, ReactViewManager.REACT_CLASS, JavaOnlyMap.of("backgroundColor", Color.RED)); uiManager.onBatchComplete(); executePendingChoreographerCallbacks(); assertThat(view0.getLeft()).isEqualTo(1); }
@Test public void testAddAndRemoveAnimation() { UIManagerModule uiManagerModule = getUIManagerModule(); TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManagerModule); AnimationPropertyUpdater mockPropertyUpdater = mock(AnimationPropertyUpdater.class); Animation mockAnimation = spy(new AnimationStub(1000, mockPropertyUpdater)); Callback callbackMock = mock(Callback.class); int rootTag = hierarchy.rootView; uiManagerModule.createView( hierarchy.rootView, ReactViewManager.REACT_CLASS, rootTag, JavaOnlyMap.of("collapsable", false)); uiManagerModule.registerAnimation(mockAnimation); uiManagerModule.addAnimation(hierarchy.rootView, 1000, callbackMock); uiManagerModule.removeAnimation(hierarchy.rootView, 1000); uiManagerModule.onBatchComplete(); executePendingChoreographerCallbacks(); verify(callbackMock, times(1)).invoke(false); verify(mockAnimation).run(); verify(mockAnimation).cancel(); }
private UIManagerModule getUIManagerModule() { List<ViewManager> viewManagers = Arrays.<ViewManager>asList( new ReactViewManager(), new ReactTextViewManager(), new ReactRawTextManager()); UIManagerModule uiManagerModule = new UIManagerModule( mReactContext, viewManagers, new UIImplementation(mReactContext, viewManagers)); uiManagerModule.onHostResume(); return uiManagerModule; }