Instagram / Instagram/IGListKit
Scrolling loses inertia when rendering more items from data source?
- Dominant language
- Objective-C
- Stars
- 13.1k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Description
## New issue checklist
- [x] I have reviewed the [`README`](https://github.com/Instagram/IGListKit/blob/master/README.md) and [documentation](http://instagram.github.io/IGListKit)
- [x] I have searched [existing issues](https://github.com/Instagram/IGListKit/issues) and this is not a duplicate
### General information
- `IGListKit` version:
- iOS version(s): 11.2
- CocoaPods/Carthage version: 3.2.0
- Xcode version: 9.2
- Devices/Simulators affected: All that I tested with: Phone 6 (device), iPhone X (device), iPhone SE (simulator)
- Reproducible in the demo project? (Yes/No): https://github.com/achan/hesijimbo-ios
- Related issues: Possibly similar to https://github.com/Instagram/IGListKit/issues/1004
### Debug information
```bash
# Please include debug logs using the following lldb command:
po [IGListDebugger dump]
```
I'm still new to IGListKit so forgive me if I have this all wrong.
In two separate apps, one developed by me and another developed by a co-worker, we've seen scrolling inertia abruptly stop when trying to load more items to our `UICollectionView` (a la infinite scroll).
They're both implemented similarly to [this](https://github.com/achan/hesijimbo-ios/blob/ae162d96fed545a6c2cef024b20c8d43027f157f/HesiJimbo/Video%20Feed/VideoFeedController.swift#L61-L66):
```swift
// VideoFeedController.swift
override func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer) {
let distance = scrollView.contentSize.height - (targetContentOffset.pointee.y + scrollView.bounds.height)
if !viewModel.isLoading && distance < 200 {
loadMore()
}
}
```
Where `loadMore()` is ultimately performing a network request, converting the request into `ListDiffable` view models, appending to the data source and telling the `adapter` to perform updates.
[`UICollectionViewController`](https://github.com/achan/hesijimbo-ios/blob/ae162d96fed545a6c2cef024b20c8d43027f157f/HesiJimbo/Video%20Feed/VideoFeedController.swift#L76-L86):
```swift
private func load(request: Promise) {
adapter.performUpdates(animated: true, completion: nil)
_ = request.done { [weak self] listing in
guard let strongSelf = self else {
return
}
strongSelf.adapter.performUpdates(animated: false, completion: nil)
strongSelf.refresher.endRefreshing()
}
}
```
[`View Model`](https://github.com/achan/hesijimbo-ios/blob/master/HesiJimbo/Video%20Feed/VideoFeedViewModel.swift#L24-L36):
```swift
@discardableResult
func loadMore() -> Promise {
isLoading = true
return service.perform(pagination: pagination).done { [weak self] listing in
self?.loaded(listing: listing)
}
}
private func loaded(listing: VideoFeedListing) {
isLoading = false
items.append(contentsOf: listing.items)
pagination = listing.pagination
}
```
I've played around with moving loadMore() to a background thread with similar outcome, though I believe network requests from URLSessionDataTask do that automatically?
Here's a screen capture of the bug in action. I've added a print statement for emphasis.

Thanks for your time and all the hard work on this library 👏
Contributor guide
Research direction
Reproduce the scrolling behavior in the linked HesiJimbo demo, starting at VideoFeedController.swift and its scrollViewWillEndDragging and load methods. Trace the interaction between loadMore(), the view model's item append, and adapter.performUpdates; compare with related issue #1004. Done means infinite scrolling adds items without abruptly stopping UICollectionView scrolling inertia.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ios, swift
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100