Instagram / IGListKit

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

Visible sectionController's layout not updated after performUpdates() #629

Closed maxim04 closed 7 years ago

maxim04 commented 7 years ago

New issue checklist

General information

Hi all, i am getting data from a rest api, after getting the data i append it to the data array and call adapter.performUpdates(). I apply a transform to the cells in the sectionController, but the visible sectionController's layout is not updated until the state of the section changes from offScreen -> onScreen.

This can be reproduced in the example project in the Tail Loading example by applying cell.transform = CGAffineTransform(a: 1, b: 0, c: 0, d: -1, tx: 0, ty: 0) in the LabelSectionController, newly added visible cell's will not have the correct transform until they go offScreen -> onScreen.

Can anybody guide me in the correct direction here, much appreciated.

ryancstack commented 7 years ago

adapter.performUpdates() looks at the the diffIdentifier and the isEqualTo:diffableObject methods to identify if a section controller needs reloading. You can include your transform in the isEqualTo:diffableObject method to determine if the view model has changed.

rnystrom commented 7 years ago

@maxim04 to apply transforms to the cells, you might want to use IGListDisplayDelegate and apply your transform in willDisplay like this.

It also might be more technically correct to do this sort of stuff in a UICollectionViewLayout.

maxim04 commented 7 years ago

@rnystrom tried to apply the transform in listAdapter(_ listAdapter: IGListAdapter, willDisplay sectionController: IGListSectionController, cell: UICollectionViewCell, at index: Int) and still the same thing happening, the transform is only applied when the cell comes from offscreen to onscreen, the already onscreen sections don't have the correct transform. I'm using IGListKit in conjunction with SlackTextViewController if that gives more context, hence why i'm trying to apply the inverted transform.

rnystrom commented 7 years ago

Oh, I've actually never gotten the inverted transform to work with UICollectionView. I believe if you want that to work you'll have to do it all through a custom layout.

ryancstack commented 7 years ago

To make an inverted table work for me, in the cellForItem:atIndex method, I've added a transform like so: cell.transform = cell.transform.scaledBy(x: 1, y: -1) (you may need to set the identity at reuse so you don't keep flipping it). I've also added my collection view as the "arbitrary scroll view managed by SlackTextViewController" in the init(scrollView:) initializer for the SlackTextViewController. But yeah, probably best to have it in a custom layout.

maxim04 commented 7 years ago

After a lot of trial and error i managed to get the inverted UICollectionView to work. The trick was to apply the transform to cell.contentView instead of the cell, i also did this in cellForItem(at index: Int). Now the already on screen sections have the correct transform, as well as the offscreen ones.