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

Fixed Label Visibility Issue on macOS and iOS #28081

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Dhivya-SF4094
Copy link
Contributor

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

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 bot 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.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/iOS 🍎 platform/macOS 🍏 macOS / Mac Catalyst
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Visibility Issues: Incomplete Label Display on macOS and IOS When Padding is Applied
3 participants