-
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
Changing image source on Android causes flicker between images #6625
Comments
Verified repro on Android 12.0 with VS 17.3.0 Preview 1.0 [32427.455.main]. Repro with above project. |
This could also be fixed with #6898 |
I just tried it with the most recent maui.aar and the flicker is somewhat better. But there is still a distinct gap between the old image and the new image, i.e. a noticeable flicker. In Preview 14 there is none. I will note, however, that the sample code above is not completely representative of my actual code. I'm going to say the sample code should probably still not flicker at all but my actual code calls LoadImage on the ImageSource and actually sets the Source property on the Image control during the callback. My interpretation of the LoadImage method was that the callback was called when the image was actually fetched and decoded so that display would be immediate. As I mentioned, this works exactly as I expect in Preview 14 but still flickers with the maui.aar from #6898. Also, this observation is predicated on the premise that I grabbed the correct maui.aar. I'm pretty sure I copied it to the right place since images started appearing after I copied the new one but I'm not sure how to determine if what I grabbed actually has #6898 in it. Edit: I just checked the history of maui.aar and it appears to include #6898 so the flicker does still seem to be there. |
The reason for the gap is because we actually clear out the old image when assigning a new one. Not sure if that is desired behaviour for general apps or not. There are a few scenarios:
There may be more, but what should the correct way be? Should we have an API that allows the developer to decide? Is there an example of this type of API out in the wild and regardless of frameworks or language, what do other frameworks do? I am wondering if this should/could be done with 2 image views and having the one mage loaded even trigger a swap between the two? So by default clear, but the smooth way is to actually load the image into an invisible image view? Is that better? Is that worse? |
Is there any insight on what changed from Preview 14 to RC1 and why it changed behavior? |
I am not sure why... Seems we always cleared the old image since the very first image support: https://github.com/dotnet/maui/pull/759/files#diff-13df83e905abc59530f995480e58f3532792e1c248818fa2f29b3eeaa358d0c3R46 However both @PureWeen reworked the images as well as @Redth moved more code into Java land. I did test your code in the issue and I still see flickering - but only at the start and then once all the images are cached, it goes away. When I remove the code to clear the image before loading the new one, I do actually see a noticeable difference and no flickering at all. Same with Windows. So, why do we clear the image? I have no idea and it seemed correct at the time because why would you want some old image in there? Well, to not make the UX terrible. I'll do a PR on not-clearing and we can see. |
Thanks for the persistence. |
Unfortunately, the nature of the app I'm working on pretty much guarantees the images will never be cached. I just used the tumblr images to demonstrate the flickering. In reality, the app fetches images from a very large pool so it's very likely they'd have been dumped from the cache long before they ever came up again. |
Description
I have an Image control and I periodically set the source to a new Uri image. This worked perfectly (on Android...don't get me started on Windows) in Preview 14. It was completely broken by RC1 and then partially sort of fixed by #6394 and then more fixed in #6543. However, the image still flickers, i.e., goes black for a short time, maybe a quarter second or so, when the image source is set to a new Uri.
I just noticed in a test app that when the images are cached, i.e., have already been loaded and displayed once, there is no flicker. Unfortunately, my app is fetching a series of hundreds and sometimes thousands of images so the images will literally never be cached.
Again, in Preview 14 there was no flickering at all.
Steps to Reproduce
MainPage.xaml:
MainPage.xaml.cs:
Version with bug
Release Candidate 3
Last version that worked well
Preview 14
Affected platforms
Android
Affected platform versions
Seeing it on Android 11
Did you find any workaround?
No workaround was found. I tried performing ImageSource.LoadImage and setting the image source in the callback (which is what I was doing in Preview 14) but that didn't appear to help.
Relevant log output
The text was updated successfully, but these errors were encountered: