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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue27614.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 27614, "Label not sized correctly on Android", PlatformAffected.Android)]
public class Issue27614 : ContentPage
{
public Issue27614()
{

var singleLineLabel = new Label
{
HorizontalOptions = LayoutOptions.Start,
AutomationId = "Label",
Margin = new Thickness(5, 5),
Text = "Hello World",
BackgroundColor = Colors.Blue,
TextColor = Colors.Black,
FontSize = 20
};

var multiLineLabel = new Label
{
HorizontalOptions = LayoutOptions.Start,
Margin = new Thickness(5, 5),
Text = "NET MAUI is a framework used to build native, cross-platform desktop and mobile apps from a single C# codebase for Android, iOS, Mac, and Windows",
BackgroundColor = Colors.Orchid,
TextColor = Colors.Black,
FontSize = 20
};

var button = new Button
{
Text = "Change Label HorizontalOptions to Center",
AutomationId = "CenterButton",
Margin = new Thickness(5, 5)

};
button.Clicked += (s, e) =>
{
singleLineLabel.HorizontalOptions = LayoutOptions.Center;
multiLineLabel.HorizontalOptions = LayoutOptions.Center;
};
var button1 = new Button
{
Text = "Change Label HorizontalOptions to End",
AutomationId = "EndButton",
Margin = new Thickness(5, 5)
};
button1.Clicked += (s, e) =>
{
singleLineLabel.HorizontalOptions = LayoutOptions.End;
multiLineLabel.HorizontalOptions = LayoutOptions.End;
};
var layout = new VerticalStackLayout
{
Children = { singleLineLabel, multiLineLabel, button, button1 }
};

Content = layout;
}
}
}
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.
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,41 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue27614 : _IssuesUITest
{
public Issue27614(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "Label not sized correctly on Android";

[Test, Order(1)]
[Category(UITestCategories.Label)]
public void LabelShouldSizeCorrectlyOnHorizontalStartLayoutOptions()
{
App.WaitForElement("Label");
VerifyScreenshot();
}

[Test, Order(2)]
[Category(UITestCategories.Label)]
public void LabelShouldSizeCorrectlyOnHorizontalCenterLayoutOptions()
{
App.WaitForElement("CenterButton");
App.Tap("CenterButton");
VerifyScreenshot();
}

[Test, Order(3)]
[Category(UITestCategories.Label)]
public void LabelShouldSizeCorrectlyOnHorizontalEndLayoutOptions()
{
App.WaitForElement("EndButton");
App.Tap("EndButton");
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.
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.
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.
22 changes: 22 additions & 0 deletions src/Core/src/Platform/Android/MauiTextView.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using Android.Content;
using AndroidX.AppCompat.Widget;
using Android.Text;
using Android.Views;

namespace Microsoft.Maui.Platform
{
Expand All @@ -16,6 +18,26 @@ internal override void OnLayoutFormatted(bool changed, int l, int t, int r, int
{
LayoutChanged?.Invoke(this, new LayoutChangedEventArgs(l, t, r, b));
}
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);
}
base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
}

static float GetMaxLineWidth(Layout layout)
{
float maxWidth = 0;
//Calculates the maximum width needed to display the content based on the widest line."
for (int i = 0, count = layout.LineCount; i < count; i++)
{
maxWidth = Math.Max(maxWidth, layout.GetLineWidth(i));
}
return maxWidth;
}
}

public class LayoutChangedEventArgs : EventArgs
Expand Down
3 changes: 2 additions & 1 deletion src/Core/src/PublicAPI/net-android/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,5 @@ virtual Microsoft.Maui.PlatformContentViewGroup.SetHasClip(bool hasClip) -> void
override Microsoft.Maui.PlatformWrapperView.OnLayout(bool changed, int left, int top, int right, int bottom) -> void
virtual Microsoft.Maui.PlatformWrapperView.DrawShadow(Android.Graphics.Canvas! canvas, int viewWidth, int viewHeight) -> void
*REMOVED*~override Microsoft.Maui.Platform.WrapperView.DrawShadow(Android.Graphics.Canvas canvas, int viewWidth, int viewHeight) -> void
*REMOVED*abstract Microsoft.Maui.PlatformWrapperView.DrawShadow(Android.Graphics.Canvas! p0, int p1, int p2) -> void
*REMOVED*abstract Microsoft.Maui.PlatformWrapperView.DrawShadow(Android.Graphics.Canvas! p0, int p1, int p2) -> void
override Microsoft.Maui.Platform.MauiTextView.OnMeasure(int widthMeasureSpec, int heightMeasureSpec) -> void
Loading