maui icon indicating copy to clipboard operation
maui copied to clipboard

[iOS] CollectionView takes up huge vertical space

Open BlagoCuljak opened this issue 2 years ago • 20 comments

Description

We are developing MAUI app, and we use CollectionView constantly. However, on iOS, every collection view takes up huge vertical space, just like this. Android looks good. image

Here is the sample: CollectionViewDemos.zip

Steps to Reproduce

Start the app, and click on one view in menu. Android looks fine, iPhone had huge problem with lower number of items in CollectionView.

Version with bug

6.0.408 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 15

Did you find any workaround?

None at the moment, you can set MaximumHeight, but it just gets ugly then, and not all items are displayed, and you need to scroll inside that small MaxHeight window.

Relevant log output

No response

BlagoCuljak avatar Aug 02 '22 13:08 BlagoCuljak

Please add the repro as a GitHub repository, thank you!

jfversluis avatar Aug 03 '22 13:08 jfversluis

Hi @BlagoCuljak. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

ghost avatar Aug 03 '22 13:08 ghost

Please add the repro as a GitHub repository, thank you!

Hi @jfversluis, thanks for your comment, here you will find github repo. https://github.com/BlagoCuljak/CollectionViewIOSheight

BlagoCuljak avatar Aug 03 '22 13:08 BlagoCuljak

I can confirm the issue, present on iOS. Android works well.

Adelzu avatar Aug 05 '22 07:08 Adelzu

Can confirm same issue on iOS, Android works OK!

andrijankara avatar Aug 05 '22 15:08 andrijankara

I can see the same problem in the horizontal direction. The screenshot is from a mac catalyst app.

Screenshot 2022-08-25 at 10 20 16

dhindrik avatar Aug 25 '22 08:08 dhindrik

Facing same issue with ios, works fine in Android - MAUI ios My collection view is inside a Frame which is inside a ScrollView. Any solution or workaround

ganeshachary avatar Nov 02 '22 12:11 ganeshachary

Related https://github.com/dotnet/maui/issues/7315

PureWeen avatar Nov 02 '22 19:11 PureWeen

I'am also facing the same issue on MAUI for iOS. Is there any chance that this issue will be fixed in the near future?

BaumTom avatar Nov 04 '22 08:11 BaumTom

I am experiencing the exact same issue. I have nested collection views and each of them renders in a huge amount of space (only on iOS).

If anyone has any resources on how to possibly dynamically size the items and the CollectionView itself, I'd love to know because the current "built-in" functionality is completely broken.

EmberLynn avatar Nov 07 '22 21:11 EmberLynn

My workaround so far is to replace the CollectionView with a (Vertical)StackLayout with BindableLayout.ItemsSource. The CollectionView is not usable at all for me.

BaumTom avatar Nov 08 '22 08:11 BaumTom

I am experiencing the exact same issue. I have nested collection views and each of them renders in a huge amount of space (only on iOS).

If anyone has any resources on how to possibly dynamically size the items and the CollectionView itself, I'd love to know because the current "built-in" functionality is completely broken.

Well, I named this thread "[iOS] CollectionView takes up huge vertical space; this makes almost impossible to use MAUI" and I feel your pain. I just don't know what people at Microsoft think how this works. It was 3 months since my issue, and no luck what so ever.

BlagoCuljak avatar Nov 08 '22 08:11 BlagoCuljak

My workaround so far is to replace the CollectionView with a (Vertical)StackLayout with BindableLayout.ItemsSource. The CollectionView is not usable at all for me.

Thanks for the suggestion. I was also thinking about giving ListView a try, too.

EmberLynn avatar Nov 08 '22 15:11 EmberLynn

I am experiencing the exact same issue. I have nested collection views and each of them renders in a huge amount of space (only on iOS). If anyone has any resources on how to possibly dynamically size the items and the CollectionView itself, I'd love to know because the current "built-in" functionality is completely broken.

Well, I named this thread "[iOS] CollectionView takes up huge vertical space; this makes almost impossible to use MAUI" and I feel your pain. I just don't know what people at Microsoft think how this works. It was 3 months since my issue, and no luck what so ever.

This is a massive issue and takes away the entire "one size fits all" problem that Microsoft is trying to solve with MAUI. They've released MAUI into production, yet it is still plagued with bugs that make certain use cases impossible to solve. They suggest you use CollectionView above ListView, but that isn't helpful when the CollectionView's behavior doesn't come close to matching Android's. I have to fiddle around with multiple views, render in iOS to see if it looks okay, and then render back in Android to see if it looks okay there.

EmberLynn avatar Nov 08 '22 15:11 EmberLynn

I also have the same issue. Any updates?

akhanalcs avatar Nov 09 '22 20:11 akhanalcs

hi,

Just to confirm I have the same issue.

The reason why I can't replace the child CollectionView is the Span=X grid layout which is damn useful with our big 7" phone screens !

manitra avatar Nov 11 '22 08:11 manitra

just not funny anymore...

nebula2 avatar Nov 11 '22 13:11 nebula2

I'm having the same issue here, visual studio for mac 17.4 . Can you guys give us some feedback on this ? @jfversluis Could you please help us ? This is a critical issue and it's happening from a long time

