Skip to content

[iOS] Button.LineBreakMode Does Not Appear to Truncate in this Context: StackLayout > Border > Grid > Button #19806

@pcharleszemora

Description

@pcharleszemora

Description

There appears to be different behavior for Button.LineBreakMode on iOS and Android in the scenario included in the Steps to Reproduce section.

On iOS, one can see the Button.Text does not appear to truncate (Figure 1.1).
On Android, one can see the Button.Text does appear to truncate (Figure 1.2).

Is this behavior by design or a bug?

Figure 1.1: iOS
iOS - iPhone 11 Pro Max (iOS 15 5)

Figure 1.2: Android
android-pixel-5-android-12-api-31

Steps to Reproduce

  1. Create a new .NET MAUI app
  2. Replace the XAML in MainPage.xaml with this:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">

    <VerticalStackLayout>
        <Border Margin="8"
                Padding="8"
                Background="White"
                StrokeShape="{RoundRectangle CornerRadius=4}"
                Shadow="{Shadow Radius=4, Opacity=.4}">
        
            <Grid Padding="8"
                  ColumnDefinitions="*"
                  RowSpacing="4"
                  RowDefinitions="*,*,*">

                <Label Grid.Row="0"
                       Grid.Column="0"
                       Text="Row 0: Hello, World!"
                       SemanticProperties.HeadingLevel="Level1" />

                <Label Grid.Row="1"
                       Grid.Column="0"
                       Text="Row 1: Welcome to .NET Multi-platform App UI"
                       SemanticProperties.HeadingLevel="Level2"
                       SemanticProperties.Description="Welcome to dot net Multi platform App U I" />

                <Button Grid.Row="2"
                        Grid.Column="0"
                        x:Name="CounterBtn"
                        Text="Row 2: Why is this happening to this button in this context on this iOS simulator?" 
                        SemanticProperties.Hint="Counts the number of times you click"
                        Clicked="OnCounterClicked"
                        HorizontalOptions="Start"
                        BorderWidth="1"
                        BackgroundColor="White"
                        TextColor="Purple"
                        BorderColor="Purple"
                        Padding="0"
                        LineBreakMode="TailTruncation"/>
            </Grid>
        </Border>
    </VerticalStackLayout>

</ContentPage>
  1. Replace the C# code in MainPage.xaml.cs with this:
namespace GridButtonLineBreak;

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
    }

    private void OnCounterClicked(object sender, EventArgs e)
    {
        var textColor = CounterBtn.TextColor;
        var backgroundColor = CounterBtn.BackgroundColor;

        CounterBtn.BackgroundColor = textColor;
        CounterBtn.TextColor = backgroundColor;
    }
}
  1. Run the app on an iOS simulator.

Observed: The Button.Text does not truncate.
Expected: The Button.Text to truncate.

Link to public reproduction project repository

No response

Version with bug

8.0.3

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 15.5

Did you find any workaround?

In this scenario, instead of using a Button, try using a Label w/ TapGestureRecognizer.

Relevant log output

No response

Metadata

Metadata

Assignees

Labels

area-controls-buttonButton, ImageButtonarea-layoutStackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenterp/1Work that is important, and has been scheduled for release in this or an upcoming sprintplatform/iost/bugSomething isn't working

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions