@OnUnmount static void onUnmount(ComponentContext c, LithoView mountedView) { mountedView.setComponentTree(null); } }
/** Sets or replaces the ComponentTree being rendered in this Activity. */ public void setComponentTree(ComponentTree componentTree) { final LithoView lithoView = new LithoView(this); lithoView.setComponentTree(componentTree); setContentView(lithoView); } }
private void unmount() { mLithoView.setComponentTree(null); mScrollPosition = null; getViewTreeObserver().removeOnPreDrawListener(mOnPreDrawListener); mOnPreDrawListener = null; } }
/** * Create a new {@link LithoView} instance and initialize it * with the given {@link Component} root. * * @param context {@link ComponentContext}. * @param component The root component to draw. * @return {@link LithoView} able to render a {@link Component} hierarchy. */ public static LithoView create(ComponentContext context, Component component) { final LithoView lithoView = new LithoView(context); lithoView.setComponentTree(ComponentTree.create(context, component).build()); return lithoView; }
@Override public void onViewRecycled(BaseViewHolder holder) { if (holder.isLithoViewType) { final LithoView lithoView = (LithoView) holder.itemView; lithoView.unmountAllItems(); lithoView.setComponentTree(null); lithoView.setInvalidStateLogParamsList(null); } else { final ViewBinder viewBinder = holder.viewBinder; if (viewBinder != null) { viewBinder.unbind(holder.itemView); holder.viewBinder = null; } } }
/** * Change the root component measuring it on a background thread before updating the UI. * If this {@link LithoView} doesn't have a ComponentTree initialized, the root will be * computed synchronously. */ public void setComponentAsync(Component component) { if (mComponentTree == null) { setComponentTree(ComponentTree.create(getComponentContext(), component).build()); } else { mComponentTree.setRootAsync(component); } }
/** * Change the root component synchronously. */ public void setComponent(Component component) { if (mComponentTree == null) { setComponentTree(ComponentTree.create(getComponentContext(), component).build()); } else { mComponentTree.setRoot(component); } }
public void setStickyComponent(ComponentTree component) { if (component.getLithoView() != null) { component.getLithoView().startTemporaryDetach(); } mStickyHeader.setComponentTree(component); measureStickyHeader(getWidth()); }
@Test public void testDontThrowWhenLayoutStateIsNull() { final ComponentTree mockComponentTree = mock(ComponentTree.class); mLithoView.setComponentTree(mockComponentTree); mLithoView.requestLayout(); mLithoView.performIncrementalMount(); }
private void buildAndSetComponentTree(boolean useRT) { final ComponentContext context = new ComponentContext(this); final Component component = RTAnimationComponent.create(context).useRT(useRT).build(); mLithoView.setComponentTree(ComponentTree.create(context, component).build()); }
void mount(Component component, int width, int height) { if (mLithoView.getComponentTree() == null) { mLithoView.setComponentTree( ComponentTree.create(mLithoView.getComponentContext(), component) .incrementalMount(false) .build()); } else { mLithoView.setComponent(component); } mComponentWidth = width; mComponentHeight = height; }
public static LithoView createAndMeasureLithoView( ComponentContext c, Component component, int widthSpec, int heightSpec) { final ComponentTree componentTree = ComponentTree.create(c, component).build(); final LithoView lithoView = new LithoView(c); lithoView.setComponentTree(componentTree); lithoView.onAttachedToWindow(); lithoView.measure(widthSpec, heightSpec); // This is really lithoView#layout without the mount componentTree.measure(widthSpec, heightSpec, LAYOUT_SIZE_OUT, false); return lithoView; }
@Test public void testSuppressMeasureComponentTree() { final ComponentTree mockComponentTree = mock(ComponentTree.class); final int width = 240; final int height = 400; mLithoView.setComponentTree(mockComponentTree); mLithoView.suppressMeasureComponentTree(true); mLithoView.measure( makeMeasureSpec(width, EXACTLY), makeMeasureSpec(height, EXACTLY)); verify(mockComponentTree, never()) .measure(anyInt(), anyInt(), any(int[].class), anyBoolean()); LithoViewAssert.assertThat(mLithoView) .hasMeasuredWidthOf(width) .hasMeasuredHeightOf(height); }
private LithoView getLithoView(ComponentTree componentTree) { LithoView lithoView = new LithoView(mContext); lithoView.setComponentTree(componentTree); lithoView.measure( View.MeasureSpec.makeMeasureSpec(HOST_WIDTH, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(HOST_HEIGHT, View.MeasureSpec.EXACTLY)); lithoView.layout(0, 0, lithoView.getMeasuredWidth(), lithoView.getMeasuredHeight()); return lithoView; } }
@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); }
private LithoView getLithoView(ComponentTree componentTree) { LithoView lithoView = new LithoView(mContext); lithoView.setComponentTree(componentTree); lithoView.measure( View.MeasureSpec.makeMeasureSpec(HOST_WIDTH, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(HOST_HEIGHT, View.MeasureSpec.EXACTLY)); lithoView.layout( 0, 0, lithoView.getMeasuredWidth(), lithoView.getMeasuredHeight()); return lithoView; }
@Override public void run() { mView.setComponentTree(tree); ViewHelpers.setupView(mView).setExactWidthPx(200).setExactHeightPx(100).layout(); } });
@Test public void testSetTreeToTwoViewsBothAttached() { Component component = TestDrawableComponent.create(mContext) .build(); ComponentTree componentTree = ComponentTree.create( mContext, component) .build(); // Attach first view. LithoView lithoView1 = new LithoView(mContext); lithoView1.setComponentTree(componentTree); lithoView1.onAttachedToWindow(); // Attach second view. LithoView lithoView2 = new LithoView(mContext); lithoView2.onAttachedToWindow(); // Set the component that is already mounted on the first view, on the second attached view. // This should be ok. lithoView2.setComponentTree(componentTree); }
@Before public void setup() throws Exception { mLithoView = new LithoView(RuntimeEnvironment.application); mComponent = LifecycleMethodsComponent.create(10); final ComponentContext c = new ComponentContext(RuntimeEnvironment.application); mComponentTree = ComponentTree.create(c, mComponent).build(); mLithoView.setComponentTree(mComponentTree); }
@Test public void testComponentTreeReleaseClearsView() { Component component = TestDrawableComponent.create(mContext) .build(); ComponentTree componentTree = create( mContext, component) .build(); LithoView lithoView = new LithoView(mContext); lithoView.setComponentTree(componentTree); assertThat(componentTree).isEqualTo(lithoView.getComponentTree()); componentTree.release(); assertThat(lithoView.getComponentTree()).isNull(); }