Skip to content

Fixed Label Visibility Issue on macOS and iOS #28081

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

Merged
merged 5 commits into from
Mar 18, 2025

Conversation

Dhivya-SF4094
Copy link
Contributor

@Dhivya-SF4094 Dhivya-SF4094 commented Feb 27, 2025

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

  • Android
  • Windows
  • iOS
  • Mac

Issues Fixed:

Fixes #19007
Fixes #28180

Screenshots

iOS

Before After
   

macOS

Before  After 
   

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Feb 27, 2025
Copy link
Contributor

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.

@dotnet-policy-service dotnet-policy-service bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Feb 27, 2025
@jsuarezruiz jsuarezruiz changed the title Fix 19007 Fix Visibility Issues Feb 27, 2025
@Dhivya-SF4094 Dhivya-SF4094 changed the title Fix Visibility Issues Fix Label Visibility Issue on macOS and iOS Feb 28, 2025
@Dhivya-SF4094 Dhivya-SF4094 changed the title Fix Label Visibility Issue on macOS and iOS Fixed Label Visibility Issue on macOS and iOS Feb 28, 2025
@Dhivya-SF4094 Dhivya-SF4094 marked this pull request as ready for review February 28, 2025 11:50
@Copilot Copilot AI review requested due to automatic review settings February 28, 2025 11:50
@Dhivya-SF4094 Dhivya-SF4094 requested a review from a team as a code owner February 28, 2025 11:50
Copy link
Contributor

@Copilot Copilot AI left a 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.

Comment on lines +72 to +73
var adjustedWidth = size.Width - TextInsets.Left - TextInsets.Right;
var adjustedHeight = size.Height - TextInsets.Top - TextInsets.Bottom;
Copy link
Preview

Copilot AI Feb 28, 2025

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.

Suggested change
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.

@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MartyIX Converted the shared file to file-scope namespace as per #28040

@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen PureWeen changed the base branch from main to inflight/current March 18, 2025 18:21
@PureWeen PureWeen merged commit 041e041 into dotnet:inflight/current Mar 18, 2025
122 of 129 checks passed
anandhan-rajagopal pushed a commit to anandhan-rajagopal/maui that referenced this pull request Mar 26, 2025
* Fixed Label Display on macOS and IOS When Padding is Applied

* Optimized the fix

* Added test case

* Added Snapshot for android and iOS

* Added snapshot for winUI and macOS, updated test sample
anandhan-rajagopal pushed a commit to anandhan-rajagopal/maui that referenced this pull request Mar 26, 2025
* Fixed Label Display on macOS and IOS When Padding is Applied

* Optimized the fix

* Added test case

* Added Snapshot for android and iOS

* Added snapshot for winUI and macOS, updated test sample
PureWeen pushed a commit that referenced this pull request Mar 26, 2025
* Fixed Label Display on macOS and IOS When Padding is Applied

* Optimized the fix

* Added test case

* Added Snapshot for android and iOS

* Added snapshot for winUI and macOS, updated test sample
PureWeen pushed a commit that referenced this pull request Mar 26, 2025
* Fixed Label Display on macOS and IOS When Padding is Applied

* Optimized the fix

* Added test case

* Added Snapshot for android and iOS

* Added snapshot for winUI and macOS, updated test sample
github-actions bot pushed a commit that referenced this pull request Mar 27, 2025
* Fixed Label Display on macOS and IOS When Padding is Applied

* Optimized the fix

* Added test case

* Added Snapshot for android and iOS

* Added snapshot for winUI and macOS, updated test sample
bhavanesh2001 added a commit to bhavanesh2001/maui that referenced this pull request Apr 11, 2025
bhavanesh2001 added a commit to bhavanesh2001/maui that referenced this pull request Apr 11, 2025
bhavanesh2001 added a commit to bhavanesh2001/maui that referenced this pull request Apr 11, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Apr 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/iOS 🍎 platform/macOS 🍏 macOS / Mac Catalyst
Projects
None yet
5 participants