FFImageLoading icon indicating copy to clipboard operation
FFImageLoading copied to clipboard

XF CustomRenderer and FFImageLoading

Open patook opened this issue 10 years ago • 7 comments

Hi I am running into a problem when using ImageViewAsync within a custom renderer. Could you provide some guidance?

The images get loaded correctly the first time, but then fail to render when they are loaded from cache. Here is the gist of it - any ideas?

public class VisitorViewCustomRenderer : ViewRenderer<MyPage.VisitorView, Android.Widget.LinearLayout> { ImageViewAsync ProfilePicture;

    protected override void OnElementChanged(ElementChangedEventArgs<MyPage.VisitorView> e)
    {
        base.OnElementChanged(e);

        if (Control == null)
        {
            ProfilePicture = new ImageViewAsync(Context) { ScaleToFit = true };
            ProfilePicture.LayoutParameters = new LinearLayout.LayoutParams((int)(105 * Resources.DisplayMetrics.Density), LayoutParams.MatchParent);

[...] TotalPanel = new LinearLayout(); TotalPanel.AddView(layoutPanel); SetNativeControl(TotalPanel); }

        if (e.NewElement != null)
        {                       ImageService.Instance.LoadUrl(e.NewElement.ImageSource).Into(ProfilePicture);
        }
    }

patook avatar Oct 30 '16 04:10 patook

Hi @patook,

Did you try replacing (e.NewElement != null) with (Control != null) call?

daniel-luberda avatar Oct 31 '16 08:10 daniel-luberda

Hi @daniel-luberda I just did. Same problem.

Whenever the image is served from cache it appears as an empty box. When it is not it shows up.

I'll mention CachedImage works fine for me on regular Xamarin Forms

patook avatar Oct 31 '16 17:10 patook

I don't have a clue what that might be.

  • Did you try to disable memory cache? ImageService.Instance.LoadUrl(e.NewElement.ImageSource).WithCache(Cache.CacheType.Disk).Into(ProfilePicture);? Does it work like that?
  • Did you try to call Control.Invalidate() after loading cache from memory?
  • Could you make a reproduction?

daniel-luberda avatar Nov 03 '16 01:11 daniel-luberda

@daniel-luberda I have created and attached a very simple repro case (only 20 lines or so).

Please click the button twice and you'll see that when the images are loaded from memory they stop rendering.

I noticed that setting ScaleToFit=true is one of the things that breaks it but I believe there are others.

SimpleFFCustomRenderer.zip

patook avatar Nov 03 '16 03:11 patook

ScaleToFit is an ImageViewAsync specific method. This is the code which is responsible for its functionality: https://github.com/luberda-molinet/FFImageLoading/blob/master/source/FFImageLoading.Droid/Views/ImageViewAsync.cs#L89-L145

Do you see anything wrong there?

daniel-luberda avatar Nov 09 '16 20:11 daniel-luberda

@patook Does it still apply to the newest prerelease?

daniel-luberda avatar Dec 28 '16 19:12 daniel-luberda

Please reopen if you still experience it (try newest prerelease nuget). Thanks.

daniel-luberda avatar Jan 02 '17 18:01 daniel-luberda