dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.83k stars 1.67k forks source link

Returning UIImage in custom ImageSourceService doesn't trigger an UI update #13490

Open roubachof opened 1 year ago

roubachof commented 1 year ago

Description

Hi there !

https://github.com/roubachof/Maui.Nuke has a weird issue when returning a valid UIImage with ImageSourceServiceResult. It doesn't seem to trigger the display of the image right away... But if you force the layout to refresh, the UIImage renders correctly.

I'm plugging into Image service architecture in order to use ImageCaching.Nuke nuget (which is a swift binding).

public static class ImageSourcesMauiAppBuilderExtensions
{
    public static MauiAppBuilder UseNuke(this MauiAppBuilder builder, bool showDebugLogs = false)
    {
#if __IOS__
        NukeController.ShowDebugLogs = showDebugLogs;
        builder.ConfigureImageSources(services =>
        {
            services.AddService(
                svcs => new NukeFileImageSourceService(
                    svcs.GetService<ILogger<FileImageSourceService>>()));

            services.AddService(
                svcs => new NukeUriImageSourceService(
                    svcs.GetService<ILogger<UriImageSourceService>>()));

            services.AddService<FileImageSource>(
                svcs => new NukeFileImageSourceService(
                    svcs.GetService<ILogger<FileImageSourceService>>()));

            services.AddService<UriImageSource>(
                svcs => new NukeUriImageSourceService(
                    svcs.GetService<ILogger<UriImageSourceService>>()));
        });
#endif
        return builder;
    }
}

Steps to Reproduce

  1. Create new MAUI app with the default template
  2. Clone https://github.com/roubachof/Maui.Nuke next to your app
  3. Reference Maui.Nuke csproj in your app
  4. Initialize Nuke as described in Maui.Nuke
  5. put a breakpoint in https://github.com/roubachof/Maui.Nuke/blob/d8682d833abd7cd6bafb2e82e46e5e72d3823b47/Maui.Nuke/NukeFileImageSourceService.cs#L105
  6. You will see UIImage is not null and valid, but you won't see the bot displayed
  7. If you click the button, image appears

Link to public reproduction project repository

https://github.com/roubachof/Maui.Nuke

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS

Did you find any workaround?

nope

Relevant log output

nothing here
ghost commented 1 year ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

vhugogarcia commented 1 year ago

I'm facing this issue as well on iOS.

@PureWeen do you know if this can be fixed by using a custom handler in .NET MAUI somehow? 🤔

Thanks in advance

vhugogarcia commented 1 year ago

Maybe this can improve performance a lot for Maui in iOS when rendering images lots os images in a collection view or bindable layout. @jonathanpeppers what do you think? Maybe integrate it natively on MAUI?

Thank you

homeyf commented 7 months ago

Verified this issue with VSM 17.6.7 (build 417). Can repro on ios platform.

roubachof commented 5 months ago

Just tested with .net8 MAUI, and still failing

vhugogarcia commented 5 months ago

https://github.com/roubachof/Maui.Nuke

Hello @roubachof , I'm wondering if you had opportunity to review my comment here on how I solved the issue for my project: https://github.com/roubachof/Maui.Nuke/issues/2#issuecomment-1555198169 in .NET 7+

I'm not sure if that will solve the issue 100% but just wanted to share my grain of salt 😃 .

Regards

roubachof commented 5 months ago

I tested it with .net 7 and .net 8, same issue