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

when a node is both stretch and auto, get the result with width and height "null" #644

Closed
Lizz0y opened this issue Oct 7, 2017 · 5 comments

Comments

@Lizz0y
Copy link

Lizz0y commented Oct 7, 2017

Report

when a node is both cross stretch and margin auto, get the result with width and height "null",i have read the source code and found the following code:

          if (alignItem == YGAlignStretch &&
              YGMarginLeadingValue(child, crossAxis)->unit != YGUnitAuto &&
              YGMarginTrailingValue(child, crossAxis)->unit != YGUnitAuto) {

can someone explain , since the alignItem is already stretch ,auto is meaningless, so why this code exclude the auto ?

@woehrl01
Copy link
Contributor

woehrl01 commented Oct 7, 2017

It excludes auto, as if you have a margin of auto, the node should not stretch. Margin is "stronger" than align-item. Thus the node is the size of its content, but it shouldn't be "null". Could you please provide a testcase where it fails, I'll take a look into it.

@Lizz0y
Copy link
Author

Lizz0y commented Oct 8, 2017

i write a node with "text" type ,since text has no width&height,so i set a custom measureFunction as:

 YogaNode root = new YogaNode();
 root.setWidth(500);
 root.setHeight(300);

        YogaNode text = new YogaNode();
        text.setMeasureFunction(new YogaMeasureFunction() {
            @Override
            public long measure(YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode) {
                return new YogaMeasureOutput().make(50,50);
            }
        });
       text.setMarginAuto(YogaEdge.LEFT);
        root.addChildAt(text, 0);

when i run this code ,find the text node return "null" for both height and width, please find what's wrong with it ,thx

@woehrl01
Copy link
Contributor

woehrl01 commented Oct 8, 2017

It should be a width and height of 50 and left 450 here. I'll reproduce and have a look.

@woehrl01
Copy link
Contributor

woehrl01 commented Oct 8, 2017

thank you for the hint @Lizz0y , I pushed a fix for this in #645

@Lizz0y
Copy link
Author

Lizz0y commented Oct 10, 2017

thx @woehrl01 for fix this problem

@Lizz0y Lizz0y closed this as completed Oct 11, 2017
facebook-github-bot pushed a commit that referenced this issue Nov 27, 2017
Summary:
If you have a measurable node and set ```marign-left: auto``` + ```align-item:stretch``` on it, it won't get measured and they get a width/height of ```-(nan)```. This change fixes that behaviour. Fixes #644.
Closes #645

Differential Revision: D6413512

Pulled By: emilsjolander

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

Successfully merging a pull request may close this issue.

2 participants