-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug when a section reload is queued while batch updating #288
Comments
@rnystrom should we get this in 2.0 or release a 2.0.1 ? |
@jessesquires let's do 2.0.1, pretty difficult/odd setup to get this to happen, and we've never seen it in IG, so I think we can take some time to do this one right. |
@rnystrom, Hi. I'm trying to implement a chat using IGListKit. Messages should be grouped by date. My app fetches messages' batches from a server side while a user scrolls the chat. So, I use Sometimes, if a user scrolls very fast my app will crash.
My investigation shows, actually 4 step was not executed. New cells were not inserted in UICollectionView. And on the 5 step I get a crash, because of I try insert a new batch, but UICollectionView doesn't about previously "added" batch. Otherwise, if a user scrolls slow, everything works. I think the reason is a time interval between steps 3 and 4 is longer in that case. If I invoke |
@vldalx that sounds like it might be a separate issue. I'd love if you could:
Sounds like you might have found something really interesting! |
I discovered this working on my sample weather app. Here's the conditions that I noticed to reproduce this:
Dispatch.async { ... }
insidedidUpdate(to object:)
collectionContext.reload(section: self)
Result: reload will never be called.
This is because
-[UICollectionView performBatchUpdates:completion:]
, is asynchronous in that it executes over several runloop turns (aggregation and animations).We use a flag to monitor when batch updating, setting it to YES before we enter the update block, then setting it to NO in the completion block of
performBatchUpdates:completion:
.If a reload is added while this flag is set to
YES
, we assume it is part of unloading our blocks of batched operations.The problem is anyone can queue a reload from anywhere. When the current batch updates finish, we queue another update to clear anything we might have collected in the meanwhile. However before we update we check if
hasChanges
is true.Unfortunately the bug lies in that we don't check reloads in
hasChanges
.Some options for fixing:
self.reloadSections.count > 0
inhasChanges
batchUpdateOrReloadInProgress
with a "mode" enum to model states ofperformBatchUpdates:completion:
:The latter is a more thorough solution and probably better in the long run given some of the plans I have for how batch operations are handled.
The text was updated successfully, but these errors were encountered: