Instagram / IGListKit

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

Add prefetching functionality to IGListBindingSectionController as WorkRange for IGListAdapter #1046

Open qhhonx opened 6 years ago

qhhonx commented 6 years ago

New issue checklist

UICollectionView introduced prefetchDataSource in iOS10 that we can ease to do preparing stuffs like image-loading for incoming display cells.

IGListKit disabled the builtin prefetching functionality due to performance, while it provides work range mechanism for prefetching. It works for sections based adapter like in Instagram main feed in which we place PostSectionControllers, but sucks in Instagram profile feed in which we probably use one IGListBindingSectionController to show user's all photos and one ProfileSectionController to show user's information. If implement it like this, we loose work-range feature to do prefetch jobs because there are only two objects (sections): user-info model and user-array-photos model.

So, does IGListKit consider to add prefetching functionality to IGListBindingSectionController?

rnystrom commented 6 years ago

Great question!! You can still use the working range with a binding section controller. Just set self as the working range delegate in init (alongside setting the data source) and you can implement the prefetch APIs as you see fit.

Now the only thing is you can’t have a per item prefetch event.

I’d recommend architecting a profile-type list with separate section controllers for each grid item. You can use our IGListCollectionViewLayout to do this! In fact, that’s exactly how we do it in Instagram 😄

Sent with GitHawk

qhhonx commented 6 years ago

It is a feasible solution, but I think maybe it sounds tricky from a certain perspective.

As we known that IGListBindingSectionController is lightweight of IGListAdapter consisting of some IGListSectionControllers. It provides powerful IGListBindable so that we fully take advantage of MVVM architecture which can be integrated easily. Apart from its binding technique, It is natural that IGListBindingSectionController is used to display grid-items and ease to reuse not just single-item GridSectionController. I think IGListBindingSectionController can be adopt in many situations if we give it more capabilities like work-range as many as IGListAdapter already have.

So, if it is available I can try to contribute it.

rnystrom commented 6 years ago

Would be happy for the contribution! Might want a bit of a proposal written up at first though so that I can totally make sense of it.

Even for implementing grids, we recommend sticking to a single section controller per grid item so that you can fully encapsulate your data + business logic in the section controller. You can still enjoy all the benefits of MVVM w/ that design too!

brurend commented 6 years ago

@rnystrom I'm trying to implement a binding section controller with a working range as well but I couldn't figure it out how to prefetch each section controller. In my case its not a grid, its a feed with items similar to the binding section controller example.

zrxq commented 5 years ago

@rnystrom could you please elaborate a little on using a dedicated section controller per grid item? What do you think would be a a good way of implementing inter-item and line spacing for the entire grid in this case? How do you usually implement "line breaks" for grid item lines and what would be a good approach to somehow incapsulating a "whole grid behaviour" logic, like, showing a spinner in place of the grid during a fetch or collapsing/expanding content sections? Do you use some sort of SectionSectionController objects to manage, well, "logical" or content sections consisting of several UICollectionView sections? I understand that ListKit is mostly about the presentation/"view" part of the MVC and my questions are probably out of scope, still an advice would be much appreciated.