summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.MacOS
diff options
context:
space:
mode:
authorMarko B. Ludolph <MarkoBL@users.noreply.github.com>2017-07-25 15:39:44 +0200
committerRui Marinho <me@ruimarinho.net>2017-07-25 09:39:44 -0400
commit9c82ed129ffb349a393e67dc9695dbc2f3600c35 (patch)
treee6cb8aee2a0899561cad65bf284e17861cf90a64 /Xamarin.Forms.Platform.MacOS
parentf3f34245445089ecdb9f562e4fbb7a841b480914 (diff)
downloadxamarin-forms-9c82ed129ffb349a393e67dc9695dbc2f3600c35.tar.gz
xamarin-forms-9c82ed129ffb349a393e67dc9695dbc2f3600c35.tar.bz2
xamarin-forms-9c82ed129ffb349a393e67dc9695dbc2f3600c35.zip
[MacOS] Image Aspect Fix (#1041)
* MacOS Image Aspect Fix * FormsNSImageView internal * Fixed: Renderers/ImageRenderer.cs(9,15,9,28): error CS0060: Inconsistent accessibility: base class 'ViewRenderer<Image, FormsNSImageView>' is less accessible than class 'ImageRenderer' * FormsNSImage internal fix
Diffstat (limited to 'Xamarin.Forms.Platform.MacOS')
-rw-r--r--Xamarin.Forms.Platform.MacOS/Controls/FormsImageView.cs12
-rw-r--r--Xamarin.Forms.Platform.MacOS/Renderers/ImageRenderer.cs37
2 files changed, 36 insertions, 13 deletions
diff --git a/Xamarin.Forms.Platform.MacOS/Controls/FormsImageView.cs b/Xamarin.Forms.Platform.MacOS/Controls/FormsImageView.cs
index 33ed73b6..6d7cd3c5 100644
--- a/Xamarin.Forms.Platform.MacOS/Controls/FormsImageView.cs
+++ b/Xamarin.Forms.Platform.MacOS/Controls/FormsImageView.cs
@@ -1,11 +1,19 @@
-using AppKit;
+using System;
+using AppKit;
+using CoreAnimation;
namespace Xamarin.Forms.Platform.MacOS
{
- internal class FormsNSImageView : NSImageView
+ internal class FormsNSImageView : NSView
{
bool _isOpaque;
+ public FormsNSImageView()
+ {
+ Layer = new CALayer();
+ WantsLayer = true;
+ }
+
public void SetIsOpaque(bool isOpaque)
{
_isOpaque = isOpaque;
diff --git a/Xamarin.Forms.Platform.MacOS/Renderers/ImageRenderer.cs b/Xamarin.Forms.Platform.MacOS/Renderers/ImageRenderer.cs
index cfb6249a..fa7aac4f 100644
--- a/Xamarin.Forms.Platform.MacOS/Renderers/ImageRenderer.cs
+++ b/Xamarin.Forms.Platform.MacOS/Renderers/ImageRenderer.cs
@@ -1,10 +1,12 @@
using System;
using System.ComponentModel;
using AppKit;
+using CoreAnimation;
+using CoreGraphics;
namespace Xamarin.Forms.Platform.MacOS
{
- public class ImageRenderer : ViewRenderer<Image, NSImageView>
+ public class ImageRenderer : ViewRenderer<Image, NSView>
{
bool _isDisposed;
@@ -15,8 +17,8 @@ namespace Xamarin.Forms.Platform.MacOS
if (disposing)
{
- NSImage oldUIImage;
- if (Control != null && (oldUIImage = Control.Image) != null)
+ CGImage oldUIImage;
+ if (Control != null && (oldUIImage = Control.Layer.Contents) != null)
{
oldUIImage.Dispose();
}
@@ -58,8 +60,19 @@ namespace Xamarin.Forms.Platform.MacOS
void SetAspect()
{
- //TODO: Implement set Image Aspect
- //Control.ContentMode = Element.Aspect.ToUIViewContentMode();
+ switch (Element.Aspect)
+ {
+ case Aspect.AspectFill:
+ Control.Layer.ContentsGravity = CALayer.GravityResizeAspectFill;
+ break;
+ case Aspect.Fill:
+ Control.Layer.ContentsGravity = CALayer.GravityResize;
+ break;
+ case Aspect.AspectFit:
+ default:
+ Control.Layer.ContentsGravity = CALayer.GravityResizeAspect;
+ break;
+ }
}
async void SetImage(Image oldElement = null)
@@ -76,7 +89,7 @@ namespace Xamarin.Forms.Platform.MacOS
if (imageSource != null && source is FileImageSource && imageSource.File == ((FileImageSource)source).File)
return;
- Control.Image = null;
+ Control.Layer.Contents = null;
}
IImageSourceHandler handler;
@@ -85,25 +98,27 @@ namespace Xamarin.Forms.Platform.MacOS
if (source != null && (handler = Internals.Registrar.Registered.GetHandler<IImageSourceHandler>(source.GetType())) != null)
{
- NSImage uiimage;
+ NSImage nsImage;
try
{
- uiimage = await handler.LoadImageAsync(source, scale: (float)NSScreen.MainScreen.BackingScaleFactor);
+ nsImage = await handler.LoadImageAsync(source, scale: (float)NSScreen.MainScreen.BackingScaleFactor);
}
catch (OperationCanceledException)
{
- uiimage = null;
+ nsImage = null;
}
var imageView = Control;
if (imageView != null)
- imageView.Image = uiimage;
+ imageView.Layer.Contents = nsImage != null ? nsImage.CGImage : null;
+ if (nsImage != null)
+ nsImage.Dispose();
if (!_isDisposed)
((IVisualElementController)Element).NativeSizeChanged();
}
else
- Control.Image = null;
+ Control.Layer.Contents = null;
if (!_isDisposed)
Element.SetIsLoading(false);