Skip to content

[Bug] iOS: CollectionView items don't change their size when item content size is changed #3643

@MariyaGordeeva

Description

@MariyaGordeeva

Description

CollectionView items don't change their size when item content size is changed

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MauiApp.MainPage" BackgroundColor="White">

     <StackLayout>
        <Button Text="Button" Clicked="Button_Clicked"/>
        <CollectionView ItemsSource="{Binding Items}" >
                <CollectionView.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Label Text="{Binding Name}"/>
                        </Grid>
                    </DataTemplate>
                </CollectionView.ItemTemplate>
        </CollectionView>
    </StackLayout>
</ContentPage>
public partial class MainPage : ContentPage {
	public MainPage() {
		InitializeComponent();
                BindingContext = this;
	}

        ObservableCollection<SomeItem> _items;
        public ObservableCollection<SomeItem> Items {
            get {
                if (_items == null) {
                    _items = new ObservableCollection<SomeItem>(Enumerable.Range(0, 5).Select(c => {
                        return new SomeItem() { Name = string.Format("Item {0}", c) };
                    }));
                }

                return _items;
            }
        }

        void Button_Clicked(System.Object sender, System.EventArgs e) {
            foreach (SomeItem item in Items) {
                item.Name = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
            }
        }

public class SomeItem : INotifyPropertyChanged {
        string name;
        public string Name {
            get => name;
            set {
                name = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Name)));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}

Expected Behavior

All items change their height

Screen.Recording.2021-12-03.at.13.07.37.mov

Actual Behavior

All items don't change their height

Screen.Recording.2021-12-03.at.13.06.48.mov

Steps to Reproduce

  1. Create a MAUI app
  2. Put Button and CollectionView into StackLayout on the MainPage.xaml
  3. Set ItemTemplate for CollectionView, put into ItemTemplate Grid with Label
  4. In the Button.Clicked event handler change Label.Text
  5. Deploy to iOS simulator and click the Button

Version with bug

Preview 10 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 15

Did you find any workaround?

No response

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-controls-collectionviewCollectionView, CarouselView, IndicatorViewarea-layoutStackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenterfixed-in-6.0.400Look for this fix in 6.0.400!fixed-in-7.0.100fixed-in-7.0.101fixed-in-7.0.59Look for this fix in 7.0.59!fixed-in-8.0.0-preview.1.7762Look for this fix in 8.0.0-preview.1.7762!p/1Work that is important, and has been scheduled for release in this or an upcoming sprintpartnerIssue or Request from a partner teamplatform/ioss/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions