@Override public void callOnAttachedToWindow() { super.callOnAttachedToWindow(); }
/** This verifies that the width is 0 with normal layout params. */ @Test public void measureWithLayoutParams() { final Component component = new InlineLayoutSpec() { @Override protected Component onCreateLayout(ComponentContext c) { return TestDrawableComponent.create(c).widthPercent(100).heightPx(100).build(); } }; mLithoView = new LithoView(RuntimeEnvironment.application); mLithoView.setComponent(component); mLithoView.setLayoutParams(new ViewGroup.LayoutParams(0, 200)); mLithoView.measure(makeMeasureSpec(0, UNSPECIFIED), makeMeasureSpec(200, EXACTLY)); mLithoView.layout(0, 0, mLithoView.getMeasuredWidth(), mLithoView.getMeasuredHeight()); // View got measured. assertThat(mLithoView.getMeasuredWidth()).isEqualTo(0); assertThat(mLithoView.getMeasuredHeight()).isEqualTo(200); // Attaching will not mount anything as we have no width. ShadowView shadow = shadowOf(mLithoView); shadow.callOnAttachedToWindow(); assertThat(getInternalMountItems(mLithoView)).isNull(); }
@Test public void measureBeforeBeingAttached() { mLithoView.measure( makeMeasureSpec(0, UNSPECIFIED), makeMeasureSpec(0, UNSPECIFIED)); mLithoView.layout( 0, 0, mLithoView.getMeasuredWidth(), mLithoView.getMeasuredHeight()); // View got measured. assertThat(mLithoView.getMeasuredWidth()).isGreaterThan(0); assertThat(mLithoView.getMeasuredHeight()).isGreaterThan(0); // Attaching will automatically mount since we already have a layout fitting our size. ShadowView shadow = shadowOf(mLithoView); shadow.callOnAttachedToWindow(); assertThat(getInternalMountItems(mLithoView)).hasSize(2); }
/** This verifies that the width is correct with at most layout params. */ @Test public void measureWithAtMostLayoutParams() { final Component component = new InlineLayoutSpec() { @Override protected Component onCreateLayout(ComponentContext c) { return TestDrawableComponent.create(c).widthPercent(50).heightPercent(10).build(); } }; mLithoView = new LithoView(RuntimeEnvironment.application); mLithoView.setComponent(component); mLithoView.setLayoutParams( new RecyclerViewLayoutManagerOverrideParams( SizeSpec.makeSizeSpec(100, SizeSpec.AT_MOST), SizeSpec.makeSizeSpec(200, SizeSpec.AT_MOST))); mLithoView.measure(makeMeasureSpec(0, UNSPECIFIED), makeMeasureSpec(0, UNSPECIFIED)); mLithoView.layout(0, 0, mLithoView.getMeasuredWidth(), mLithoView.getMeasuredHeight()); // View got measured. assertThat(mLithoView.getMeasuredWidth()).isEqualTo(50); assertThat(mLithoView.getMeasuredHeight()).isEqualTo(20); // Attaching will automatically mount since we already have a layout fitting our size. ShadowView shadow = shadowOf(mLithoView); shadow.callOnAttachedToWindow(); assertThat(getInternalMountItems(mLithoView)).hasSize(2); }