-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[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
Conversation
/azp run MAUI-UITests-public |
Azure Pipelines successfully started running 1 pipeline(s). |
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.
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. |
/azp run MAUI-UITests-public |
Azure Pipelines successfully started running 1 pipeline(s). |
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.
This test could potentially fail. Must use the UITestEntry
from the test controls and the IsCursorVisible
property to false.
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.
I modified the test sample to use UITestEntry
and set IsCursorVisible
to false to avoid cursor-related issues in the future. @jsuarezruiz
/azp run MAUI-UITests-public |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run MAUI-UITests-public |
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; |
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.
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);
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.
I have made the changes. Please let me know if you have any other concerns. @jsuarezruiz
/azp run MAUI-UITests-public |
Azure Pipelines successfully started running 1 pipeline(s). |
/backport to release/9.0.1xx-sr6 |
/azp run MAUI-DeviceTests-public |
Started backporting to release/9.0.1xx-sr6: https://github.com/dotnet/maui/actions/runs/14861756027 |
/azp run MAUI-public |
Azure Pipelines successfully started running 1 pipeline(s). |
1 similar comment
Azure Pipelines successfully started running 1 pipeline(s). |
…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
Root Cause of the issue
layout
is not fullyinitialized
.Description of Change
Layout.Width > 0
. This prevents width calculations during unstable layout transitions and ensures that measurements are only taken when the layout is in avalid state
.Regressed PR
Issues Fixed
Fixes #29194
Fixes #29287
Tested the behaviour in the following platforms
Screenshot
LabelIssueVideo.mov
LabelFixVideo.mov