Skip to content

[iOS] Updating the text of a label destroys the ScrollView layout #18496

@hwsmo

Description

@hwsmo

Description

If the text of a label in a ScrollView is updated, then it destroys the layout of the ScrollView.

Bug is only see in iOS. There are no problems on Android and Windows.

Version wich bug:
[8.0.0-rc.2.9511]

The bug did not occur in version 8.0.0-rc.2.9373!

Steps to Reproduce

  1. Create a new project > New .NET MAUI App
  2. Create a page with a lots of labels in a ScrollView and with one label (named "ViewCounter") far below.
  3. In the code behind, we start a dispatcher timer and update the text of the "ViewCounter" label every 5 seconds.
  4. Start the test app and scroll to the “ViewCounter” label.
  5. Wait and admire the bug ;o)

MainPage XAML:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
  x:Class="HW_Playground.MainPage"
  xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
  xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">

  <ScrollView
    Orientation="Vertical"
    VerticalOptions="FillAndExpand"
    VerticalScrollBarVisibility="Always">
    <VerticalStackLayout
      Padding="30,0"
      Spacing="25"
      VerticalOptions="Center">
      <Image
        HeightRequest="200"
        HorizontalOptions="Center"
        SemanticProperties.Description="Cute dot net bot waving hi to you!"
        Source="dotnet_bot.png" />
      <Label
        FontSize="32"
        HorizontalOptions="Center"
        SemanticProperties.HeadingLevel="Level1"
        Text="Hello, World!" />
      <Label
        FontSize="32"
        HorizontalOptions="Center"
        SemanticProperties.HeadingLevel="Level1"
        Text="Hello, World!" />
      <Label
        FontSize="32"
        HorizontalOptions="Center"
        SemanticProperties.HeadingLevel="Level1"
        Text="Hello, World!" />
      <Label
        FontSize="32"
        HorizontalOptions="Center"
        SemanticProperties.HeadingLevel="Level1"
        Text="Hello, World!" />
      <Label
        FontSize="32"
        HorizontalOptions="Center"
        SemanticProperties.HeadingLevel="Level1"
        Text="Hello, World!" />
      <Label
        FontSize="32"
        HorizontalOptions="Center"
        SemanticProperties.HeadingLevel="Level1"
        Text="Hello, World!" />
      <Label
        FontSize="32"
        HorizontalOptions="Center"
        SemanticProperties.HeadingLevel="Level1"
        Text="Hello, World!" />
      <Label
        FontSize="32"
        HorizontalOptions="Center"
        SemanticProperties.HeadingLevel="Level1"
        Text="Hello, World!" />
      <Label
        x:Name="ViewCounter"
        FontSize="32"
        HorizontalOptions="Center"
        SemanticProperties.HeadingLevel="Level1"
        Text="COUNTER"
        TextColor="Red" />
      <Label
        FontSize="32"
        HorizontalOptions="Center"
        SemanticProperties.HeadingLevel="Level1"
        Text="Hello, World!" />
      <Label
        FontSize="32"
        HorizontalOptions="Center"
        SemanticProperties.HeadingLevel="Level1"
        Text="Hello, World!" />
      <Label
        FontSize="32"
        HorizontalOptions="Center"
        SemanticProperties.HeadingLevel="Level1"
        Text="Hello, World!" />
    </VerticalStackLayout>
  </ScrollView>

</ContentPage>

MainPage Code Behind:

namespace HW_Playground;

public partial class MainPage : ContentPage
{
  int count = 0;

  public MainPage()
  {
    InitializeComponent();
  }


  protected override void OnAppearing()
  {
    base.OnAppearing();

    Timer.Start();
  }

  private IDispatcherTimer Timer
  {
    get
    {
      if ( _timer == null )
      {
        _timer = Dispatcher.CreateTimer();
        _timer.Interval = TimeSpan.FromSeconds( 5 );
        _timer.Tick += Tick;
      }

      return _timer;
    }
  }
  private IDispatcherTimer? _timer;


  int counter = 1;
  private void Tick( object? _sender, EventArgs _eventArgs )
  {
    ViewCounter.Text = $"Counter: {counter++}";
  }

}

Link to public reproduction project repository

No response

Version with bug

Unknown/Other

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.0-rc.2.9373

Affected platforms

iOS

Affected platform versions

iOS 17.0.3

Did you find any workaround?

Not yet.

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-controls-scrollviewScrollViewi/regressionThis issue described a confirmed regression on a currently supported versionplatform/iost/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions