Skip to content

Commit

Permalink
Try harder in the Android backend to load images in the main (UI) thread
Browse files Browse the repository at this point in the history
  • Loading branch information
jstedfast committed Mar 24, 2023
1 parent 7601b0a commit e562fb6
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public MauiCustomViewTarget(@NonNull ImageView view, ImageLoaderCallback callbac

@Override
protected void onResourceCleared(@Nullable Drawable placeholder) {
this.view.setImageDrawable(placeholder);
post(() -> this.view.setImageDrawable(placeholder));
}

@Override
Expand All @@ -46,11 +46,13 @@ public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? s
return;
this.completed = true;

// set the image
this.view.setImageDrawable(resource);
post(() -> {
// set the image
this.view.setImageDrawable(resource);

// trigger the callback out of this target
post(() -> callback.onComplete(true, resource, this::clear));
// trigger the callback out of this target
callback.onComplete(true, resource, this::clear)
});
}

private void post(Runnable runnable) {
Expand Down

0 comments on commit e562fb6

Please sign in to comment.