-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Flexline width exceeds container width #521
Flexline width exceeds container width #521
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
.../src/main/java/com/google/android/flexbox/apps/catgallery/perf/TextViewMeasurementBuilder.kt
Outdated
Show resolved
Hide resolved
@googlebot I signed it! |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
I updated the Gist to also include a Checkbox widget, because I noticed a different behavior happening in this case. In fact, when Checkbox is allowed to shrink (flexShrink = 1f), during the recalculation can end up being shrunk more than what I would consider its "minimum size" since the negative space is calculated for both the TextView and the Checkbox in the shrinkFlexItems() method. The image below shows the behavior explained above: I am trying to understand if there is a viable way to take scenarios like this one into account during measurement. In the case of Checkbox specifically, the widget has a ButtonDrawable that has a minimumWidth and minimumHeight and I am wondering if this information should be taken into account. At least on web, a widget like a checkbox does not seem to be shrinkable. A possible solution can be something like the snippet below where users can decide to use the buttonDrawable information into account in their custom Checkbox widgets, but I am not sure this is the best solution? Code
Result |
Thanks for the PR! Sorry for the delayed reply... Looks like the issue for the ButtonDrawable can be fixed in another PR. |
Hi @thagikura, thank you for reviewing the diff. I added a couple of tests to verify the fix. I agree we can address the ButtonDrawable in a separate PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
This "fix" broke my UI. Please don't publish breaking changes as fix versions in the future. |
Hi @Ribesg, sorry to hear this fix broke your UI. I had a problem with text rendering and based on the investigation in the Gist in the description, it looked like during onMeasure the Text widget were given the full-screen width even when they did not have it available. May I ask you if you can share more information about your scenario that got broken after this fix? Thank you in advance. |
In this PR I am trying to address an issue that occurs when the calculation of flexlines exceeds the permitted size of their container and some items can be shrunk.
After successfully calculating the number of flexline the FlexboxLayout proceeds its measurement by determining the main size through the determineMainSize() method. In certain situations, the width of some flexlines might be bigger than the size of their container. In this cases, we need to restrict their calculated width by retriggering a second layout calculation and enforcing their width as the one of their containers.
Before the change
The example below shows how the TextView width is calculated based on the full screen width causing its text to be cut out. In that specific case the total width of the flexline is: ImageView width (which has fixed size) + the TextView width (which is equals to the screen size). No re-measurement happens after the calculation of the number of flexlines since the main size calculated in the determineMainSize() is based on the widest flexline, which in this case exceeds the container width:
After the change
After changing the determineMainSize() method to disallow lines to be wider than their container, the flexlines are correctly recalculated and laid out. The pictures below show the same example with both a single ImageView or with two ImageView on the left and right of the TextView. The end results are showing a correctly recalculated layout:
This Gist contains the classes that have been used to reproduce the scenarios described above.