-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this shifts the problem a little bit, if the REloadRequired is still called it will crash. Should we instead of checking the NumberofSections of the CollectionView can we try look at the ItemsSource Count ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() == 0
to 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() == 0
is 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