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] Fix cell size changed on CollectionView #7447

Merged
merged 4 commits into from
May 31, 2022
Merged

[iOS] Fix cell size changed on CollectionView #7447

merged 4 commits into from
May 31, 2022

Conversation

rmarinho
Copy link
Member

@rmarinho rmarinho commented May 24, 2022

Description of Change

CollectionView Cells need a way to know that the contents of the MAUI view have changed and to update it's layout. We used MeasuredInvalidated for that, but the new layouts weren't bubbling it from the children, this pr allows that to done when a child is added to the VE.

On iOS the InvalidateLayout wasn0't working to update cell size, but if we reload the visible cells it works fine.

Issues Fixed

Fixes #3643

Use this to test

<Grid>
      <CollectionView ItemsSource="{Binding Items}" BackgroundColor="Pink" >
          <CollectionView.ItemTemplate>
              <DataTemplate>
                  <Grid BackgroundColor="Red" Padding="10">
                      <Label Text="{Binding Name}" BackgroundColor="Yellow" TextColor="Black"/>
                  </Grid>
              </DataTemplate>
          </CollectionView.ItemTemplate>
      </CollectionView>
 </Grid>
public MainPage()
{
   InitializeComponent();
   BindingContext = this;
   Device.StartTimer(TimeSpan.FromSeconds(5), () =>
   {
   	UpdateStuff();
   	return false;
   });
}

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

   	return _items;
   }
}
   
void UpdateStuff()
{
   System.Diagnostics.Debug.WriteLine($"UpdateStuff");
   		var bigString = "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.";
   foreach (var item in Items)
   {
   	item.Name = bigString;
   }
}

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;
}

@rmarinho rmarinho requested a review from hartez May 24, 2022 17:52
@Redth Redth added this to the 6.0.3xx-sr1 milestone May 24, 2022
@Eilon Eilon added the area-controls-collectionview CollectionView, CarouselView, IndicatorView label May 24, 2022
@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@rmarinho rmarinho merged commit e4aa6df into main May 31, 2022
@rmarinho rmarinho deleted the fix-3643 branch May 31, 2022 13:51
@github-actions github-actions bot locked and limited conversation to collaborators Dec 21, 2023
@samhouts samhouts added the fixed-in-6.0.400 Look for this fix in 6.0.400! label Aug 2, 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 fixed-in-6.0.400 Look for this fix in 6.0.400!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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