@Test public void testMeasureWithIncompatibleSetRootAsync() throws InterruptedException { ComponentTree componentTree = ComponentTree.create(mContext, mComponent).build(); componentTree.setLithoView(new LithoView(mContext));
final ComponentTree componentTree = ComponentTree.create(mContext, oldComponent) .incrementalMount(false) .layoutDiffing(true) .build();
@Override public void bind(@NonNull LithoView view) { Component<T> component = getComponent(view.getComponentContext()); if (view.getComponentTree() == null) { view.setComponentTree(ComponentTree.create(view.getComponentContext(), component) .asyncStateUpdates(false) // does this need to be off? .layoutThreadLooper(Looper.getMainLooper()) .incrementalMount( false) // this needs to be off for recyclerview to work. Should we manually // incrementally mount views in a scroll listener? .layoutDiffing(false) // should we use this? .build()); } view.setComponent(component); }
.build(); ComponentTree tree = ComponentTree.create(mContext, firstLayout).build(); LithoView cv = new LithoView(mContext);
.layoutThreadHandler(handler) .useSharedLayoutStateFuture(true) .build();
.heightPx(10)) .build()) .build());
.build(); ComponentTree componentTree = ComponentTree.create(mContext, firstComponent).build(); LayoutState state = componentTree.calculateLayoutState(
.build(); LayoutState state = componentTree.calculateLayoutState(
.layoutThreadHandler(handler) .useSharedLayoutStateFuture(true) .build();
.build(); LayoutState state = componentTree.calculateLayoutState(
.incrementalMount(incrementalMountEnabled) .layoutDiffing(false) .build();
final ComponentTree componentTree = ComponentTree.create(mContext, oldComponent) .incrementalMount(false) .layoutDiffing(true) .build();
final ComponentTree componentTree = ComponentTree.create(mContext, oldComponent) .incrementalMount(false) .layoutDiffing(true) .build();
.build(); LayoutState state = componentTree.calculateLayoutState(
.layoutThreadHandler(handler) .useSharedLayoutStateFuture(true) .build();
@Before public void setup() { MockitoAnnotations.initMocks(this); mContext = new ComponentContext(RuntimeEnvironment.application); mComponent = new InlineLayoutSpec() { @Override @OnCreateLayout protected Component onCreateLayout(ComponentContext c) { return Row.create(c) .marginPx(YogaEdge.LEFT, MARGIN_LEFT) .marginPx(YogaEdge.TOP, MARGIN_TOP) .child( TestDrawableComponent.create(c) .key("anchor") .widthPx(ANCHOR_WIDTH) .heightPx(ANCHOR_HEIGHT)) .build(); } }; mComponentTree = ComponentTree.create(mContext, mComponent).build(); Whitebox.setInternalState( mComponent, "mGlobalKey", ComponentKeyUtils.getKeyWithSeparator( mComponent.getTypeId(), Row.create(mContext).build().getTypeId())); mContext = ComponentContext.withComponentTree(mContext, mComponentTree); mContext = ComponentContext.withComponentScope(mContext, mComponent); mLithoView = getLithoView(mComponentTree); }
@Test public void testSkipShouldUpdateAndRemountForUnsupportedComponent() { final TestComponent firstComponent = create( mContext, false, true, true, false, false) .build(); final LithoView firstLithoView = mountComponent(mContext, Column.create(mContext).child(firstComponent).build()); assertThat(firstComponent.wasOnMountCalled()).isTrue(); assertThat(firstComponent.wasOnBindCalled()).isTrue(); assertThat(firstComponent.wasOnUnmountCalled()).isFalse(); final TestComponent secondComponent = spy(create(mContext, false, true, true, false, false).build()); doReturn(secondComponent).when(secondComponent).makeShallowCopy(); final ComponentTree secondTree = ComponentTree.create(mContext, Column.create(mContext).child(secondComponent).build()) .build(); secondTree.setSizeSpec(100, 100); mountComponent(firstLithoView, secondTree); verify(secondComponent).makeShallowCopy(); assertThat(secondComponent.wasOnMountCalled()).isTrue(); assertThat(secondComponent.wasOnBindCalled()).isTrue(); assertThat(firstComponent.wasOnUnmountCalled()).isTrue(); }
@Test public void testMeasureWithIncompatibleSetRootAsyncThatFinishes() { ComponentTree componentTree = ComponentTree.create(mContext, mComponent).build(); componentTree.setLithoView(new LithoView(mContext)); int widthSpec1 = SizeSpec.makeSizeSpec(1000, SizeSpec.EXACTLY); int heightSpec1 = SizeSpec.makeSizeSpec(1000, SizeSpec.AT_MOST); int widthSpec2 = SizeSpec.makeSizeSpec(1000, SizeSpec.EXACTLY); int heightSpec2 = SizeSpec.makeSizeSpec(0, SizeSpec.UNSPECIFIED); componentTree.measure(widthSpec2, heightSpec2, new int[2], false); componentTree.attach(); componentTree.measure(widthSpec1, heightSpec1, new int[2], false); Component newComponent = TestDrawableComponent.create(mContext).color(1234).build(); componentTree.setRootAsync(newComponent); runOnBackgroundThreadSync( new Runnable() { @Override public void run() { // "Commit" layout (it will fail since it doesn't have compatible size specs) mLayoutThreadShadowLooper.runToEndOfTasks(); } }); componentTree.measure(widthSpec2, heightSpec2, new int[2], false); assertThat(componentTree.getRoot()).isEqualTo(newComponent); assertThat(componentTree.hasCompatibleLayout(widthSpec2, heightSpec2)).isTrue(); assertThat(componentTree.getMainThreadLayoutState().isForComponentId(newComponent.getId())) .isTrue() .withFailMessage( "The main thread should calculate a new layout synchronously because the async layout will not be used once it completes"); }
@Test public void testMeasureWithIncompatibleSetRootAsyncBeforeStart() { ComponentTree componentTree = ComponentTree.create(mContext, mComponent).build(); componentTree.setLithoView(new LithoView(mContext));
@Test public void testMountUnmountWithNoShouldUpdateAndSameMeasures() { final TestComponent firstComponent = create(mContext, 0, 0, true, true, true, false, false, true) .color(Color.GRAY) .build(); final LithoView lithoView = mountComponent( new LithoView(mContext), ComponentTree.create(mContext, Column.create(mContext).child(firstComponent).build()) .build(), makeMeasureSpec(100, EXACTLY), makeMeasureSpec(100, EXACTLY)); assertThat(firstComponent.wasOnMountCalled()).isTrue(); assertThat(firstComponent.wasOnBindCalled()).isTrue(); assertThat(firstComponent.wasOnUnmountCalled()).isFalse(); final TestComponent secondComponent = create(mContext) .color(Color.RED) .build(); lithoView .getComponentTree() .setRoot(Column.create(mContext).child(secondComponent).widthPx(10).heightPx(10).build()); assertThat(lithoView.isLayoutRequested()).isFalse(); assertThat(secondComponent.wasOnMountCalled()).isTrue(); assertThat(secondComponent.wasOnBindCalled()).isTrue(); assertThat(firstComponent.wasOnUnmountCalled()).isTrue(); }