Skip to content

Commit

Permalink
fix(droid): CommandBar AppBar Icon crashing
Browse files Browse the repository at this point in the history
  • Loading branch information
ajpinedam committed Jun 17, 2023
1 parent 43620a6 commit 8ff5e83
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Uno.UWP/Helpers/DrawableHelper.Android.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#nullable enable
#nullable enable
using Android.Graphics.Drawables;
using AndroidX.Core.Content;
using AndroidX.Core.Graphics.Drawable;
Expand Down Expand Up @@ -87,6 +87,11 @@ public static Type? Drawables
/// <returns><seealso cref="Drawable"/> for the URI provided or null otherwise</returns>
public static Drawable? FromUri(Uri uri)
{
if (uri?.PathAndQuery is null)
{
return null;
}

var id = FindResourceIdFromPath(uri.PathAndQuery.TrimStart(new[] { '/' }));
var drawable = id.HasValue
? ContextCompat.GetDrawable(ContextHelper.Current, id.Value)
Expand All @@ -109,11 +114,16 @@ public static Type? Drawables

private static void InitializeDrawablesLookup()
{
if (_drawables is null)
{
return;
}

_drawablesLookup = _drawables
?.GetFields(BindingFlags.Static | BindingFlags.Public)
.GetFields(BindingFlags.Static | BindingFlags.Public)
.ToDictionary(
p => p.Name,
p => (int)p.GetValue(null)
p => (p.GetValue(null) as int?) ?? 0
);
}
}
Expand Down

0 comments on commit 8ff5e83

Please sign in to comment.