Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue29194.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 29194, "[Android][Label] Setting a Label visible after having had focus on a InputView will increase the Label's height", PlatformAffected.Android)]
public class Issue29194 : ContentPage
{
public Issue29194()
{
var mySwitch = new Switch() { AutomationId = "Switch" };

var label = new Label
{
Text = "Hello, World!",
BackgroundColor = Colors.Red,
AutomationId = "Label"
};

label.SetBinding(Label.IsVisibleProperty, new Binding(nameof(Switch.IsToggled), source: mySwitch));

var verticalStack = new VerticalStackLayout
{
Children =
{
label,
mySwitch,
new UITestEntry() {AutomationId = "Entry",IsCursorVisible=false},
}
};

var scrollView = new ScrollView
{
Content = verticalStack
};

Content = scrollView;

}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;
public class Issue29194 : _IssuesUITest
{
public Issue29194(TestDevice device) : base(device) { }

public override string Issue => "[Android][Label] Setting a Label visible after having had focus on a InputView will increase the Label's height";

[Test]
[Category(UITestCategories.Label)]
public void LabelShouldSizeProperly()
{
App.WaitForElement("Entry");
App.Tap("Entry");
App.Tap("Switch");
App.WaitForElement("Label");
App.DismissKeyboard();
VerifyScreenshot();
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 13 additions & 2 deletions src/Core/src/Platform/Android/MauiTextView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,19 @@ protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
if (MeasureSpec.GetMode(widthMeasureSpec) == MeasureSpecMode.AtMost && Layout is not null)
{
int maxWidth = (int)Math.Ceiling(GetMaxLineWidth(Layout)) + CompoundPaddingLeft + CompoundPaddingRight;
widthMeasureSpec = MeasureSpec.MakeMeasureSpec(maxWidth, MeasureSpecMode.AtMost);
// Ensure the Layout is valid and measured before reading LineCount or GetLineWidth(i) to avoid unnecessary calculations.
if (Layout.Width > 0)
{
// 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);
}
}
base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
}
Expand Down
Loading