Skip to content

[iOS] Wrong sizing of layouts #9825

@RadekVyM

Description

@RadekVyM

Description

Hi, I found out that layouts do not react to size changes of their children correctly on iOS. Let's have this quite simple layout:

<Grid RowDefinitions="*, 100">
    <Border VerticalOptions="Center" HorizontalOptions="Center">
        <Grid RowDefinitions="auto" ColumnDefinitions="auto">
            <BoxView Color="Red" HorizontalOptions="Fill" VerticalOptions="Fill"/>
            <ScrollView>
                <StackLayout BackgroundColor="Yellow">
                    <Label Text="This"/>
                    <Label Text="is"/>
                    <Label Text="a"/>
                    <Label Text="StackLayout"/>
                    <Label Text="content"/>
                    <Label x:Name="variableLabel" WidthRequest="100" Text="Label with variable width"/>
                </StackLayout>
            </ScrollView>
        </Grid>
    </Border>

    <Button 
        Grid.Row="1"
        HorizontalOptions="Center" VerticalOptions="Center"
        Text="Change size of the label in StackLayout"
        Clicked="ButtonClicked"/>
</Grid>

On button click, the label with the text "Label with variable width" changes its width from 100 to 200 (and vice versa) - see code behind:

private void ButtonClicked(object sender, EventArgs e)
{
    if (variableLabel.WidthRequest == 100)
        variableLabel.WidthRequest = 200;
    else
        variableLabel.WidthRequest = 100;
}

Examples

Here are examples of how clicking the button behaves on different platforms:

Android.example.mp4
Windows.example.mp4
iOS.example.1.mp4

As you can see, it behaves as expected on Windows and Android (containers adjust to the size changes of their content), but on iOS it is completely wrong (containers do not adjust at all). The label with the text "Label with variable width" is also clipped from the bottom, which it should not be.

If I remove the ScrollView from the layout:

iOS.example.2.mp4

Containers adjust to the wider label, but then it does not shrink back down.

If I remove the red BoxView too:

iOS.example.3.mp4

The required behavior is almost there but not entirely - the label is still clipped from the bottom.

The problem is probably present on the macOS version too, but I have not had an opportunity to test it there yet.

I hope my description of the problem is clear. If not, feel free to ask 🙂

Steps to Reproduce

Download the reproduction project, run it, and click the button a few times. You will see the behavior described above.

Link to public reproduction project repository

https://github.com/RadekVyM/MauiBugs/tree/main/iOSWrongSizing

Version with bug

6.0.486 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 15

Did you find any workaround?

No

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions