Skip to content

Commit

Permalink
feat: (macOS) Add #2844 support for Image
Browse files Browse the repository at this point in the history
  • Loading branch information
ajpinedam committed Mar 31, 2020
1 parent d0b6e1c commit c0d16ea
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Uno.UI/UI/Xaml/Media/ImageSource.macOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public bool HasSource()
/// </summary>
internal NSImage OpenBundle()
{
ImageData = OpenBundleFromString(BundleName) ?? OpenBundleFromString(BundlePath);
ImageData = OpenBundleFromString(BundleName) ?? OpenResourceFromString(BundlePath);

if (ImageData == null)
{
Expand All @@ -86,6 +86,23 @@ private static NSImage OpenBundleFromString(string bundle)
return null;
}

private static NSImage OpenResourceFromString(string name)
{
if (name.HasValueTrimmed())
{
var extension = Path.GetExtension(name);
var fileName = name.Replace(extension, string.Empty);

var path = NSBundle.MainBundle.PathForResource(fileName, extension);

return !string.IsNullOrEmpty(path)
? new NSImage(path)
: null;
}

return null;
}

internal async Task<NSImage> Open(CancellationToken ct)
{
using (
Expand Down

0 comments on commit c0d16ea

Please sign in to comment.