com.facebook.yoga.YogaMeasureFunction Java Examples

The following examples show how to use com.facebook.yoga.YogaMeasureFunction. 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 vote down vote up
@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 #2
Source File: ComponentLifecycleTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@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 #3
Source File: ComponentLifecycleTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateLayoutAndDontResolveNestedTreeWithLayoutSpecCannotMeasure() {
  Component component =
      setUpSpyComponentForCreateLayout(false /* isMountSpec */, false /* canMeasure */);
  InternalNode node = Layout.create(mContext, component, false);

  verify(component).onCreateLayout(mContext);
  verify(node).appendComponent(component);
  verify(node, never()).setMeasureFunction((YogaMeasureFunction) any());
}
 
Example #4
Source File: TreeDiffingTest.java    From litho with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #5
Source File: ComponentLifecycleTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@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: ComponentLifecycleTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@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 #7
Source File: ComponentLifecycleTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@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 #8
Source File: ComponentLifecycleTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateLayoutAndDontResolveNestedTreeWithLayoutSpecCanMeasure() {
  Component component =
      setUpSpyComponentForCreateLayout(false /* isMountSpec */, true /* canMeasure */);
  InternalNode node = Layout.create(mContext, component, false);

  verify(component, never()).onCreateLayout((ComponentContext) any());
  verify(component, never())
      .onCreateLayoutWithSizeSpec((ComponentContext) any(), anyInt(), anyInt());
  verify(node).appendComponent(component);
  verify(node).setMeasureFunction((YogaMeasureFunction) any());
  verify(component, never()).onPrepare((ComponentContext) any());
}
 
Example #9
Source File: ComponentLifecycleTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateLayoutAndResolveNestedTreeWithLayoutSpecCanMeasure() {
  Component component =
      setUpSpyComponentForCreateLayout(false /* isMountSpec */, true /* canMeasure */);
  mContext.setWidthSpec(mNestedTreeWidthSpec);
  mContext.setHeightSpec(mNestedTreeHeightSpec);
  InternalNode node = Layout.create(mContext, component, true);

  verify(component)
      .onCreateLayoutWithSizeSpec(mContext, mNestedTreeWidthSpec, mNestedTreeHeightSpec);
  verify(node).appendComponent(component);
  verify(node, never()).setMeasureFunction((YogaMeasureFunction) any());
}
 
Example #10
Source File: ComponentLifecycleTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateLayoutAndResolveNestedTreeWithLayoutSpecCannotMeasure() {
  Component component =
      setUpSpyComponentForCreateLayout(false /* isMountSpec */, false /* canMeasure */);
  InternalNode node = Layout.create(mContext, component, true);

  verify(component).onCreateLayout(mContext);
  verify(node).appendComponent(component);
  verify(node, never()).setMeasureFunction((YogaMeasureFunction) any());
}
 
Example #11
Source File: ComponentLifecycleTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateLayoutAndDontResolveNestedTreeWithMountSpecCanMeasure() {
  Component component =
      setUpSpyComponentForCreateLayout(true /* isMountSpec */, true /* canMeasure */);
  InternalNode node = Layout.create(mContext, component, false);

  verify(node).appendComponent(component);
  verify(node).setMeasureFunction((YogaMeasureFunction) any());
  verify(component).onPrepare(mContext);
}
 
Example #12
Source File: ComponentLifecycleTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateLayoutAndResolveNestedTreeWithMountSpecCanMeasure() {
  Component component =
      setUpSpyComponentForCreateLayout(true /* isMountSpec */, true /* canMeasure */);
  InternalNode node = Layout.create(mContext, component, true);

  verify(node).appendComponent(component);
  verify(node).setMeasureFunction((YogaMeasureFunction) any());
  verify(component).onPrepare(mContext);
}
 
Example #13
Source File: ComponentLifecycleTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateLayoutAndDontResolveNestedTreeWithMountSpecCannotMeasure() {
  Component component =
      setUpSpyComponentForCreateLayout(true /* isMountSpec */, false /* canMeasure */);
  InternalNode node = Layout.create(mContext, component, false);

  verify(node).appendComponent(component);
  verify(node, never()).setMeasureFunction((YogaMeasureFunction) any());
  verify(component).onPrepare(mContext);
}
 
Example #14
Source File: ComponentLifecycleTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateLayoutAndResolveNestedTreeWithMountSpecCannotMeasure() {
  Component component =
      setUpSpyComponentForCreateLayout(true /* isMountSpec */, false /* canMeasure */);
  InternalNode node = Layout.create(mContext, component, true);

  verify(node).appendComponent(component);
  verify(node, never()).setMeasureFunction((YogaMeasureFunction) any());
  verify(component).onPrepare(mContext);
}
 
Example #15
Source File: ReactShadowNodeImpl.java    From react-native-GPay with MIT License 4 votes vote down vote up
@Override
public void setMeasureFunction(YogaMeasureFunction measureFunction) {
  assertNotSealed();
  mYogaNode.setMeasureFunction(measureFunction);
}
 
Example #16
Source File: DefaultInternalNode.java    From litho with Apache License 2.0 4 votes vote down vote up
@Override
public void setMeasureFunction(YogaMeasureFunction measureFunction) {
  mYogaNode.setMeasureFunction(measureFunction);
}
 
Example #17
Source File: NoOpInternalNode.java    From litho with Apache License 2.0 4 votes vote down vote up
@Override
public void setMeasureFunction(YogaMeasureFunction measureFunction) {}
 
Example #18
Source File: ComponentLifecycleTest.java    From litho with Apache License 2.0 4 votes vote down vote up
private YogaMeasureFunction getMeasureFunction(Component component) {
  when(mNode.getTailComponent()).thenReturn(component);

  return Whitebox.getInternalState(ComponentLifecycle.class, "sMeasureFunction");
}
 
Example #19
Source File: InternalNode.java    From litho with Apache License 2.0 votes vote down vote up
void setMeasureFunction(YogaMeasureFunction measureFunction); 
Example #20
Source File: ReactShadowNode.java    From react-native-GPay with MIT License votes vote down vote up
void setMeasureFunction(YogaMeasureFunction measureFunction);