Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Avoid ImageButtonRenderer ObjectDisposedException on Android (#996)
Browse files Browse the repository at this point in the history
* Avoid crash using reflection or exception ignoring

* Remove uncessserary exception reference.
Comment reference to XF issue

Co-authored-by: Andrei <andrei.misiukevich@gmail.com>
  • Loading branch information
Cfun1 and AndreiMisiukevich committed Mar 2, 2021
1 parent 0db9352 commit caa3ebc
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using System;
using System.ComponentModel;
using System.Linq;
using Android.Graphics;
using Android.Widget;
Expand Down Expand Up @@ -50,16 +51,21 @@ void ApplyTintColor()

void ClearTintColor()
{
switch (Control)
try
{
case ImageView image:
image.ClearColorFilter();
break;
case Button button:
var drawables = button.GetCompoundDrawables().Where(d => d != null);
foreach (var img in drawables)
img.ClearColorFilter();
break;
switch (Control)
{
case ImageView image:
image.ClearColorFilter();
break;
case Button button:
foreach (var drawable in button.GetCompoundDrawables())
drawable?.ClearColorFilter();
break;
}
}
catch (ObjectDisposedException) {
// We ignore ObjectDisposedException as a workaround of XF issue https://github.com/xamarin/Xamarin.Forms/issues/13889
}
}

Expand Down

0 comments on commit caa3ebc

Please sign in to comment.