XF CustomRenderer and FFImageLoading
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);
}
}
Hi @patook,
Did you try replacing (e.NewElement != null) with (Control != null) call?
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
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 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.
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?
@patook Does it still apply to the newest prerelease?
Please reopen if you still experience it (try newest prerelease nuget). Thanks.