@Override protected LithoView buildView(@NonNull ViewGroup parent) { return new LithoView(parent.getContext()); } }
LithoScrollView(Context context) { super(context); mLithoView = new LithoView(context); addView(mLithoView); }
public HorizontalScrollLithoView(Context context) { super(context); mLithoView = new LithoView(context); addView(mLithoView); }
@OnCreateMountContent static LithoView onCreateMountContent(Context c) { return new LithoView(c); }
/** 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); } }
/** * 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; }
@Before public void setup() { final Component component = new InlineLayoutSpec() { @Override protected Component onCreateLayout(ComponentContext c) { return TestDrawableComponent.create(c).widthPx(100).heightPx(100).build(); } }; mLithoView = new LithoView(RuntimeEnvironment.application); mLithoView.setComponent(component); }
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; }
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; } }
private LithoView getLithoView(Component component) { LithoView lithoView = new LithoView(mContext); lithoView.setComponent(component); lithoView.measure( View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); lithoView.layout(0, 0, lithoView.getMeasuredWidth(), lithoView.getMeasuredHeight()); return lithoView; }
@Test public void testListenerNotInvokedWhenMeasureDoesntComputeALayout() { mComponentTree.setNewLayoutStateReadyListener(mListener); mComponentTree.setLithoView(new LithoView(mContext)); mComponentTree.attach(); mComponentTree.setSizeSpec(mWidthSpec, mHeightSpec); verify(mListener).onNewLayoutStateReady(mComponentTree); reset(mListener); mComponentTree.measure(mWidthSpec, mHeightSpec, new int[] {0, 0}, false); verify(mListener, never()).onNewLayoutStateReady(mComponentTree); }
private LithoView getLithoView(Component component) { LithoView lithoView = new LithoView(mContext); lithoView.setComponent(component); lithoView.measure( View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); lithoView.layout( 0, 0, lithoView.getMeasuredWidth(), lithoView.getMeasuredHeight()); return lithoView; }
@Test public void testListenerInvokedForSetRootAsyncWhenAttached() { mComponentTree.setNewLayoutStateReadyListener(mListener); mComponentTree.setSizeSpecAsync(mWidthSpec, mHeightSpec); mComponentTree.setLithoView(new LithoView(mContext)); mComponentTree.attach(); verify(mListener, never()).onNewLayoutStateReady(any(ComponentTree.class)); // Now the background thread run the queued task. mLayoutThreadShadowLooper.runToEndOfTasks(); verify(mListener).onNewLayoutStateReady(mComponentTree); }
@Test public void testListenerInvokedForMeasure() { mComponentTree.setNewLayoutStateReadyListener(mListener); mComponentTree.setLithoView(new LithoView(mContext)); mComponentTree.attach(); mComponentTree.setSizeSpec(mWidthSpec, mHeightSpec); verify(mListener).onNewLayoutStateReady(mComponentTree); reset(mListener); mComponentTree.measure(mWidthSpec2, mHeightSpec2, new int[] {0, 0}, false); verify(mListener).onNewLayoutStateReady(mComponentTree); }
@Before public void setup() { mContext = new ComponentContext(RuntimeEnvironment.application); mLithoView = new LithoView(mContext); mParent = new FrameLayout(mContext.getAndroidContext()); mParent.setLeft(0); mParent.setTop(0); mParent.setRight(10); mParent.setBottom(10); mParent.addView(mLithoView); }
@Test public void testListenerNotInvokedWhenNewMeasureSpecsAreCompatible() { mComponentTree.setLithoView(new LithoView(mContext)); mComponentTree.attach(); mComponentTree.setSizeSpec(mWidthSpec, mHeightSpec); mComponentTree.setNewLayoutStateReadyListener(mListener); mComponentTree.setSizeSpec(mWidthSpec, mHeightSpec); verify(mListener, never()).onNewLayoutStateReady(mComponentTree); } }
@Test public void testMeasureComputesLayoutStateWhenSpecsAreNotExact() { mLithoView = new LithoView(RuntimeEnvironment.application); mLithoView.setComponent( TestDrawableComponent.create(mLithoView.getComponentContext()).heightPx(100).build()); mLithoView.measure(makeMeasureSpec(100, EXACTLY), makeMeasureSpec(100, AT_MOST)); assertThat(mLithoView.getMeasuredWidth()).isEqualTo(100); assertThat(mLithoView.getMeasuredHeight()).isEqualTo(100); assertThat(mLithoView.getComponentTree().getMainThreadLayoutState()).isNotNull(); }
@Test public void testSetSizeSpecWithOutputWhenAttachedToViewWithSameSpec() { ComponentTree componentTree = ComponentTree.create(mContext, mComponent).build(); componentTree.setLithoView(new LithoView(mContext)); Size size = new Size(); componentTree.measure(mWidthSpec, mHeightSpec, new int[2], false); componentTree.attach(); componentTree.setSizeSpec(mWidthSpec, mHeightSpec, size); assertEquals(SizeSpec.getSize(mWidthSpec), size.width, 0.0); assertEquals(SizeSpec.getSize(mHeightSpec), size.height, 0.0); assertThat(componentTree.hasCompatibleLayout(mWidthSpec, mHeightSpec)).isTrue(); assertThat(componentTree.getRoot()).isEqualTo(mComponent); }
@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 testMeasureDoesNotComputeLayoutStateWhenSpecsAreExact() { mLithoView = new LithoView(RuntimeEnvironment.application); mLithoView.setComponent(TestDrawableComponent.create(mLithoView.getComponentContext()).build()); mLithoView.measure(makeMeasureSpec(100, EXACTLY), makeMeasureSpec(100, EXACTLY)); assertThat(mLithoView.getMeasuredWidth()).isEqualTo(100); assertThat(mLithoView.getMeasuredHeight()).isEqualTo(100); assertThat(mLithoView.getComponentTree().getMainThreadLayoutState()).isNull(); mLithoView.layout(0, 0, 50, 50); final LayoutState layoutState = mLithoView.getComponentTree().getMainThreadLayoutState(); assertThat(layoutState).isNotNull(); assertThat(layoutState.isCompatibleSize(50, 50)).isTrue(); }