Skip to content

Revert - Fixed the Label not sized correctly on Android #30023

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 3 commits into from
Jun 19, 2025
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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: 0 additions & 61 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue27614.cs

This file was deleted.

124 changes: 124 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue29542.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 29542, "I1_Vertical_list_for_Multiple_Rows - Rotating the emulator would cause clipping on the description text.", PlatformAffected.Android)]
public class Issue29542 : ContentPage
{
public Issue29542()
{
var grid = new Grid
{
Margin = 20,
RowDefinitions =
{
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = GridLength.Star },

}
};

// Top text description
var headerLabel = new Label
{
Text = "1. The test passes if resizing or rotating without clipping or elements disappearing in multiple rows.",
};

var button = new Button
{
Text = "Scroll Down",
AutomationId = "ScrollToDownButton",
BackgroundColor = Colors.Red,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
};

var verticalHeaderLayout = new VerticalStackLayout()
{
Children =
{
headerLabel
},
};
Grid.SetRow(verticalHeaderLayout, 0);
Grid.SetRow(button, 1);
var items = new List<string>();
for (int i = 1; i <= 21; i++)
{
items.Add(i.ToString());
}
var myCollection = new CollectionView
{
AutomationId = "TestCollectionView",
ItemsSource = items,
ItemsLayout = new GridItemsLayout(1, ItemsLayoutOrientation.Vertical)
{
VerticalItemSpacing = 5
},
Header = new Label
{
Text = "Header",
FontSize = 32,
TextColor = Color.FromArgb("#3B3A39")
},
ItemTemplate = new DataTemplate(CreateItemTemplate)
};

Grid.SetRow(myCollection, 2);
button.Clicked += (s, e) =>
{

myCollection.ScrollTo(15, position: ScrollToPosition.End, animate: true);
};

// Add to grid
grid.Children.Add(verticalHeaderLayout);
grid.Children.Add(button);

grid.Children.Add(myCollection);
Content = grid;
}

private View CreateItemTemplate()
{
var label = new Label
{
MaxLines = 3,
LineBreakMode = LineBreakMode.TailTruncation,
Text = @"DescriptionDescriptionDescriptionDescriptionDescriptionDescriptionDescriptionDescriptionDescriptionDescriptionDescriptionDescription DescriptionDescriptionDescriptionDescriptionDescriptionDescriptionDescriptionDescription
DescriptionDescriptionDescriptionDescriptionDescriptionDescription DescriptionDescriptionDescriptionDescriptionDescriptionDescriptionDescriptionDescriptionDescriptionDescriptionDescriptionDescriptionDescriptionDescriptionDescription
DescriptionDescriptionDescription
DescriptionDescriptionDescription",
BackgroundColor = Colors.Green,
HorizontalOptions = LayoutOptions.Start
};

var image = new Image
{
Aspect = Aspect.AspectFit,
BackgroundColor = Colors.Transparent,
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
HeightRequest = 24,
Source = "dotnet_bot.png",
Margin = new Thickness(0, 0, 20, 0)
};

var layout = new Grid
{
ColumnDefinitions =
{
new ColumnDefinition { Width = GridLength.Star },
new ColumnDefinition { Width = GridLength.Auto }
},
BackgroundColor = Colors.AliceBlue,
Padding = 5
};

layout.Children.Add(label);
layout.Children.Add(image);
Grid.SetColumn(label, 0);
Grid.SetColumn(image, 1);

return layout;
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#if TEST_FAILS_ON_CATALYST && TEST_FAILS_ON_WINDOWS //The test fails on Windows and MacCatalyst because the SetOrientation method, which is intended to change the device orientation, is only supported on mobile platforms iOS and Android.
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue29542 : _IssuesUITest
{
public Issue29542(TestDevice device) : base(device) { }

public override string Issue => "I1_Vertical_list_for_Multiple_Rows - Rotating the emulator would cause clipping on the description text.";

[Test]
[Category(UITestCategories.Label)]
public void LabelShouldSizeProperlyOnCollectionView()
{
App.WaitForElement("TestCollectionView");
App.Tap("ScrollToDownButton");
App.SetOrientationLandscape();
App.WaitForElement("TestCollectionView");
VerifyScreenshot();
}

[TearDown]
public void TearDown()
{
App.SetOrientationPortrait();
}
}
#endif
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 0 additions & 33 deletions src/Core/src/Platform/Android/MauiTextView.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using Android.Content;
using Android.Text;
using Android.Views;
using AndroidX.AppCompat.Widget;

namespace Microsoft.Maui.Platform
Expand All @@ -18,37 +16,6 @@ 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)
{
// 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);
}

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
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
*REMOVED*override Microsoft.Maui.Platform.MauiPicker.OnTouchEvent(Android.Views.MotionEvent? e) -> bool
override Microsoft.Maui.Platform.MauiDatePicker.DefaultMovementMethod.get -> Android.Text.Method.IMovementMethod?
override Microsoft.Maui.Platform.MauiPickerBase.DefaultMovementMethod.get -> Android.Text.Method.IMovementMethod?
override Microsoft.Maui.Platform.MauiTimePicker.DefaultMovementMethod.get -> Android.Text.Method.IMovementMethod?
override Microsoft.Maui.Platform.MauiTimePicker.DefaultMovementMethod.get -> Android.Text.Method.IMovementMethod?
*REMOVED*override Microsoft.Maui.Platform.MauiTextView.OnMeasure(int widthMeasureSpec, int heightMeasureSpec) -> void