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

Change flex getters to return the set values #431

Closed
wants to merge 4 commits into from

Conversation

woehrl01
Copy link
Contributor

Changed the flex getters to return the values they were actually set. See #421 .

Copy link
Contributor

@emilsjolander emilsjolander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small things. Otherwise looks good. Thanks!

ASSERT_FLOAT_EQ(0, YGNodeStyleGetFlexGrow(root));
ASSERT_FLOAT_EQ(0, YGNodeStyleGetFlexShrink(root));
ASSERT_FALSE(YGNodeStyleGetFlexBasis(root).unit != YGUnitAuto);
ASSERT_TRUE(YGFloatIsUndefined(YGNodeStyleGetFlexGrow(root)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these should still return 0 (their current default) if nothing has been set.

Copy link
Contributor Author

@woehrl01 woehrl01 Feb 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently our internal default is Undefined and we use that value inside YGResolveFlexGrow to check if explicitly set. What do you think how we should use that with the flex shorthand? Should we use flex to set the flexGrow directly. But so we loose the previous set values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As flex

is a shorthand for the flex-grow, flex-shrink, and the flex-basis properties.

maybe we should explictily set flex-grow, flex-shrink if we call it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative is, to return 0 for these values in a (custom) getter, and keep the undefined as an internal implementation detail?

yoga/Yoga.c Outdated
YG_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexGrow, flexGrow, flexGrow);
YG_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexShrink, flexShrink, flexShrink);
YG_NODE_STYLE_PROPERTY_SETTER_UNIT_AUTO_IMPL(float, FlexBasis, flexBasis, flexBasis);
YG_NODE_STYLE_PROPERTY_IMPL(float, FlexGrow, flexGrow, flexGrow);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a YG_NODE_STYLE_PROPERTY_IMPL for the Flex shorthand?

@emilsjolander
Copy link
Contributor

👍

@facebook-github-bot
Copy link
Contributor

@emilsjolander has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@astreet astreet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

yoga/Yoga.c Outdated
@@ -423,7 +423,15 @@ inline float YGNodeStyleGetFlexGrow(const YGNodeRef node) {
return 0.0f;
}

inline float YGNodeStyleGetFlexShrink(const YGNodeRef node) {
float YGNodeStyleGetFlexGrow(const YGNodeRef node) {
return YGFloatIsUndefined(node->style.flexGrow) ? 0.0f : node->style.flexGrow;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of 0.0f, can we have the reference the defaults instead for clarity and to not introduce bugs?

@woehrl01
Copy link
Contributor Author

We don't really have a default constant here. But this return value is at least covered by the default tests.

@emilsjolander
Copy link
Contributor

@astreet Right, I forgot about this. The value encoded in the default struct (gYGNodeDefaults) is YGUndefined as it is resolved later using the flex shorthand.

@emilsjolander
Copy link
Contributor

@woehrl01 Can you pull out 0.0f into constants kDefaultFlexGrow and kDefaultFlexShrink ? then use these in both the style getter and the resolve function? I think that would make it clearer what the zero is referencing.

@woehrl01
Copy link
Contributor Author

Sounds like a great idea 💡 will do!

@woehrl01 woehrl01 changed the title Change flex getters return the setted values Change flex getters return the set values Feb 23, 2017
@woehrl01 woehrl01 changed the title Change flex getters return the set values Change flex getters to return the set values Feb 23, 2017
@facebook-github-bot
Copy link
Contributor

@emilsjolander has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Feb 28, 2017
Summary:
Changed the flex getters to return the values they were actually set. See #421 .
Closes facebook/yoga#431

Reviewed By: astreet

Differential Revision: D4604744

Pulled By: emilsjolander

fbshipit-source-id: 02d79100ef22be866db1c3bd9d53e4447186811f
dudeinthemirror pushed a commit to dudeinthemirror/react-native that referenced this pull request Mar 1, 2017
Summary:
Changed the flex getters to return the values they were actually set. See facebook#421 .
Closes facebook/yoga#431

Reviewed By: astreet

Differential Revision: D4604744

Pulled By: emilsjolander

fbshipit-source-id: 02d79100ef22be866db1c3bd9d53e4447186811f
dudeinthemirror pushed a commit to dudeinthemirror/react-native that referenced this pull request Mar 1, 2017
Summary:
Changed the flex getters to return the values they were actually set. See facebook#421 .
Closes facebook/yoga#431

Reviewed By: astreet

Differential Revision: D4604744

Pulled By: emilsjolander

fbshipit-source-id: 02d79100ef22be866db1c3bd9d53e4447186811f
vincentriemer pushed a commit to vincentriemer/yoga-dom that referenced this pull request May 9, 2018
Summary:
Changed the flex getters to return the values they were actually set. See #421 .
Closes facebook/yoga#431

Reviewed By: astreet

Differential Revision: D4604744

Pulled By: emilsjolander

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

Successfully merging this pull request may close these issues.

4 participants