Skip to content

Commit

Permalink
Update image source after recycling bitmap in custom target (#12310)
Browse files Browse the repository at this point in the history
Fixes #11519
  • Loading branch information
hartez committed Dec 28, 2022
1 parent a639458 commit de692d4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public MauiCustomViewTarget(@NonNull ImageView view, ImageLoaderCallback callbac

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

@Override
Expand Down Expand Up @@ -57,10 +58,10 @@ private void post(Runnable runnable) {
}

private void clear() {
post(() -> {
//post(() -> {
// TODO: Explicitly release image
// https://github.com/dotnet/maui/issues/6464
// https://github.com/dotnet/maui/pull/6543
});
//});
}
}
Binary file modified src/Core/src/maui.aar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,28 @@ namespace Microsoft.Maui.DeviceTests
{
public partial class ImageHandlerTests<TImageHandler, TStub>
{
[Fact]
public async Task UpdatingSourceWorks()
{
var image = new TStub
{
Background = new SolidPaintStub(Colors.Black),
Source = new FileImageSourceStub("red.png"),
};

await InvokeOnMainThreadAsync(async () =>
{
var handler = CreateHandler<CountedImageHandler>(image);
await image.Wait();
await handler.PlatformView.AssertContainsColor(Colors.Red);
image.Source = new FileImageSourceStub("blue.png");
handler.UpdateValue(nameof(IImage.Source));
await image.Wait();
await handler.PlatformView.AssertContainsColor(Colors.Blue);
});
}

[Fact]
public async Task LoadDrawableAsyncReturnsWithSameImageAndDoesNotHang()
{
Expand Down

0 comments on commit de692d4

Please sign in to comment.