Skip to content

Commit

Permalink
fix: Fix unhandled ObjectDisposedException in IconTintColorBehavior.C…
Browse files Browse the repository at this point in the history
…learTintColor on Android (#2012)
  • Loading branch information
Kay-STL authored Jul 24, 2024
1 parent 83a1482 commit f242cec
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected override void OnDetachedFrom(View bindable, AndroidView platformView)
{
base.OnDetachedFrom(bindable, platformView);

ClearTintColor(bindable, platformView);
ClearTintColor(platformView);

bindable.PropertyChanged -= OnElementPropertyChanged;
PropertyChanged -= OnTintedImagePropertyChanged;
Expand Down Expand Up @@ -62,7 +62,6 @@ static void ApplyTintColor(AndroidView? nativeView, Color? tintColor)
throw new NotSupportedException($"{nameof(IconTintColorBehavior)} only currently supports Android.Widget.Button and {nameof(ImageView)}.");
}


static void SetImageViewTintColor(ImageView image, Color? color)
{
if (color is null)
Expand Down Expand Up @@ -103,9 +102,14 @@ static void SetWidgetButtonTintColor(AndroidWidgetButton button, Color? color)
}
}

static void ClearTintColor(View element, AndroidView control)
static void ClearTintColor(AndroidView? nativeView)
{
switch (control)
if (nativeView is null)
{
return;
}

switch (nativeView)
{
case ImageView image:
image.ClearColorFilter();
Expand All @@ -114,7 +118,6 @@ static void ClearTintColor(View element, AndroidView control)
case AndroidMaterialButton mButton:
mButton.IconTint = null;
break;

case AndroidWidgetButton button:
foreach (var drawable in button.GetCompoundDrawables())
{
Expand Down

0 comments on commit f242cec

Please sign in to comment.