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

Reduce the number of measure calls for children of Flexbox #514

Merged
merged 5 commits into from
Oct 31, 2019
Merged

Conversation

thagikura
Copy link
Contributor

@thagikura thagikura commented Oct 24, 2019

This PR reduces the number of measure calls for the children of the
Flexbox.
If any items in a FlexLine don't have the flexGrow or flexShrink
attributes set, the children in the FlexLine don't have to be measured
in the FlexboxHelper#determineMainSize method.

Similarly, if the AlignItems attribute for the Flexbox is not equal to
AlignItems.STRETCH nor any items in a FlexLine don't have the
AlignSelf.STRETCH attributes, the items in the FlexLine don't have to be
measured in the FlexboxHelpers#stretchViews method.

Also this PR changes the default values of FlexboxLayout as follows:

  • mAlignItems: STRETCH -> FLEX_START
  • mAlignContent: STRETCH -> FLEX_START

Fixes #46

This PR prevents the number of measure calls for the children of the
Flexbox.
If any items in a FlexLine don't have the flexGrow or flexShrink
attributes set, the children in the FlexLine don't have to be measured
in the FlexboxHelper#determineMainSize method.

Similarly, if the AlignItems attribute for the Flexbox is not equal to
AlignItems.STRETCH nor any items in a FlexLine don't have the
AlignSelf.STRETCH attributes, the items in the FlexLine don't have to be
measured in the FlexboxHelpers#stretchViews method.

Also this PR changes the default values of FlexboxLayout as follows:
- mAlignItems: STRETCH -> FLEX_START
- mAlignContent: STRETCH -> FLEX_START
@thagikura thagikura changed the title WIP: Attempt to fix #46 Reduce the number of measure calls for children of Flexbox Oct 28, 2019
If the temporary calculated line length is less than the length of the
main axis, the calculation isn't needed.
@thagikura thagikura requested a review from yaraki October 30, 2019 10:09
@@ -223,8 +223,8 @@ public FlexboxLayout(Context context, AttributeSet attrs, int defStyleAttr) {
mFlexWrap = a.getInt(R.styleable.FlexboxLayout_flexWrap, FlexWrap.NOWRAP);
mJustifyContent = a
.getInt(R.styleable.FlexboxLayout_justifyContent, JustifyContent.FLEX_START);
mAlignItems = a.getInt(R.styleable.FlexboxLayout_alignItems, AlignItems.STRETCH);
mAlignContent = a.getInt(R.styleable.FlexboxLayout_alignContent, AlignContent.STRETCH);
mAlignItems = a.getInt(R.styleable.FlexboxLayout_alignItems, AlignItems.FLEX_START);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this break existing apps? Should we bump up the major version if so?

Copy link
Contributor Author

@thagikura thagikura Oct 31, 2019

Choose a reason for hiding this comment

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

Yes, it may break the existing apps and we should bump the major version once we release it.
I think it's better in the long run because setting the AlignItems.STRETCH is expensive like setting the weight attribute in LinearLayout especially FlexboxLayout is nested more than several levels.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see. It makes sense.

@agentcooper
Copy link

Can you please mention the changes to default values in Known differences from the original CSS specification in README?

@thagikura
Copy link
Contributor Author

thagikura commented Nov 13, 2019 via email

@thagikura thagikura deleted the nested branch January 4, 2020 05:29
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 this pull request may close these issues.

Avoid duplicate measurements for children
3 participants