Skip to content

Commit

Permalink
Don't let Glide clear the old image on Android ImageView unless we ge…
Browse files Browse the repository at this point in the history
…t an error
  • Loading branch information
albyrock87 committed Jun 27, 2024
1 parent 45a8686 commit 85bc395
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,32 @@
public class MauiCustomViewTarget extends CustomViewTarget<ImageView, Drawable> {
private final ImageLoaderCallback callback;
private boolean completed;
private boolean cleared;

public MauiCustomViewTarget(@NonNull ImageView view, ImageLoaderCallback callback) {
super(view);

this.completed = false;
this.cleared = false;
this.callback = callback;
}

@Override
protected void onResourceCleared(@Nullable Drawable placeholder) {
this.view.setImageDrawable(placeholder);
this.cleared = true;
}

@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
if (completed)
return;

this.completed = true;

if (this.cleared) {
this.view.setImageDrawable(null);
}

// trigger the callback out of this target
post(() -> callback.onComplete(false, errorDrawable, this::clear));
}
Expand All @@ -44,6 +51,7 @@ public void onLoadFailed(@Nullable Drawable errorDrawable) {
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
if (completed)
return;

this.completed = true;

post(() -> {
Expand Down
Binary file modified src/Core/src/maui.aar
Binary file not shown.

0 comments on commit 85bc395

Please sign in to comment.