summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS/ViewRenderer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.iOS/ViewRenderer.cs')
-rw-r--r--Xamarin.Forms.Platform.iOS/ViewRenderer.cs52
1 files changed, 44 insertions, 8 deletions
diff --git a/Xamarin.Forms.Platform.iOS/ViewRenderer.cs b/Xamarin.Forms.Platform.iOS/ViewRenderer.cs
index 6ecc307..01f8e06 100644
--- a/Xamarin.Forms.Platform.iOS/ViewRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/ViewRenderer.cs
@@ -1,21 +1,34 @@
using System;
using System.ComponentModel;
-using UIKit;
+
using RectangleF = CoreGraphics.CGRect;
using SizeF = CoreGraphics.CGSize;
+#if __MOBILE__
+using UIKit;
+using NativeView = UIKit.UIView;
+using NativeColor = UIKit.UIColor;
+using NativeControl = UIKit.UIControl;
+
namespace Xamarin.Forms.Platform.iOS
+#else
+using NativeView = AppKit.NSView;
+using NativeColor = CoreGraphics.CGColor;
+using NativeControl = AppKit.NSControl;
+
+namespace Xamarin.Forms.Platform.MacOS
+#endif
{
- public abstract class ViewRenderer : ViewRenderer<View, UIView>
+ public abstract class ViewRenderer : ViewRenderer<View, NativeView>
{
}
- public abstract class ViewRenderer<TView, TNativeView> : VisualElementRenderer<TView> where TView : View where TNativeView : UIView
+ public abstract class ViewRenderer<TView, TNativeView> : VisualElementRenderer<TView> where TView : View where TNativeView : NativeView
{
- UIColor _defaultColor;
+ NativeColor _defaultColor;
public TNativeView Control { get; private set; }
-
+#if __MOBILE__
public override void LayoutSubviews()
{
base.LayoutSubviews();
@@ -30,6 +43,19 @@ namespace Xamarin.Forms.Platform.iOS
return Control.SizeThatFits(size);
}
+#else
+ public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
+ {
+ return (Control ?? NativeView).GetSizeRequest(widthConstraint, heightConstraint);
+ }
+
+ public override void Layout()
+ {
+ if (Control != null)
+ Control.Frame = new RectangleF(0, 0, (nfloat)Element.Width, (nfloat)Element.Height);
+ base.Layout();
+ }
+#endif
/// <summary>
/// Determines whether the native control is disposed of when this renderer is disposed
@@ -100,16 +126,24 @@ namespace Xamarin.Forms.Platform.iOS
{
if (Control == null)
return;
-
+#if __MOBILE__
if (color == Color.Default)
Control.BackgroundColor = _defaultColor;
else
Control.BackgroundColor = color.ToUIColor();
+#else
+ Control.Layer.BackgroundColor = color == Color.Default ? _defaultColor : color.ToCGColor();
+#endif
}
protected void SetNativeControl(TNativeView uiview)
{
+#if __MOBILE__
_defaultColor = uiview.BackgroundColor;
+#else
+ uiview.WantsLayer = true;
+ _defaultColor = uiview.Layer.BackgroundColor;
+#endif
Control = uiview;
if (Element.BackgroundColor != Color.Default)
@@ -120,17 +154,19 @@ namespace Xamarin.Forms.Platform.iOS
AddSubview(uiview);
}
- internal override void SendVisualElementInitialized(VisualElement element, UIView nativeView)
+#if __MOBILE__
+ internal override void SendVisualElementInitialized(VisualElement element, NativeView nativeView)
{
base.SendVisualElementInitialized(element, Control);
}
+#endif
void UpdateIsEnabled()
{
if (Element == null || Control == null)
return;
- var uiControl = Control as UIControl;
+ var uiControl = Control as NativeControl;
if (uiControl == null)
return;
uiControl.Enabled = Element.IsEnabled;