Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Shapes in CollectionView will cause item height increase #23446

Closed
NXDMN opened this issue Jul 5, 2024 · 3 comments
Closed

[iOS] Shapes in CollectionView will cause item height increase #23446

NXDMN opened this issue Jul 5, 2024 · 3 comments
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView platform/iOS 🍎 s/needs-repro Attach a solution or code which reproduces the issue t/bug Something isn't working

Comments

@NXDMN
Copy link

NXDMN commented Jul 5, 2024

Description

When ItemTemplate of CollectionView contains BoxView (actually all Shapes type) that has WidthRequest and no HeightRequest, the height of items that appear after scrolling seem to follow previous items, like the previous item height is cached and used on items that come after, without remeasure them.

Steps to Reproduce

xaml file:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MauiApp1.CollectionViewPage"
             Title="CollectionViewPage">
    <Grid Padding="10">
        <RefreshView Grid.Row="0" IsRefreshing="{Binding IsRefreshing}" Refreshing="RefreshView_Refreshing">
            <CollectionView ItemsSource="{Binding Items}" 
                            RemainingItemsThreshold="0"
                            RemainingItemsThresholdReached="CollectionView_RemainingItemsThresholdReached">
                <CollectionView.ItemTemplate>
                    <DataTemplate>
                        <VerticalStackLayout>
                            <Frame Margin="0,10" BackgroundColor="GhostWhite" Padding="0" CornerRadius="4">
                                <Grid
                                    ColumnSpacing="6"
                                    HorizontalOptions="FillAndExpand">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>

                                    <BoxView
                                        Grid.Column="0"
                                        Color="Red"
                                        VerticalOptions="FillAndExpand"
                                        WidthRequest="5" />
                                    <Label Grid.Column="1" Text="{Binding .}" FontSize="20"/>
                                </Grid>
                            </Frame>
                        </VerticalStackLayout>
                    </DataTemplate>
                </CollectionView.ItemTemplate>
            </CollectionView>
        </RefreshView>
    </Grid>
</ContentPage>

Code-behind file:

using System.Collections.ObjectModel;
using System.ComponentModel;

namespace MauiApp1;

public partial class CollectionViewPage : ContentPage
{
	public bool IsRefreshing { get; set; } = false;

	public ObservableCollection<string> Items { get; set;} = [];

	public CollectionViewPage()
	{
		InitializeComponent();
		BindingContext = this;
	}

        protected override void OnAppearing()
        {
                 base.OnAppearing();

		 LoadItems(true);
         }
 
	private void LoadItems(bool clearItems = false)
	{
		IsRefreshing = true;

		if(clearItems) Items.Clear();
		
		for(int i = 0; i <= 20; i++){
			Items.Add(GenerateRandomString());
		}

		IsRefreshing = false;
		OnPropertyChanged(nameof(IsRefreshing));
	}

        private readonly Random _random = new();

	private string GenerateRandomString()
	{
		const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
		return new string(Enumerable.Repeat(chars, _random.Next(1, 256)).Select(s => s[_random.Next(s.Length)]).ToArray());
	}

	private void RefreshView_Refreshing(object sender, EventArgs eventArgs)
	{
		LoadItems(true);
	}

	private void CollectionView_RemainingItemsThresholdReached(object sender, EventArgs eventArgs)
	{
		LoadItems();
	}
}

Link to public reproduction project repository

No response

Version with bug

8.0.61 SR6.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

iOS 17.5

Did you find any workaround?

Use Grid

Relevant log output

No response

@NXDMN NXDMN added the t/bug Something isn't working label Jul 5, 2024
Copy link
Contributor

github-actions bot commented Jul 5, 2024

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@MartyIX MartyIX added platform/iOS 🍎 area-controls-collectionview CollectionView, CarouselView, IndicatorView labels Jul 5, 2024
@PureWeen PureWeen added the s/needs-repro Attach a solution or code which reproduces the issue label Jul 9, 2024
Copy link
Contributor

Hi @NXDMN. 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.

@dotnet-policy-service dotnet-policy-service bot added the s/no-recent-activity Issue has had no recent activity label Jul 15, 2024
Copy link
Contributor

This issue has been automatically marked as stale because it has been marked as requiring author feedback to reproduce the issue but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 18, 2024
@dotnet-policy-service dotnet-policy-service bot removed the s/no-recent-activity Issue has had no recent activity label Aug 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView platform/iOS 🍎 s/needs-repro Attach a solution or code which reproduces the issue t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants