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

[iOS] Fix Label Truncation on iOS with HorizontalOptions #14453

Merged
merged 13 commits into from
May 8, 2023

Conversation

tj-devel709
Copy link
Member

@tj-devel709 tj-devel709 commented Apr 7, 2023

Description of Change

Thank you @kunyli for uncovering that the issue of the label not staying inside the parent and not truncating properly happens when the HorizontalOption is set!

It turns out that when we have a label in iOS, it computes the desiredWidth using UIView's SizeThatFits(). This returns the full width of the label (even if it is longer than the parent view). In LayoutExtensions, it checks if the view.HorizontalLayoutAlignment == LayoutAlignment.Fill and if so, will use the width of the parent view. It is also worth noting that the default HorizontalOption value is fill.

Therefore, when we set the HorizontalOption to anything other than fill, it does not hit this check and will set the frame based on the entire desired width of the label. Also when the label has it's longer desired width, there was no need for truncating.

The fix in this PR is to use the parent container view's width when the desired width from the label is larger.

Below are the examples from the two issues with the changes in this PR:

image

image

Issues Fixed

Fixes #9084
Fixes #14368

@tj-devel709 tj-devel709 added platform/iOS 🍎 legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor area-controls-label Label, Span labels Apr 7, 2023
@github-actions
Copy link
Contributor

github-actions bot commented May 3, 2023

Thank you for your pull request. We are auto-formatting your source code to follow our code guidelines.

@github-actions
Copy link
Contributor

github-actions bot commented May 5, 2023

Thank you for your pull request. We are auto-formatting your source code to follow our code guidelines.

@tj-devel709 tj-devel709 enabled auto-merge (squash) May 8, 2023 13:55
@tj-devel709 tj-devel709 disabled auto-merge May 8, 2023 13:56
@PureWeen PureWeen merged commit 6bbf93e into dotnet:main May 8, 2023
@LanceMcCarthy
Copy link

Good stuff!

AwesomeReactionGIF

rmarinho pushed a commit that referenced this pull request May 30, 2023
* initial fix

* Add tests

* round test asserts for android

* add conditional for no wrap and add more tests

* Adjust tests for android

* do not run on windows for now

* Add changes to work on Windows

* limit the labels text to the parent container width and adjust tests

* Auto-format source code

* also add a height restriction

* Auto-format source code

---------

Co-authored-by: tj-devel709 <tjlambert@microsoft.com>
Co-authored-by: GitHub Actions Autoformatter <autoformat@example.com>
@borrmann
Copy link
Contributor

borrmann commented Jul 1, 2023

Maybe something similar happens in #14411 ?

@github-actions github-actions bot locked and limited conversation to collaborators Dec 12, 2023
@Eilon Eilon removed the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label May 10, 2024
@samhouts samhouts added the fixed-in-8.0.0-preview.5.8529 Look for this fix in 8.0.0-preview.5.8529! label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-label Label, Span fixed-in-8.0.0-preview.5.8529 Look for this fix in 8.0.0-preview.5.8529! platform/iOS 🍎
Projects
None yet
9 participants