-
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
Fixed Label Visibility Issue on macOS and iOS #28081
base: main
Are you sure you want to change the base?
Conversation
Hey there @Dhivya-SF4094! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
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.
PR Overview
This PR addresses the incomplete label display on macOS and iOS when padding is applied by adjusting the size passed to SizeThatFits.
- Adjust the width and height by subtracting padding values before calculating text size, then add the insets back with AddInsets.
- Add test cases in both TestCases.Shared.Tests and TestCases.HostApp to validate the fix.
Reviewed Changes
File | Description |
---|---|
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue19007.cs | Added UI test for label with padding. |
src/Controls/tests/TestCases.HostApp/Issues/Issue19007.cs | Implemented sample page with padded label. |
src/Core/src/Platform/iOS/MauiLabel.cs | Adjusted SizeThatFits to subtract padding before size calculation. |
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
var adjustedWidth = size.Width - TextInsets.Left - TextInsets.Right; | ||
var adjustedHeight = size.Height - TextInsets.Top - TextInsets.Bottom; |
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.
Consider clamping the adjusted width (and similarly the adjusted height on line 73) to a minimum value (e.g., 0) to avoid negative dimensions when the combined padding exceeds the provided size.
var adjustedWidth = size.Width - TextInsets.Left - TextInsets.Right; | |
var adjustedHeight = size.Height - TextInsets.Top - TextInsets.Bottom; | |
var adjustedWidth = Math.Max(0, size.Width - TextInsets.Left - TextInsets.Right); | |
var adjustedHeight = Math.Max(0, size.Height - TextInsets.Top - TextInsets.Bottom); |
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
using UITest.Appium; | ||
using UITest.Core; | ||
|
||
namespace Microsoft.Maui.TestCases.Tests.Issues |
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.
Super-nit: After #28040, you can convert this to file-scope namespace by CTRL+. in Visual Studio (I believe it's the same in VS Code).
If it is converted, then new files will use file-scope namespaces more and more as people IMO copy old files to create new code.
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.
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
Issue Details:
In macOS and iOS, a visibility issue arises when a label fails to display fully when padding is applied to it. The label is completely visible when the padding is removed.
Root Cause
When a direct size value is passed to the SizeThatFits() method, it incorrectly assumes that the label has adequate width to accommodate the text, without accounting for the padding. As a result, the height calculation becomes inaccurate.
Description of Change
To resolve this, the padding value should be subtracted from the width before passing it to SizeThatFits(). This adjustment ensures the width is correctly calculated, leading to an accurate height value. Then added the padding value back in the AddInsets method.
Validated the behaviour in the following platforms
Issues Fixed:
Fixes #19007
Screenshots
iOS
macOS