Skip to content

Commit

Permalink
Fixes #536 - Android fade animation doesn't work when loading from ca…
Browse files Browse the repository at this point in the history
…che and no placeholder is set
  • Loading branch information
daniel-luberda committed Sep 30, 2017
1 parent ad60783 commit f90b5da
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions source/FFImageLoading.Droid/Extensions/DrawableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,10 @@ public static bool IsValidAndHasValidBitmap(this ISelfDisposingBitmapDrawable dr
{
return drawable != null && drawable.Handle != IntPtr.Zero && drawable.HasValidBitmap;
}

public static bool IsValidAndHasValidBitmap(this SelfDisposingBitmapDrawable drawable)
{
return drawable != null && drawable.Handle != IntPtr.Zero && drawable.HasValidBitmap;
}
}
}
12 changes: 11 additions & 1 deletion source/FFImageLoading.Droid/Work/PlatformImageLoadingTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using FFImageLoading.Extensions;
using FFImageLoading.Helpers;
using FFImageLoading.Work;
using FFImageLoading.Views;

namespace FFImageLoading
{
Expand Down Expand Up @@ -51,7 +52,16 @@ protected async override Task SetTargetAsync(SelfDisposingBitmapDrawable image,
if (animated)
{
SelfDisposingBitmapDrawable placeholderDrawable = null;
if (PlaceholderWeakReference != null && PlaceholderWeakReference.TryGetTarget(out placeholderDrawable) && placeholderDrawable != null)
PlaceholderWeakReference?.TryGetTarget(out placeholderDrawable);

if (placeholderDrawable == null)
{
// Enable fade animation when no placeholder is set and the previous image is not null
var imageView = PlatformTarget.Control as ImageViewAsync;
placeholderDrawable = imageView?.Drawable as SelfDisposingBitmapDrawable;
}

if (placeholderDrawable.IsValidAndHasValidBitmap())
{
int fadeDuration = Parameters.FadeAnimationDuration.HasValue ?
Parameters.FadeAnimationDuration.Value : Configuration.FadeAnimationDuration;
Expand Down

0 comments on commit f90b5da

Please sign in to comment.