Instagram / IGListKit

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

Scrolling offset might be wrong when scrolling backwards using scrollToObject: method #1239

Open darko55s opened 6 years ago

darko55s commented 6 years ago

New issue checklist

General information

Debug information

Hi, i am using IGListKit with supplementaryHeaderViews but i am facing an issue when i want to use the scrollToObject: method inside the adapter. When the visible sections are greater then the one that i want to scroll to it scrolls to the correct object but the sections are not fully visible.

You can reproduce the issue in one of the Demo Projects, the one for the Supplementary Views if you scroll to bottom manually but add scroll to index 0 to be executed after some delay. I am using the following code:

let item = feedItems[0]
DispatchQueue.main.asyncAfter(deadline: .now()+5) {
   self.adapter.scroll(to: item, supplementaryKinds: [UICollectionElementKindSectionHeader, UICollectionElementKindSectionFooter], scrollDirection: .vertical, scrollPosition: .top, animated: true)
 }

Am i doing something wrong or the contentOffset calculations is bad.

Thank you !

rnystrom commented 5 years ago

@darko55s what is the actual bug? Have you done any digging into this?

darko55s commented 5 years ago

Hey @rnystrom, sorry for late response, the is issue is that the scrollToObject is not calculating the height of the supplementaryHeaderViews. So when you do scrollToObject on a section that is not visible(when it need to scroll backwards) the first cell of the sectionController is not fully visible. The part that is not visible has the exact height as the supplementaryHeaderView height.

Also the same happens when you use scrollToSectionController: on the collectionContext object. It scrolls to the correct section and index but the visible area of the topmost cell is cut by the supplementaryHeaderView.

P.S. The supplementaryHeaderView are sticky i am using this : let collectionView = UICollectionView(frame: .zero, collectionViewLayout: ListCollectionViewLayout(stickyHeaders: true, topContentInset: 0, stretchToEdge: true))

iperry90 commented 4 years ago

I'm able to reproduce this. Will look into a fix.

Annastaciahubbard commented 4 years ago

I will look into it as well