Instagram / IGListKit

A data-driven UICollectionView framework for building fast and flexible lists.
https://instagram.github.io/IGListKit/
MIT License
12.87k stars 1.54k forks source link

Should "invalidateLayoutForSectionController:" call "cellForItemAtIndex:" ? #511

Closed diegorozen closed 7 years ago

diegorozen commented 7 years ago

New issue checklist

General information

The latest API addition invalidateLayoutForSectionController: allows for a smooth animation of the cells, but cellForItemAtIndex: doesn't get call at the end of the animation. What should be the approach if I wanted to have a different cell layout/configuration for expanded vs collapsed state?

Thanks!

rnystrom commented 7 years ago

@diegorozen good question! I just ran into this yesterday on Instagram 😄

What we do when the cell needs updated is call our configure methods again. Something like:

- (UICollectionViewCell *)cellForItemAtIndex:(NSInteger)index {
  MyCell *cell = // dequeue
  [cell configureWithData:self.data];
  return cell;
}

- (void)didSelectItemAtIndex:(NSInteger)index {
  [self.collectionContext invalidateLayoutForSectionController:self completion:nil];
  [self configureWithData:self.data];
}

Which works for us. I'd rather leave it to clients that need to reload data to do that manually since cells can be built to respond to changes in other ways, and I don't know think there's a good, single approach.

jessesquires commented 7 years ago

Sounds reasonable to me 👍

diegorozen commented 7 years ago

Works great, thanks!