/** * Mount a component into a component view. * * @param context A components context * @param lithoView The view to mount the component into * @param component The component to mount * @param incrementalMountEnabled States whether incremental mount is enabled * @param width The width of the resulting view * @param height The height of the resulting view * @return A LithoView with the component mounted in it. */ public static LithoView mountComponent( ComponentContext context, LithoView lithoView, Component component, boolean incrementalMountEnabled, int width, int height) { return mountComponent( lithoView, ComponentTree.create(context, component) .incrementalMount(incrementalMountEnabled) .layoutDiffing(false) .build(), makeMeasureSpec(width, EXACTLY), makeMeasureSpec(height, EXACTLY)); }
@Before public void setup() { ComponentContext context = new ComponentContext(RuntimeEnvironment.application); mComponentTree = ComponentTree.create( context, TestDrawableComponent.create(context).color(Color.BLACK).build()) .layoutDiffing(false) .build(); mLithoView = mock(TestLithoView.class); when(mLithoView.getMountState()).thenReturn(mock(MountState.class)); Whitebox.setInternalState(mComponentTree, "mLithoView", mLithoView); Whitebox.setInternalState(mComponentTree, "mMainThreadLayoutState", mock(LayoutState.class)); // Can't use verify as the rect is reset when it is released back to the pool, which occurs // before we can check it. doAnswer( new Answer() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { mMountedRect.set((Rect) invocation.getArguments()[1]); return null; } }) .when(mLithoView) .mount(any(LayoutState.class), any(Rect.class), eq(true)); }
@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); }
final ComponentTree componentTree = ComponentTree.create(context, component) .incrementalMount(incrementalMountEnabled) .layoutDiffing(false) .build();
ComponentTree.create(mContext, oldComponent) .incrementalMount(false) .layoutDiffing(true) .build();
ComponentTree.create(mContext, oldComponent) .incrementalMount(false) .layoutDiffing(true) .build();
ComponentTree.create(mContext, oldComponent) .incrementalMount(false) .layoutDiffing(true) .build();
builder.layoutDiffing((boolean) layoutDiffingEnabledAttr);
@Override public Builder layoutDiffing(boolean enabled) { return (Builder) super.layoutDiffing(enabled); }
private ComponentTree createComponentTree(boolean useSpy, boolean incMountEnabled, int width, int height) { ComponentTree componentTree = ComponentTree.create(mContext, mComponent) .incrementalMount(incMountEnabled) .layoutDiffing(false) .build(); componentTree.setSizeSpec( SizeSpec.makeSizeSpec(width, EXACTLY), SizeSpec.makeSizeSpec(height, EXACTLY)); return useSpy ? spy(componentTree) : componentTree; }