Conversation
bryankeller
left a comment
There was a problem hiding this comment.
Thanks for the change! It would be helpful if a repro case for this bug was provided. Would this be easy to provide?
One other question: would it be simpler to just not update the layout metrics for existing sections if we're recreating them from scratch anyways? Maybe the change is even simpler:
// Update layout metrics if necessary
if prepareActions.contains(.updateLayoutMetrics) {
...becomes
// Update layout metrics if necessary
if !prepareActions.contains(.recreateSectionModels), prepareActions.contains(.updateLayoutMetrics) {
...Let me know if this works. And if you can provide a repro-case, that would be really helpful so I can better-understand what application behavior triggers this.
|
Apologises for the slow reply, unfortunately I did not get my manager's approval to provide a repro case or a video about our project, apart from what I can share here :
I can confirm that your suggested changes does indeed fix the issue as well, so I guess this PR can be cancelled if you guys do push your suggested change instead. |
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