Skip to content

[Android] Fixed Setting a Label visible after having had focus on a InputView will increase the Label's height #29210

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 7 commits into from
May 6, 2025

Conversation

Ahamed-Ali
Copy link
Contributor

@Ahamed-Ali Ahamed-Ali commented Apr 25, 2025

Root Cause of the issue

  • The layout measurements of the TextView may become unstable during initialization. As a result, the GetMaxLineWidth() method can return incorrect values because the layout is not fully initialized.

Description of Change

  • The fix introduces a validation check using Layout.Width > 0. This prevents width calculations during unstable layout transitions and ensures that measurements are only taken when the layout is in a valid state.

Regressed PR

Issues Fixed

Fixes #29194
Fixes #29287

Tested the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Screenshot

Before Issue Fix After Issue Fix
LabelIssueVideo.mov
LabelFixVideo.mov

@dotnet-policy-service dotnet-policy-service bot added community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration labels Apr 25, 2025
@sheiksyedm sheiksyedm added the area-controls-label Label, Span label Apr 25, 2025
@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Ahamed-Ali Ahamed-Ali marked this pull request as ready for review April 28, 2025 11:06
@Copilot Copilot AI review requested due to automatic review settings April 28, 2025 11:06
@Ahamed-Ali Ahamed-Ali requested a review from a team as a code owner April 28, 2025 11:06
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.

Pull Request Overview

This PR fixes an issue on Android where the label's height increases unexpectedly after an InputView receives focus and then becomes visible. The changes include adding a layout width check in the MauiTextView component and providing new test cases in both the shared tests and host app to ensure proper behavior.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

File Description
src/Core/src/Platform/Android/MauiTextView.cs Added a validation check (Layout.Width > 0) before recalculating width measurements.
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29194.cs Introduced a new NUnit test to automate verification of the label behavior.
src/Controls/tests/TestCases.HostApp/Issues/Issue29194.cs Added a host app test page to support the automated test for the issue fix.

@PureWeen
Copy link
Member

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@PureWeen PureWeen added this to the .NET 9 SR7 milestone Apr 28, 2025
@PureWeen PureWeen added the p/0 Work that we can't release without label Apr 28, 2025
Copy link
Contributor

Choose a reason for hiding this comment

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

This test could potentially fail. Must use the UITestEntry from the test controls and the IsCursorVisible property to false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I modified the test sample to use UITestEntry and set IsCursorVisible to false to avoid cursor-related issues in the future. @jsuarezruiz

@github-project-automation github-project-automation bot moved this from Todo to Changes Requested in MAUI SDK Ongoing Apr 30, 2025
@PureWeen
Copy link
Member

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

// Ensure the Layout is valid and measured before reading LineCount or GetLineWidth(i) to avoid unnecessary calculations.
if (Layout.Width > 0)
{
int maxWidth = (int)Math.Ceiling(GetMaxLineWidth(Layout)) + CompoundPaddingLeft + CompoundPaddingRight;
Copy link
Contributor

@jsuarezruiz jsuarezruiz May 2, 2025

Choose a reason for hiding this comment

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

Just split the maxWidth variable in more small steps for clarity and, could we ensure the desired width doesn't exceed the available width from the original spec? (use Math.Min).

// Calculate the total width needed based on text content plus padding
int contentWidth = (int)Math.Ceiling(GetMaxLineWidth(Layout));
int totalPadding = CompoundPaddingLeft + CompoundPaddingRight;
int requiredWidth = contentWidth + totalPadding;

// Constrain to maximum available width from original spec
int availableWidth = MeasureSpec.GetSize(widthMeasureSpec);
int desiredWidth = Math.Min(requiredWidth, availableWidth);

widthMeasureSpec = MeasureSpec.MakeMeasureSpec(desiredWidth, MeasureSpecMode.AtMost);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have made the changes. Please let me know if you have any other concerns. @jsuarezruiz

@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@PureWeen PureWeen requested a review from jsuarezruiz May 5, 2025 20:44
@github-project-automation github-project-automation bot moved this from Changes Requested to Approved in MAUI SDK Ongoing May 6, 2025
@PureWeen
Copy link
Member

PureWeen commented May 6, 2025

/backport to release/9.0.1xx-sr6

@PureWeen
Copy link
Member

PureWeen commented May 6, 2025

/azp run MAUI-DeviceTests-public

Copy link
Contributor

github-actions bot commented May 6, 2025

Started backporting to release/9.0.1xx-sr6: https://github.com/dotnet/maui/actions/runs/14861756027

@PureWeen
Copy link
Member

PureWeen commented May 6, 2025

/azp run MAUI-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

1 similar comment
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@PureWeen PureWeen merged commit 15b7beb into dotnet:main May 6, 2025
125 of 129 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in MAUI SDK Ongoing May 6, 2025
SuthiYuvaraj pushed a commit to SuthiYuvaraj/maui that referenced this pull request May 9, 2025
…nputView will increase the Label's height (dotnet#29210)

* Fixed the Label Measurement issue in Android

* Included the test sample and case

* Committed the fix changes and included the images

* Committed the test sample changes

* Android image added

* Updated the mac image

* Modified the review changes
@github-actions github-actions bot locked and limited conversation to collaborators Jun 6, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-label Label, Span community ✨ Community Contribution p/0 Work that we can't release without partner/syncfusion Issues / PR's with Syncfusion collaboration
Projects
Status: Done
4 participants