victorsigga avatar Nov 11 '22 14:11 victorsigga

My workaround so far is to replace the CollectionView with a (Vertical)StackLayout with BindableLayout.ItemsSource. The CollectionView is not usable at all for me.

Wanted to give an update that this is what I had to do to get my group of objects to render nicely on the screen. I first attempted to use ListView but found that its behvaiour and performance were far worse than CollectionView. So, as you mentioned, I used BindableLayouts instead.

EmberLynn avatar Nov 18 '22 20:11 EmberLynn

Ran into this as well when using CarouselView. Only workaround I found was to set the MaximumHeightRequest on it.

KieranMaclagan avatar Nov 24 '22 17:11 KieranMaclagan

Same here. Had to set the GridRowDefinition to a fix height on IOS as a workaround.

Lazareena avatar Dec 07 '22 16:12 Lazareena

I have same problem on iOS platform with CarouselView. Android platform is ok

MarMarIV avatar Dec 15 '22 04:12 MarMarIV

This is a pretty big issue in my app too. My layouts need to be hardcoded, which really prevents making them pretty. Hopefully a fix comes out soon!

AdamBebko avatar Dec 28 '22 21:12 AdamBebko

Also having this issue on my IOS MAUI app

jpsaccount avatar Dec 31 '22 00:12 jpsaccount

Instead of opening a new issue, has this issue being fixed especially on iOS.

EdwardMcFlurry avatar Jan 03 '23 08:01 EdwardMcFlurry

This issue very soon must be solved

progrish avatar Jan 09 '23 08:01 progrish

The CarouselView and CollectionView both have this issue due to which it takes up huge amount of space on iOS. The only workaround is to give it a fix size or use bindable layout.

HobDev avatar Jan 14 '23 07:01 HobDev

in this old post : https://github.com/dotnet/maui/issues/6605 [@espenrl] (https://github.com/espenrl) commented [on Oct 19, 2022] solve a part of the problem with a behavior as follow

for a complete solution that work in StackLayout, VerticalStackLayout, SchrollView, ... I add a border arround the CollectionView to force the computation of height (and use of behavior) before container height determination.

It save my project !!!

<CollectionView.Behaviors>
   <views:IOSFixInfiniteHeightCollectionView />
</CollectionView.Behaviors>
    /// <summary>
    /// iOS CollectionView size calculation
    /// https://github.com/dotnet/maui/issues/6605
    /// </summary>
    public sealed class IOSFixInfiniteHeightCollectionView : Behavior<CollectionView>
    {
        private void CollectionViewOnSizeChanged(object? sender, EventArgs e)
        {
#if IOS
            if (sender is not CollectionView collectionView)
            {
                throw new InvalidOperationException();
            }
            if (collectionView.Handler?.PlatformView is not UIKit.UIView uiView)
            {
                throw new InvalidOperationException();
            }

            var uiCollectionView = uiView.Subviews
                .OfType<UIKit.UICollectionView>()
                .Single();

            const double emptyViewRequiredHeight = 50;
            const double additionalHeight = 20; // this is needed or else the collection view will be truncated
            var calculatedHeight = (double)uiCollectionView.CollectionViewLayout.CollectionViewContentSize.Height;
            var height = additionalHeight + calculatedHeight;
            collectionView.MaximumHeightRequest = Math.Max(emptyViewRequiredHeight, height);
#endif
        }

        protected override void OnAttachedTo(CollectionView bindable) => bindable.SizeChanged += CollectionViewOnSizeChanged;
        protected override void OnDetachingFrom(CollectionView bindable) => bindable.SizeChanged -= CollectionViewOnSizeChanged;
    }

TheDev51 avatar Jan 20 '23 14:01 TheDev51

Both CollectionView and CarouselView are derived from ItemsView. So I assume the source of the problem is related to ItemsView.

AlexeyStarkov avatar Jan 25 '23 22:01 AlexeyStarkov

Same issue occurs with CarourselView. But I cannot find a similar workaround as above with tweaking MaximumHeightRequest in OnSizeChanged.

Code to reproduce: Main ContentPage like this:

<VerticalStackLayout>
        <Label Text="Label1"></Label>
        <CarouselView ItemsSource="{Binding Items}" Loop="false" IndicatorView="indicatorView">
            <CarouselView.ItemTemplate>
                <DataTemplate>
                    <Label Text="{Binding Name}" BackgroundColor="LightGray"></Label>
                </DataTemplate>
            </CarouselView.ItemTemplate>
        </CarouselView>
        <IndicatorView x:Name="indicatorView" HorizontalOptions="Center"></IndicatorView>
        <Label Text="Label2"></Label>
    </VerticalStackLayout>
public partial class MainPage : ContentPage
{
    public class Item
    {
        public string Name { get; set; }
    }

    public ObservableCollection<Item> Items { set; get; }

    public MainPage()
	{
        Items = new ObservableCollection<Item>();
        Items.Add(new Item() { Name = "Item1" });
        Items.Add(new Item() { Name = "Item2" });
        Items.Add(new Item() { Name = "Item3" });
        InitializeComponent();
        BindingContext = this;
    }
}

ThoHensler avatar Mar 09 '23 13:03 ThoHensler