question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(Android) LoadingImage not replaced when (image)Stream received from server on CachedImage

See original GitHub issue

Hi…,

I’ve a bug to be reported, in a specific situation. We build Xamarin.Forms Apps and we use MAM for this application and it is not allowed to use the default HttpClient by GOOD(GD).

GD have its own GDHttpClient we have to use to retrieve images and other date from within our own domain. We have created our own GDFFCachedImage based on the FFImageLoading.Forms.CachedImage like this:

public class GDFFCachedImage : FFImageLoading.Forms.CachedImage
{
    public static readonly BindableProperty GDImageSourceProperty =
    BindableProperty.Create<GDFFCachedImage, string>(p => p.GDImageSource, "");

    //Gets or sets the source of the GD Image
    public string GDImageSource
    {
        get { return (string)GetValue(GDImageSourceProperty); }
        set { SetValue(GDImageSourceProperty, value); }
    }

    protected override void OnBindingContextChanged()
    {
        base.OnBindingContextChanged();

        // When bound, stream in the Image via GenericHttpHandler
        Source = new StreamImageSource()
        { 
            Stream = async (token) => await Task.Run(() => ServiceLocator.Instance.Resolve<IGenericHttpHandler>().GetStreamAsync(this.GDImageSource))
        };  
    }
} 

In our Xaml View we bind the GDImageSource to our internal server URL. The OnBindingContextChanged event makes sure the GDHttpClient is used on Platform specific deployments.

The used ViewCell is created from class like this:

public class PersonViewCell : ViewCell
{
    public PersonViewCell()
    {
        var image = new GDFFCachedImage()
        {
            WidthRequest = 40,
            HeightRequest = 40,
            DownsampleHeight = 40,
            DownsampleUseDipUnits = true,
            TransparencyEnabled = false,
            Aspect = Aspect.AspectFill,
            CacheDuration = TimeSpan.FromDays(1),
            LoadingPlaceholder = "AvatarLoading.png",
            Transformations = new List<ITransformation>() {
                new CircleTransformation(5,"#000000"),
            }
        };
        image.SetBinding<Person>(GDFFCachedImage.GDImageSourceProperty, v => v.AvatarURL);

        var fullName = new Label()
        {
            LineBreakMode = LineBreakMode.CharacterWrap,
            VerticalTextAlignment = TextAlignment.Center,
            HorizontalTextAlignment = TextAlignment.Start,
            FontSize = 17
        };
        fullName.SetBinding<Person>(Label.TextProperty, v => v.FullName);

        var organization = new Label()
        {
            LineBreakMode = LineBreakMode.CharacterWrap,
            VerticalTextAlignment = TextAlignment.Center,
            HorizontalTextAlignment = TextAlignment.Start,
            FontSize = 15
        };
        organization.SetBinding<Person>(Label.TextProperty, v => v.Organization);

        var root = new AbsoluteLayout()
        {
            HorizontalOptions = LayoutOptions.FillAndExpand,
            VerticalOptions = LayoutOptions.FillAndExpand,
            Padding = 5,
        };

        root.Children.Add(image, new Rectangle(0f, 0f, 40f, 40f));
        root.Children.Add(fullName, new Rectangle(45f, 0f, 200f, 20f));
        root.Children.Add(organization, new Rectangle(45f, 20f, 200f, 20f));
        View = root;
    }
}

This implementation works flawless on iOS!!! But on Android the Loading image is not being refreshed/replaced when the image stream is received from our server. When not using GD and the default HttpClient. It does work…

Additional information: FFImageLoading : 2.1.7 Xamarin.Forms : 2.2.031 Build target Android : API 23 Min. Android Version : API 15 (upgrade to API 21 also does solve this issue)

Any help please… 😃

Jeffrey Klink Logeman

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
daniel-luberdacommented, Oct 27, 2016

The newest alpha has some new configuration options, you can easily provide your own IDownloadCache implementation to replace whole download logic. It’s a very simple interface with two methods to implement.

0reactions
klingucommented, Sep 25, 2016

@daniel-luberda Not yet… had no time to look into it because of Go-Live… Looking into it ASAP next sprint 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Universal Image loader not refresh image if changed from ...
I have used Universal Image Loader for load image from a server and also getting cached it into memory for fast loading. But...
Read more >
Loading images | Jetpack Compose
Load an image from the disk. Use the Image composable to display a graphic on screen. To load an image (for example: PNG,...
Read more >
How applications access and use the image service cache ...
A cached image service can behave as either a static or dynamic image service.
Read more >
[Solved]-Flutter not loading Image from Localhost-Flutter
i set the base url on flutter app as my local computer ip first then when i get url image from server i...
Read more >
Image - .NET MAUI
The .NET MAUI Image displays an image that can be loaded from a local file, a URI, or a stream.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found