Skip to content
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

Grouped CollectionView fires IndexOutOfBoundsException from MauiRecyclerView after second collapse/expand #23068

Closed
mattkeene opened this issue Jun 14, 2024 · 3 comments
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

Comments

@mattkeene
Copy link

mattkeene commented Jun 14, 2024

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 of ObservableRangeCollection<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 used List<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 a List<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

  1. Run the repo on an Android simulator or device
  2. Tap a few groups to expand
  3. Tap them again to collapse
  4. Tap any one you manually collapsed

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 of List<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 using ObservableRangeCollection<Protocol>, the expanding/collapsing is animated as expected, but crashes on second expand.

Relevant log output

**Java.Lang.IndexOutOfBoundsException:** 'Inconsistency detected. Invalid view holder adapter positionTemplatedItemViewHolder{cf38be1 position=37 id=-1, oldPos=17, pLpos:17 scrap [attachedScrap] tmpDetached no parent} crc645d80431ce5f73f11.MauiRecyclerView_3{efa7858 VFED..... ......ID 0,0-1080,2054}, adapter:crc645d80431ce5f73f11.ReorderableItemsViewAdapter_2@2f947d2, layout:androidx.recyclerview.widget.LinearLayoutManager@3a8a788, context:crc642c18c1b741c10a87.MainActivity@de5472c'
@mattkeene mattkeene added the t/bug Something isn't working label Jun 14, 2024
Copy link
Contributor

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@PureWeen PureWeen added platform/android 🤖 p/2 Work that is important, but is currently not scheduled for release area-controls-collectionview CollectionView, CarouselView, IndicatorView labels Jun 15, 2024
@PureWeen
Copy link
Member

Duplicate of #20819

@PureWeen PureWeen marked this as a duplicate of #20819 Jun 15, 2024
@mattkeene
Copy link
Author

mattkeene commented Jun 18, 2024

For anyone that comes to this after the fact, a temporary workaround until the component is fixed is use while (groupToCollase.Count > 0) groupToCollapse.RemoveAt(0) in place of groupToCollapse.Clear() until the group is empty. It slows the application down because of all the extra events, but it avoids crashing. This is only needed on Android.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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
Projects
None yet
Development

No branches or pull requests

3 participants