Skip to content

Grouped CollectionView content/items overlaps on iOS when data changes or when pull to refresh data #20336

@nsood9

Description

@nsood9

Description

On iOS when CollectionView is used to display grouped data, the content items displayed in the CollectionView overlaps. For the first time it calculates the size correctly and shows everything as expected, but if sometimes, the list data changes or I pull to refresh new data (using RefreshView), the collection content is overlapping and looks so ugly.

Steps to Reproduce

  1. Create a new MAUI app project using usual VS for Mac

  2. Create ObservableCollection for grouped data:

  3. [ObservableProperty]
    ObservableCollection<IGrouping<DateTime?, Items>> groupedItems;

  4. Populate the data from API or your data model

  5. Design your layout to include CollectionView with DataTemplateSelector:

<ResourceDictionary>
<templateSelector:ItemDataTemplateSelector x:Key="itemDataTemplateSelector"
                                        TemplateOne ="{StaticResource DataTemplateOne}"
                                        TemplateTwo ="{StaticResource DataTemplateTwo}"
                                       TemplateThree ="{StaticResource DataTemplateThree}"
                                        TemplateFour ="{StaticResource DataTemplateFour}"
                                        TemplateFive ="{StaticResource DataTemplateFive}"/>

      </ResourceDictionary>
      
      
      <RefreshView Grid.Row="0"  VerticalOptions="FillAndExpand" IsRefreshing="{Binding IsRefreshing}"
                   RefreshColor="{StaticResource Primary}"
                   Command="{Binding RefreshCommand}">
      <CollectionView TranslationY="-23"
          VerticalScrollBarVisibility="Always" ItemTemplate="{StaticResource itemDataTemplateSelector}"
          ItemsSource="{Binding GroupedItems}"  VerticalOptions="FillAndExpand"
          IsGrouped="True" ItemsUpdatingScrollMode="KeepLastItemInView">
          <CollectionView.ItemsLayout>
              <GridItemsLayout VerticalItemSpacing="5"
                  Orientation="Vertical" />
          </CollectionView.ItemsLayout>
          <CollectionView.GroupHeaderTemplate>
              <DataTemplate>
                  <Label Style="{StaticResource HeadingTextStyle}"
                      Padding="30,10,30,0" 
                      Text="{Binding Key, StringFormat='{0: dddd, MMMM dd}'}"
                      VerticalTextAlignment="Center" 
                       />
              </DataTemplate>
          </CollectionView.GroupHeaderTemplate>
          </CollectionView>
          </RefreshView>
  1. Run in iOS simulator, it will look good the very first time and then if you pull to refresh the data, observe the bad overlapping.

  2. Data is dynamic, it will sometimes overlap if the data is changed during runtime and some of the data templates are now not available as per the data

  3. I cannot use ItemSizingStrategy="MeasureFirstItem" because, my design list design requires different data templates, which are of complete different sizes, so there is no chance I can use MeasureFirstItem ItemSizingStrategy.

Due to this, the UI for the very first screen of my app looks so bad that it's not possible to release or at least demo it to client.

Link to public reproduction project repository

No response

Version with bug

8.0.3

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 17+

Did you find any workaround?

Couldn't find any workaround yet.

Relevant log output

No response

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions