[iOS] Fix for the CollectionView to prevent duplicate groups or crashes when adding a new item to a group or when adding a new group.#24873
Conversation
|
Hey there @Tamilarasan-Paranthaman! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
Azure Pipelines successfully started running 3 pipeline(s). |
@rmarinho / @PureWeen, currently, To explain in more detail: when the This issue specifically arises when clearing the ItemsSource and immediately adding a group, as reported by the customer. However, the crash does not occur if these actions are performed individually. It seems that during a reset, we call Reload(true), which internally invokes _collectionView.LayoutIfNeeded() based on the boolean parameter. Similarly, an additional layout call may be required when adding a group immediately after clearing. The issue is resolved if we call _collectionView.LayoutIfNeeded, which can be achieved by using Reload(true) in the group-adding case as well. However, it seems that the InsertSections method of the CollectionView handles this. Therefore, I believe checking the NumberOfSections (which will be 0) is unnecessary in this scenario. I have resolved the issue by removing the Could you please share your thoughts on this approach? |
rmarinho
left a comment
There was a problem hiding this comment.
Thanks for the clarification, this solution looks good and addresses the root cause of the crash effectively. The explanation clearly outlines how the issue occurs, and removing the unnecessary ReloadRequired check when adding a group seems like a smart optimization.
This PR is good to go, and I approve it. Excellent work in identifying the underlying cause and providing a clear solution!
|
@Tamilarasan-Paranthaman |
|
/backport to release/8.0.1xx-sr9 |
|
Started backporting to release/8.0.1xx-sr9: https://github.com/dotnet/maui/actions/runs/11127580408 |
Root Cause:
1. Add item in the group:
2. Adding new group:
_collectionView.NumberOfSections() == 0to determine whether a reload was required, in conjunction with theNotLoadedYet()condition._collectionView.NumberOfSections()caused a crash when the collection view was empty and a new group was added, asNumberOfSections() == 0is always true for an empty collection. This check prevented the adding a new group.Description of Change:
1. Add item in the group:
2. Adding new group:
Validated the behaviour in the following platforms,
Issues Fixed
Fixes #17969
Fixes #20336
Screenshots
After Issue Fix
Screen.Recording.mov