Fix reloading after sections updates #140
Open
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.
Details
The CollectionView reload is triggered by this func from the MagazineLayout Library :
If we follow that call it comes from the override public func prepare() here :
The prepareActions is a bit field, and you check for updateLayoutMetrics (which triggers the updates) and just bellow that highlighted line of code on the screenshot the following condition checks for recreateSectionModels which are both set to true in our situation.
The fix
The recreateSectionModels code should be called before updateLayoutMetrics if recreateSectionModels is set to true because there is no need to update the sections if we are going to recreate them anyway right after the update.
Related Issue
We have a very old crash that is occurring on our main iPad app.
The crash happens following these steps :
-> CRASH
It crashes because there is more sections on the Home Page when the user is logged (34 sections) in compared to when the user is logged out (28 sections), some sections are based on the user's preferences and his content, like recommended, suggested...).
The current code implementation tries to update the existing sections and an out of bounds crash will occur because the number of sections logged out are inferior and it will attempt to update a section that just doesn't exist.
Motivation and Context
The current behaviour is the following :
This fix just swap the 2 steps, check for recreation first and then for updates.
How Has This Been Tested
The reproducibility of this crash was 100% in our situation (following steps detailed up here).
Tested on :
Types of changes
Checklist