Remember offset of collection views during table view reload to avoid jitter #5959
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #5958
There are a number of reasons why the home screen keeps jitterring (especially with lots of data), but fundamentally they have to do with:
To expand on this, home screen table view contains row items, which themselves contain individual collection views. When we reload the table view, the usual data source methods for creating a cell will be called, which creates any given collection view by dequeing it from the table view's pool. This means that if there are multiple collection views, they may be arbitrarily and randomly swapped around and repurposed for different sections, whilst not resetting their content offset. This, I think, is one major downside to nesting table views and collection views (note, this isn't an issue with nested scrollviews).
We could simply reset content offset each time
prepareForReuse
is called (and this is indeed added now), but this on its own is not enough, given the frequency of home screen reloads (on heavy accounts this happens 20-30 times per second). The outcome of this change only would be constant resetting of each collection view to its start, i.e. another inability to scroll.Whilst a more thorough refactor of the data source and frequency of refreshes is necessary (and will be done as part of #5619), the solution presented here will store current content offsets for each collection view before a table view is reloaded, and then restored immediately afterwards. Whilst we are still refreshing far too many times, and collection views are randomly getting swapped around, at least it should not be visually jarring anymore.
A more thorough refactor of the data source will follow.