@Override public void run() { component.measure(mContext, 100, 100, new Size()); cachedLayouts[0] = component.getCachedLayout(); lockWaitMeasure.countDown(); } });
@Override public void run() { component.measure(mContext, 100, 100, new Size()); cachedLayouts[0] = component.getCachedLayout(); lockWaitMeasure.countDown(); } });
@Override public void run() { // Wait for component to have a cached layout, then make copy. try { lockWaitMeasure.await(5, TimeUnit.SECONDS); } catch (InterruptedException e) { throw new IllegalStateException(); } resultCopyComponent[0] = component.makeShallowCopy(); resultCopyComponent[0].measure(mContext, 100, 100, new Size()); cachedLayouts[1] = resultCopyComponent[0].getCachedLayout(); testFinished.countDown(); } });
@Test public void testShallowCopyCachedLayoutSameThread() { Component component = TestDrawableComponent.create(mContext).build(); component.measure(mContext, 100, 100, new Size()); assertThat(component.getCachedLayout()).isNotNull(); assertThat(component.getCachedLayout()).isNotNull(); Component copyComponent = component.makeShallowCopy(); assertThat(copyComponent.getCachedLayout()).isNotNull(); }
@OnMeasure static void onMeasure( ComponentContext context, ComponentLayout layout, int widthSpec, int heightSpec, Size size, @Prop Component contentProps, Output<Integer> measuredComponentWidth, Output<Integer> measuredComponentHeight) { final int measuredWidth; final int measuredHeight; final Size contentSize = acquireSize(); // Measure the component with undefined width spec, as the contents of the // hscroll have unlimited horizontal space. contentProps.measure(context, SizeSpec.makeSizeSpec(0, UNSPECIFIED), heightSpec, contentSize); measuredWidth = contentSize.width; measuredHeight = contentSize.height; releaseSize(contentSize); measuredComponentWidth.set(measuredWidth); measuredComponentHeight.set(measuredHeight); // If size constraints were not explicitly defined, just fallback to the // component dimensions instead. size.width = SizeSpec.getMode(widthSpec) == UNSPECIFIED ? measuredWidth : SizeSpec.getSize(widthSpec); size.height = measuredHeight; }
componentSpy.measure( c, widthMeasuredComponent,
TestLayoutComponent.create(c, 0, 0, true, true, true, false).build()); final Size sizeOutput = new Size(); componentSpy.measure( c, widthMeasuredComponent,
.build()); final Size sizeOutput = new Size(); sizeDependentComponentSpy.measure( c, widthMeasuredComponent,
@Test public void testComponentCreateAndRetrieveCachedLayout() { final ComponentContext c = new ComponentContext(application); final int unspecifiedSizeSpec = makeSizeSpec(0, UNSPECIFIED); final int exactSizeSpec = makeSizeSpec(50, EXACTLY); final Component textComponent = Text.create(c) .textSizePx(16) .text("test") .build(); final Size textSize = new Size(); textComponent.measure( c, exactSizeSpec, unspecifiedSizeSpec, textSize); assertThat(textComponent.getCachedLayout()).isNotNull(); InternalNode cachedLayout = textComponent.getCachedLayout(); assertThat(cachedLayout).isNotNull(); assertThat(cachedLayout.getLastWidthSpec()).isEqualTo(exactSizeSpec); assertThat(cachedLayout.getLastHeightSpec()).isEqualTo(unspecifiedSizeSpec); textComponent.clearCachedLayout(); assertThat(textComponent.getCachedLayout()).isNull(); }
contentProps.measure( context, SizeSpec.makeSizeSpec(0, UNSPECIFIED),
.build()); final Size sizeOutput = new Size(); sizeDependentComponentSpy.measure( c, widthMeasuredComponent,