Skip to content

Commit

Permalink
Possible fix for #353
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-luberda committed Nov 3, 2016
1 parent 57c769d commit cbfa335
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions source/FFImageLoading.Droid/Drawables/FFBitmapDrawable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class FFBitmapDrawable : SelfDisposingBitmapDrawable
bool animating;
int alpha = 255;
float fadeDuration = 200;
float normalized = 1f;

public FFBitmapDrawable(Resources res, Bitmap bitmap) : base(res, bitmap)
{
Expand Down Expand Up @@ -57,6 +58,7 @@ public void SetPlaceholder(BitmapDrawable drawable, int animationDuration)
{
if (!animating)
{
normalized = 0f;
alpha = 255;
fadeDuration = animationDuration;
startTimeMillis = SystemClock.UptimeMillis();
Expand All @@ -81,16 +83,17 @@ public override void Draw(Canvas canvas)
{
if (!animating)
{
normalized = 1f;
base.Draw(canvas);
}
else
{
float normalized = (SystemClock.UptimeMillis() - startTimeMillis) / fadeDuration;
normalized = (SystemClock.UptimeMillis() - startTimeMillis) / fadeDuration;
if (normalized >= 1f)
{
animating = false;
placeholder = null;
normalized = 0f;
normalized = 1f;
base.Draw(canvas);
}
else
Expand Down Expand Up @@ -122,7 +125,7 @@ public override int IntrinsicHeight
{
try
{
if (animating && IsBitmapDrawableValid(placeholder))
if (animating && normalized < 0.8f && IsBitmapDrawableValid(placeholder))
{
return placeholder.IntrinsicHeight;
}
Expand All @@ -139,7 +142,7 @@ public override int IntrinsicWidth
{
try
{
if (animating && IsBitmapDrawableValid(placeholder))
if (animating && normalized < 0.8f && IsBitmapDrawableValid(placeholder))
{
return placeholder.IntrinsicWidth;
}
Expand Down

0 comments on commit cbfa335

Please sign in to comment.