Skip to content

Commit

Permalink
fix(macos): Use case-insensitive API to load images from bundle
Browse files Browse the repository at this point in the history
- also remove dead/unused method, unused since c0d16ea

Addresses #8666
  • Loading branch information
spouliot committed May 3, 2022
1 parent 6b8f248 commit f21db05
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions src/Uno.UI/UI/Xaml/Media/ImageSource.macOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@ public bool HasSource()
public bool HasBundle => BundlePath.HasValueTrimmed() || BundleName.HasValueTrimmed();

/// <summary>
/// Open bundle is using either the name of the bundle (for
/// android compatibility), or the path to the bundle for Windows compatibility.
/// Open the image from the app's main bundle.
/// </summary>
internal NSImage OpenBundle()
{
ImageData = OpenBundleFromString(BundleName) ?? OpenResourceFromString(BundlePath);
ImageData = OpenResourceFromString(BundlePath) ?? OpenResourceFromString(BundleName);

if (ImageData == null)
{
Expand All @@ -77,28 +76,13 @@ internal NSImage OpenBundle()
return ImageData;
}

private static NSImage OpenBundleFromString(string bundle)
{
if (bundle.HasValueTrimmed())
{
return NSImage.ImageNamed(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;
var path = Path.Combine(NSBundle.MainBundle.ResourcePath, name);
if (File.Exists(path))
return new NSImage(path);
}

return null;
Expand Down

0 comments on commit f21db05

Please sign in to comment.