Java Code Examples for com.facebook.yoga.YogaMeasureFunction#measure()
The following examples show how to use
com.facebook.yoga.YogaMeasureFunction#measure() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ComponentLifecycleTest.java From litho with Apache License 2.0 | 6 votes |
@Test public void testLayoutSpecMeasureResolveNestedTree() { Component component = setUpSpyComponentForCreateLayout(false /* isMountSpec */, true /* canMeasure */); YogaMeasureFunction measureFunction = getMeasureFunction(component); final int nestedTreeWidth = 20; final int nestedTreeHeight = 25; InternalNode nestedTree = mock(InternalNode.class); when(nestedTree.getWidth()).thenReturn(nestedTreeWidth); when(nestedTree.getHeight()).thenReturn(nestedTreeHeight); when(Layout.create(eq(mContext), eq(mNode), anyInt(), anyInt())).thenReturn(nestedTree); when(mNode.getContext()).thenReturn(mContext); long output = measureFunction.measure(mYogaNode, 0, EXACTLY, 0, EXACTLY); PowerMockito.verifyStatic(Layout.class); Layout.create(eq(mContext), eq(mNode), anyInt(), anyInt()); assertThat(YogaMeasureOutput.getWidth(output)).isEqualTo(nestedTreeWidth); assertThat(YogaMeasureOutput.getHeight(output)).isEqualTo(nestedTreeHeight); }
Example 2
Source File: ComponentLifecycleTest.java From litho with Apache License 2.0 | 6 votes |
@Test public void testLayoutSpecMeasureResolveNestedTree_withExperiment() { Component component = setUpSpyComponentForCreateLayout(false /* isMountSpec */, true /* canMeasure */); YogaMeasureFunction measureFunction = getMeasureFunction(component); final int nestedTreeWidth = 20; final int nestedTreeHeight = 25; InternalNode nestedTree = mock(InternalNode.class); when(nestedTree.getWidth()).thenReturn(nestedTreeWidth); when(nestedTree.getHeight()).thenReturn(nestedTreeHeight); when(Layout.create(eq(mContext), eq(mNode), anyInt(), anyInt())).thenReturn(nestedTree); when(mNode.getContext()).thenReturn(mContext); when(mContext.isReconciliationEnabled()).thenReturn(true); when(mNode.getParent()).thenReturn(mNode); when(mNode.getContext()).thenReturn(mContext); long output = measureFunction.measure(mYogaNode, 0, EXACTLY, 0, EXACTLY); PowerMockito.verifyStatic(Layout.class); Layout.create(eq(mContext), eq(mNode), anyInt(), anyInt()); assertThat(YogaMeasureOutput.getWidth(output)).isEqualTo(nestedTreeWidth); assertThat(YogaMeasureOutput.getHeight(output)).isEqualTo(nestedTreeHeight); }
Example 3
Source File: ComponentLifecycleTest.java From litho with Apache License 2.0 | 5 votes |
@Test public void testOnMeasureNotOverridden() { Component component = setUpSpyComponentForCreateLayout(true, true); YogaMeasureFunction measureFunction = getMeasureFunction(component); try { measureFunction.measure(mYogaNode, 0, EXACTLY, 0, EXACTLY); fail("Should have failed without overridden onMeasure() when canMeasure() returns true."); } catch (Exception e) { assertThat(e).isExactlyInstanceOf(IllegalStateException.class); assertThat(e.getMessage()).contains("canMeasure()"); } }
Example 4
Source File: ComponentLifecycleTest.java From litho with Apache License 2.0 | 5 votes |
@Test public void testMountSpecYogaMeasureOutputNotSet() { Component component = new TestMountSpecWithEmptyOnMeasure(mNode); YogaMeasureFunction measureFunction = getMeasureFunction(component); try { measureFunction.measure(mYogaNode, 0, EXACTLY, 0, EXACTLY); fail("Should have failed when onMeasure() is empty."); } catch (Exception e) { assertThat(e).isExactlyInstanceOf(IllegalStateException.class); assertThat(e.getMessage()).contains("MeasureOutput not set"); } }
Example 5
Source File: ComponentLifecycleTest.java From litho with Apache License 2.0 | 5 votes |
@Test public void testMountSpecYogaMeasureOutputSet() { Component component = new TestMountSpecSettingSizesInOnMeasure(mNode); YogaMeasureFunction measureFunction = getMeasureFunction(component); long output = measureFunction.measure(mYogaNode, 0, EXACTLY, 0, EXACTLY); assertThat(YogaMeasureOutput.getWidth(output)).isEqualTo(A_WIDTH); assertThat(YogaMeasureOutput.getHeight(output)).isEqualTo(A_HEIGHT); }
Example 6
Source File: TreeDiffingTest.java From litho with Apache License 2.0 | 5 votes |
private long measureInternalNode( InternalNode node, float widthConstranint, float heightConstraint) { final YogaMeasureFunction measureFunc = Whitebox.getInternalState(node.getYogaNode(), "mMeasureFunction"); return measureFunc.measure( node.getYogaNode(), widthConstranint, EXACTLY, heightConstraint, EXACTLY); }