Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using System.Diagnostics;
using Android.Graphics;
using Android.Widget;
using Microsoft.Maui.Platform;
Expand Down Expand Up @@ -44,22 +45,28 @@ static void ApplyTintColor(AndroidView? nativeView, Color? tintColor)
return;
}

switch (nativeView)
try
{
case ImageView image:
SetImageViewTintColor(image, tintColor);
break;
switch (nativeView)
{
case ImageView image:
SetImageViewTintColor(image, tintColor);
break;

case AndroidMaterialButton materialButton when tintColor is not null:
SetMaterialButtonTintColor(materialButton, tintColor);
break;
case AndroidMaterialButton materialButton when tintColor is not null:
SetMaterialButtonTintColor(materialButton, tintColor);
break;

case AndroidWidgetButton widgetButton:
SetWidgetButtonTintColor(widgetButton, tintColor);
break;
case AndroidWidgetButton widgetButton:
SetWidgetButtonTintColor(widgetButton, tintColor);
break;

default:
throw new NotSupportedException($"{nameof(IconTintColorBehavior)} only currently supports Android.Widget.Button and {nameof(ImageView)}.");
default:
throw new NotSupportedException($"{nameof(IconTintColorBehavior)} only currently supports Android.Widget.Button and {nameof(ImageView)}.");
}
}
catch (ObjectDisposedException)
{
}

static void SetImageViewTintColor(ImageView image, Color? color)
Expand Down Expand Up @@ -109,22 +116,28 @@ static void ClearTintColor(AndroidView? nativeView)
return;
}

switch (nativeView)
try
{
switch (nativeView)
{
case ImageView image:
image.ClearColorFilter();
break;

case AndroidMaterialButton mButton:
mButton.IconTint = null;
break;
case AndroidWidgetButton button:
foreach (var drawable in button.GetCompoundDrawables())
{
drawable.ClearColorFilter();
}

break;
}
}
catch (ObjectDisposedException)
{
case ImageView image:
image.ClearColorFilter();
break;

case AndroidMaterialButton mButton:
mButton.IconTint = null;
break;
case AndroidWidgetButton button:
foreach (var drawable in button.GetCompoundDrawables())
{
drawable.ClearColorFilter();
}

break;
}
}

Expand Down