Skip to content

[iOS] OnSizeAllocated called repeatedly using On<iOS>() .SetUseSafeArea(true); #22090

@czuck

Description

@czuck

Description

App appears hung and is non responsive. Debug line added to OnSizeAllocated is written hundreds of time, width is always the same, height switches between 896 and 814, app eventually crashes.

Debug.WriteLine("****** Width = " + width + " Height = " + height + " Counter = " + ++counter + "***********");

[0:] ****** Width = 331 Height = 814 Counter = 1187***********
[0:] ****** Width = 331 Height = 896 Counter = 1188***********
[0:] ****** Width = 331 Height = 814 Counter = 1189***********
[0:] ****** Width = 331 Height = 896 Counter = 1190***********
[0:] ****** Width = 331 Height = 814 Counter = 1191***********
[0:] ****** Width = 331 Height = 896 Counter = 1192***********
[0:] ****** Width = 331 Height = 814 Counter = 1193***********

Steps to Reproduce

Create a File > new maui App. Create a MainFlyoutPage : Flyout page with the code:

public class MainFlyoutPage : FlyoutPage
{
    public MainFlyoutPage()
    {
        Flyout = new MenuPage();
        Detail = New NavigationPage(new DetailPage());
    }
}

Detail page can be anything. Create a MenuPage with the code:

public partial class MenuPage : ContentPage
{
    public const double Tolerance = 0.000000001;
    private double _width = 0;
    private double _height = 0;
    private int counter = 0;

    public MenuPage()
	{
		InitializeComponent();

    }


    protected override void OnSizeAllocated(double width, double height)
    {
        base.OnSizeAllocated(width, height);
        Debug.WriteLine("****** Width = " + width + " Height = " + height + " Counter = " + ++counter + "***********");
        if ((Math.Abs(width - _width) > Tolerance || Math.Abs(height - _height) > Tolerance) &&
            width != 0)
        {
            _width = width;
            _height = height;
            RenderPage();
        }
    }

    public void RenderPage()
    {
        Content = null;
        On<Microsoft.Maui.Controls.PlatformConfiguration.iOS>().SetUseSafeArea(true);
        var background = new Image
        {
            Source = "dotnet_bot.png"
        };
        Content = background;
    }

Run the app and watch the output.

Link to public reproduction project repository

No response

Version with bug

8.0.21 SR4.1

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-layoutStackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenterdelighter-scperf/generalThe issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf)platform/ioss/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions