Icons showing up in the wrong places when using StreamImageSource as a source for images inside a CollectionView #23240
Labels
area-controls-collectionview
CollectionView, CarouselView, IndicatorView
delighter
migration-compatibility
Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert
p/2
Work that is important, but is currently not scheduled for release
platform/android 🤖
s/triaged
Issue has been reviewed
s/verified
Verified / Reproducible Issue ready for Engineering Triage
t/bug
Something isn't working
Milestone
Description
We experienced some weird behavior when using a CollectionView to display items with a couple icons.
When scrolling through the CollectionView, we noticed some of the icons where displayed in the wrong place. For example, some icons were shown in locations that shouldn't display an icon at all.
We found out that this behavior only occurred on Android, when using a StreamImageSource. We weren't able to reproduce this issue on iOS and Windows, or when using a FileImageSource.
To make sure this wasn't because of our implementation, we managed to reproduce the issue in a simple Maui application, a linkt to this project is added below.
This is how it works:
We have a single page consisting of the CollectionView with a DataTemplate containing a couple labels and images:
The GestureRecognizer is to verify whether the tapped item should display a third icon or not.
The item that we are displaying is a simple object with a name, description and three file names. These file names are all strings and are used in the custom image control to load the image via a stream.
When the value of the CustomImageSource property is changed a task is queued to update the Source property of the image. This queue is added to make sure the sequence of tasks is always correct (we want to rule out that the issue we're having is due to timing). It is, however, still possible (maybe even easier) to reproduce this issue when not utilizing the queue. This is how we retrieve the image and update the Source:
The await is used to make it easier to reproduce the issue. When the source is updated fast enough, this becomes much harder.
Below is a recording of the issue (notice how the first three items shouldn't have a third icon):
Icon.issue.Android.Emulator.mp4
We're fairly certain this issue is a result of using a StreamImageSource in combination with the recycling mechanism of the CollectionView.
I'd also like to point out that this did work when we were still using Xamarin, we did however use the FFImageLoading library so that might have been the reason the issue wasn't present when using Xamarin.
Finally, at the time of writing we are using version 8.0.60, but this issue was also present in previous versions (we haven't tested all of them).
Steps to Reproduce
Link to public reproduction project repository
https://github.com/Leonardo-pixel/IconsTestApp
Version with bug
8.0.60 SR6
Is this a regression from previous behavior?
Yes, this used to work in Xamarin.Forms
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
No response
Did you find any workaround?
A work-around could be to use a FileImageSource instead, however in our actual application, we download the icons we want to display and having to convert these to a FileImageSource would result in a (probably big) performance hit.
Relevant log output
No response
The text was updated successfully, but these errors were encountered: