Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Child nodes shrink when parent node move across an axis #683

Open
1 task done
jmaurice-unity opened this issue Dec 9, 2017 · 5 comments
Open
1 task done

Child nodes shrink when parent node move across an axis #683

jmaurice-unity opened this issue Dec 9, 2017 · 5 comments
Assignees

Comments

@jmaurice-unity
Copy link

jmaurice-unity commented Dec 9, 2017

Report

Issues and Steps to Reproduce

Child nodes get smaller and smaller on every layout calculation when the parent node is moving across an axis or positioned along the axis.

shrink

The 2 test cases below reproduce the issue, notice that when the tests fail the leaf node is smaller by 10.

TEST(YogaTest, leaf_node_width_shrink_on_axis)
{
  const YGConfigRef config = YGConfigNew();

  const YGNodeRef root = YGNodeNewWithConfig(config);
  const YGNodeRef top = YGNodeNewWithConfig(config);
  // Happen with absolute position as well
  //YGNodeStyleSetPositionType(top, YGPositionTypeAbsolute);

  const YGNodeRef mid = YGNodeNewWithConfig(config);

  const YGNodeRef leaf = YGNodeNewWithConfig(config);
  YGNodeStyleSetWidth(leaf, 100);
  YGNodeStyleSetHeight(leaf, 100);

  YGNodeInsertChild(mid, leaf, 0);
  YGNodeInsertChild(top, mid, 0);
  YGNodeInsertChild(root, top, 0);

  YGNodeStyleSetPosition(top, YGEdgeLeft, 5);
  YGNodeStyleSetPosition(top, YGEdgeTop, 5);

  YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

  for (int i = 0; i < 100; i++)
  {
    float pos = YGNodeLayoutGetLeft(top);
    // Moving top container by float values > 1.5 and < 2.0 will eventually shrink the child node!
    // Everything seems fine when moving by integer or values that are rounded downward.
    // The shrink start when the top node x position gets negative.
    float newPos = pos - 1.75f;
    YGNodeStyleSetPosition(top, YGEdgeLeft, newPos);
    YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

    // This will eventually get smaller and smaller.
    // The shrinking of the leaf stop when the top node has crossed the y axis completely
    ASSERT_GT(YGNodeLayoutGetWidth(leaf), 90);
  }

  YGNodeFreeRecursive(root);

  YGConfigFree(config);
}

// Same test as above but moving along the y axis
TEST(YogaTest, leaf_node_height_shrink_on_axis)
{
  const YGConfigRef config = YGConfigNew();

  const YGNodeRef root = YGNodeNewWithConfig(config);
  const YGNodeRef top = YGNodeNewWithConfig(config);
  const YGNodeRef mid = YGNodeNewWithConfig(config);

  const YGNodeRef leaf = YGNodeNewWithConfig(config);
  YGNodeStyleSetWidth(leaf, 100);
  YGNodeStyleSetHeight(leaf, 100);

  YGNodeInsertChild(mid, leaf, 0);
  YGNodeInsertChild(top, mid, 0);
  YGNodeInsertChild(root, top, 0);

  YGNodeStyleSetPosition(top, YGEdgeLeft, 5);
  YGNodeStyleSetPosition(top, YGEdgeTop, 5);

  YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

  for (int i = 0; i < 100; i++)
  {
    float pos = YGNodeLayoutGetTop(top);
    float newPos = pos - 1.8f;
    YGNodeStyleSetPosition(top, YGEdgeTop, newPos);
    YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

    ASSERT_GT(YGNodeLayoutGetHeight(leaf), 90);
  }

  YGNodeFreeRecursive(root);

  YGConfigFree(config);
}

Expected Behavior

The width and height of the child node do not change when moving the top parent node.

Actual Behavior

Child nodes keep shrinking until they don't have any width and/or height.

@jmaurice-unity
Copy link
Author

Created pull request here : #688

@lunarraid
Copy link

This is still causing major headaches for me, and the fix looks really simple. Is there any update on when this can be resolved?

@pvinis
Copy link

pvinis commented Dec 28, 2018

it's causing problems in react native too.

@emilsjolander
Copy link
Contributor

@davidaurelio This seems to be an issue with how Yoga performs rounding. cc @shergin who implemented most of the current rounding functionality.

@davidaurelio davidaurelio self-assigned this Jan 28, 2019
@davidaurelio
Copy link
Contributor

I will look into it

facebook-github-bot pushed a commit to facebook/react-native that referenced this issue Feb 2, 2023
Summary:
This fix issue facebook/yoga#683 the rounding calculation is incorrect if a node is crossing an axis and it will shrink it's width/height on layout calculation.

The following test reproduce the issue :

