Grouped CollectionView fires IndexOutOfBoundsException from MauiRecyclerView after second collapse/expand #23068
Labels
area-controls-collectionview
CollectionView, CarouselView, IndicatorView
p/2
Work that is important, but is currently not scheduled for release
platform/android 🤖
t/bug
Something isn't working
Description
In an Android / iOS MAUI application, one of my pages implements an expandable/collapsible CollectionView bound to an
ObservableCollection<ProtocolGroup>
. ProtocolGroup is an extension ofObservableRangeCollection<Protocol>
with properties for IsCollapsed, GroupName, and DropdownText (arrow-icon that changes on collapse). ProtocolGroup also implements INotifyPropertyChanged, for when IsCollapsed and DropdownText change. ObservableRangeCollection handles the notifications for AddRange() and Clear(), the methods I use to collapse/expand each group by removing or adding Protocol objects from the full list. I originally usedList<Protocol>
for the items in each group (more info in workaround section) but this results in the groups not animating on collapse/expand.I created a fresh repo (linked below) using only the classes necessary for this single CollectionView, and the issue persists. The primary
ObservableCollection<ProtocolGroup>
does not change after initialization (no groups are added/removed) and therefore I originally had it as aList<ProtocolGroup>
which resulted in the same exact behavior, so I Ieft it as an ObservableCollection in the attached repo.All groups begin collapsed and everything works at first. I can expand all the groups, and collapse all the groups. However, when I expand a group that has previously been collapsed (e.g the second expansion) an Java.Lang.IndexOutOfBoundsException: is thrown from the MauiRecyclerView (full error pasted below in the log output) and my application crashes. Since everything is in sync for the first expand/collapse, what could be going wrong afterwards?
Steps to Reproduce
Expected outcome: The group should expand again
Actual outcome: The exception in the log output is thrown and the application crashes
Link to public reproduction project repository
https://github.com/mattkeene/CollectionViewBugRepro
Version with bug
8.0.40 SR5
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android
Affected platform versions
Android 14.0 - API 34
Did you find any workaround?
By changing ProtocolGroup to be an extension of
List<Protocol>
which implements INotifyPropertyChanged and INotifyCollectionChanged, I can manually "new" the Clear() and AddRange() methods ofList<Protocol>
to call the base versions followed by calling RaiseCollectionChanged() and RaisedPropertyChanged() (on Count, Items[], and DropdownText) which invoke them, respectively. This results in functional collapsible/expandable groups without exceptions/crashes, BUT it does not animate the collapsing/expanding which hinders the user experience as the lists simply appear and disappear starkly. By usingObservableRangeCollection<Protocol>
, the expanding/collapsing is animated as expected, but crashes on second expand.Relevant log output
The text was updated successfully, but these errors were encountered: