dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.99k stars 1.72k forks source link

ScrollView inside a dynamic Grid row won't completely scroll (iOS) #15288

Open LukeFranky opened 1 year ago

LukeFranky commented 1 year ago

Description

If a ScrollView is positioned inside of a Grid row with a dynamic height (RowDefinition Height="*"), it cannot be scrolled completely to the bottom.

This was not a problem in previous versions. Yet to find a workaround.

Steps to Reproduce

  1. Create a new MAUI project (or use the repo).
  2. Wrap the ScrollView with a Grid.
  3. Add a RowDefinition with Height="100".
  4. Add a RowDefinition with Height="*".
  5. Set ScrollView Row="1".
  6. Run the application.
  7. Try to scroll to the bottom (The button will not stay visible).

Link to public reproduction project repository

https://github.com/LukeFranky/ScrollView-in-Grid-MAUI-Bug

Version with bug

7.0.86

Last version that worked well

7.0.81

Affected platforms

iOS

Affected platform versions

14.6

Did you find any workaround?

No response

Relevant log output

No response

ritesh-burn commented 1 year ago

Yes I'm seeing this as well. I've seen a similar issue with CollectionViews inside a Grid as well but it doesn't seem to be consistent.

LukeFranky commented 1 year ago

@ritesh-burn here's my current workaround. It will only work if you have one dynamically sized row, not multiple.

Seems to be such a basic thing to be broken.

    private void TemplateGrid_SizeChanged(object sender, EventArgs e)
    {
        // Fix scroll height;
        double remainingHeight = this.TemplateGrid.Height;

        foreach (RowDefinition row in this.TemplateGrid.RowDefinitions)
        {
            if (row.Height.IsAbsolute)
            {
                remainingHeight -= row.Height.Value;
            }
        }

        this.ScrollArea.HeightRequest = remainingHeight;
    }
omghb commented 1 year ago

Maybe this is about the same issue:

ritesh-burn commented 1 year ago

Thanks @LukeFranky I will try it out. I also noticed that just setting the height to something arbitrary like CollectionView.MaximumHeightRequest = Grid.Height - 200; seems to work in most cases but still fails at times.

faheys commented 1 year ago

Same problem with both scroll views and collection views on iOS for me as well. Latest MAUI update (non preview) has completely borked almost everything that uses a grid and dynamic height/width values.

ritesh-burn commented 1 year ago

I looked at the code changes that broke this and it looks like it will go back to previous behavior if the Grid's height is fixed. So if you have a grid that covers the full height of the screen, you can do something like this as a work around and it will work like before:

    protected override void OnAppearing()
    {
        base.OnAppearing();
        Grid.HeightRequest = DeviceDisplay.MainDisplayInfo.Height / DeviceDisplay.MainDisplayInfo.Density;
    }

YMMV.