```
TEST(YogaTest, node_shrink_on_axis)
{
  const YGConfigRef config = YGConfigNew();
  const YGNodeRef root = YGNodeNewWithConfig(config);
  const YGNodeRef child = YGNodeNewWithConfig(config);

  YGNodeInsertChild(root, child, 0);

  YGNodeStyleSetWidth(child, 10);
  YGNodeStyleSetHeight(child, 10);
  YGNodeStyleSetPosition(root, YGEdgeLeft, -0.75f);
  YGNodeStyleSetPosition(root, YGEdgeTop, -0.75f);

  YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

  ASSERT_FLOAT_EQ(YGNodeLayoutGetWidth(child), 10);
  ASSERT_FLOAT_EQ(YGNodeLayoutGetHeight(child), 10);

  YGNodeFreeRecursive(root);

  YGConfigFree(config);
}
```

X-link: facebook/yoga#688

Reviewed By: NickGerleman

Differential Revision: D13866122

Pulled By: rozele

fbshipit-source-id: 4faf8a9efc86723c303f600d730660a2e13d8a73
facebook-github-bot pushed a commit that referenced this issue Feb 2, 2023
Summary:
This fix issue #683 the rounding calculation is incorrect if a node is crossing an axis and it will shrink it's width/height on layout calculation.

The following test reproduce the issue :

```
TEST(YogaTest, node_shrink_on_axis)
{
  const YGConfigRef config = YGConfigNew();
  const YGNodeRef root = YGNodeNewWithConfig(config);
  const YGNodeRef child = YGNodeNewWithConfig(config);

  YGNodeInsertChild(root, child, 0);

  YGNodeStyleSetWidth(child, 10);
  YGNodeStyleSetHeight(child, 10);
  YGNodeStyleSetPosition(root, YGEdgeLeft, -0.75f);
  YGNodeStyleSetPosition(root, YGEdgeTop, -0.75f);

  YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

  ASSERT_FLOAT_EQ(YGNodeLayoutGetWidth(child), 10);
  ASSERT_FLOAT_EQ(YGNodeLayoutGetHeight(child), 10);

  YGNodeFreeRecursive(root);

  YGConfigFree(config);
}
```

Pull Request resolved: #688

Reviewed By: NickGerleman

Differential Revision: D13866122

Pulled By: rozele

fbshipit-source-id: 4faf8a9efc86723c303f600d730660a2e13d8a73
facebook-github-bot pushed a commit to facebook/litho that referenced this issue Feb 2, 2023
Summary:
This fix issue facebook/yoga#683 the rounding calculation is incorrect if a node is crossing an axis and it will shrink it's width/height on layout calculation.

The following test reproduce the issue :

```
TEST(YogaTest, node_shrink_on_axis)
{
  const YGConfigRef config = YGConfigNew();
  const YGNodeRef root = YGNodeNewWithConfig(config);
  const YGNodeRef child = YGNodeNewWithConfig(config);

  YGNodeInsertChild(root, child, 0);

  YGNodeStyleSetWidth(child, 10);
  YGNodeStyleSetHeight(child, 10);
  YGNodeStyleSetPosition(root, YGEdgeLeft, -0.75f);
  YGNodeStyleSetPosition(root, YGEdgeTop, -0.75f);

  YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

  ASSERT_FLOAT_EQ(YGNodeLayoutGetWidth(child), 10);
  ASSERT_FLOAT_EQ(YGNodeLayoutGetHeight(child), 10);

  YGNodeFreeRecursive(root);

  YGConfigFree(config);
}
```

X-link: facebook/yoga#688

Reviewed By: NickGerleman

Differential Revision: D13866122

Pulled By: rozele

fbshipit-source-id: 4faf8a9efc86723c303f600d730660a2e13d8a73
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this issue May 22, 2023
)

Summary:
This fix issue facebook/yoga#683 the rounding calculation is incorrect if a node is crossing an axis and it will shrink it's width/height on layout calculation.

The following test reproduce the issue :

```
TEST(YogaTest, node_shrink_on_axis)
{
  const YGConfigRef config = YGConfigNew();
  const YGNodeRef root = YGNodeNewWithConfig(config);
  const YGNodeRef child = YGNodeNewWithConfig(config);

  YGNodeInsertChild(root, child, 0);

  YGNodeStyleSetWidth(child, 10);
  YGNodeStyleSetHeight(child, 10);
  YGNodeStyleSetPosition(root, YGEdgeLeft, -0.75f);
  YGNodeStyleSetPosition(root, YGEdgeTop, -0.75f);

  YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

  ASSERT_FLOAT_EQ(YGNodeLayoutGetWidth(child), 10);
  ASSERT_FLOAT_EQ(YGNodeLayoutGetHeight(child), 10);

  YGNodeFreeRecursive(root);

  YGConfigFree(config);
}
```

X-link: facebook/yoga#688

Reviewed By: NickGerleman

Differential Revision: D13866122

Pulled By: rozele

fbshipit-source-id: 4faf8a9efc86723c303f600d730660a2e13d8a73
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants