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

CollectionView on android in tab view and shell tabs does not clear when refreshing items bound to ItemsSource #117

Open
jjelecondev opened this issue Apr 23, 2024 · 5 comments

Comments

@jjelecondev
Copy link

  • OS: Android
  • Device: Pixel 4/5 (confirmed) but assuming others
  • Sdk vervion: [Android 13/API 34]
  • Maui with .net 8

Describe the bug
When CollectionView is displayed the first time, a ObservableCollection.Clear() followed by adding new items to the collection results in the view correctly refreshing. If the user navigates to another page in the tab view then back, the same action will cause the new items to prepend in the list and the "cleared" items never clear. We have found a similar problem with drop no longer working when navigating away and back.

In the attached repository, we are using multiple DataTemplates with a TemplateSelector.

To Reproduce

  1. run the example on android,
  2. navigate to page 2
  3. then back to page 1
  4. swipe down to refresh.

Exceptions (if applicable)
None found. Just doesn't clear old items

Screenshots (if applicable)
If applicable, add screenshots to help explain your problem.

@roubachof
Copy link
Owner

I tried to test the sample for a couple of hours but weird stuff happens:

  1. I cannot hit any breakpoint in the collection view renderer
  2. the binding on RefreshView seems broken (spinner spin forever)

I don't know if shell is broken or semothing....
Otherwise you could still try to create new collection instead of clearing it:

Feed.Clear() => Feed = new ObservableCollection<FeedItem>();

Oh and also you are misusing the refresh UI pattern, you should only clear the collecton if the reload if successful, cause if it's not (for example connection loss) you will end up with an empty list...

@jjelecondev
Copy link
Author

jjelecondev commented Apr 24, 2024 via email

@jjelecondev
Copy link
Author

I committed an update that may fix your debug problems. (there was a remnant of a non-existent stylesheet that appeared to be causing problems)

I also found this:
If I set the property AutoDisconnectHandler="False" in the xaml, the view appears to work correctly! What is this option supposed to do? Is this going to cause a memory leak or something if I set it to false?

@roubachof
Copy link
Owner

roubachof commented Apr 24, 2024 via email

@jjelecondev
Copy link
Author

jjelecondev commented Apr 24, 2024

Well this is good to know. I guess we can take note that android seems to have an issue on a persistent shell tab when navigating away and back when this option is set to true. I will leave it to you to decide whether it deserves a code fix.
Thanks for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants