pronebird / UIScrollView-InfiniteScroll

UIScrollView ∞ scroll category
MIT License
1.06k stars 148 forks source link

Infinite Scroll not triggered with small number of items #2

Closed TheGeekPharaoh closed 9 years ago

TheGeekPharaoh commented 9 years ago

We're using your control to pull data down from a web service using a date range and display them in a UICollectionView. We've noticed that if we only have a small number of items (small enough that they all fit on the screen with no need to scroll) scrolling down to the bottom of the page does not trigger an infinite scroll event the way it would if we had a large number of items. The event is never started, so our infinite scroll handler block is not called to grab the next set of items in the next date range.

Any idea how we can go about fixing this? Ideally, if the scroll bounces to the bottom of the scroll view we'd like to have the infinite scroll handler kicked off.

TheGeekPharaoh commented 9 years ago

To reproduce the issue we're seeing, simply change this line in the demo:

NSInteger hitsPerPage = ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) ? 12 : 24;

...to...

NSInteger hitsPerPage = ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) ? 4 : 4;

You'll see that the scroll view bounces but the infinite scroll handler is never called.

pronebird commented 9 years ago

I see what you mean. There is a lot of logic built around contentSize. I guess it would do the trick if we used view.bounds when contentSize is small enough to contain all items inside.

TheGeekPharaoh commented 9 years ago

That would be a lifesaver if you could get that implemented!

pronebird commented 9 years ago

There is one edge case. If I remove test for content height, then infinite scroll triggers even if there is no content at all. This may happen for example when you load the first batch of data.

pronebird commented 9 years ago

Would you like to pull the following patch: https://github.com/pronebird/UIScrollView-InfiniteScroll/commit/4b067afc54f91a20e062f0508cc89dae3759a922 and see if it works for you?

I haven't tested on UICollectionView but it works fine on demo app with UITableView.

TheGeekPharaoh commented 9 years ago

I'll give it a try and let you know if it works!

TheGeekPharaoh commented 9 years ago

It worked perfectly! Thanks so much!

pronebird commented 9 years ago

This has been re-fixed once again and now it works smoother.