summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS/Extensions
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.iOS/Extensions')
-rw-r--r--Xamarin.Forms.Platform.iOS/Extensions/ColorExtensions.cs47
-rw-r--r--Xamarin.Forms.Platform.iOS/Extensions/DateExtensions.cs5
-rw-r--r--Xamarin.Forms.Platform.iOS/Extensions/LayoutExtensions.cs21
-rw-r--r--Xamarin.Forms.Platform.iOS/Extensions/PlatformConfigurationExtensions.cs11
-rw-r--r--Xamarin.Forms.Platform.iOS/Extensions/UIViewExtensions.cs45
5 files changed, 111 insertions, 18 deletions
diff --git a/Xamarin.Forms.Platform.iOS/Extensions/ColorExtensions.cs b/Xamarin.Forms.Platform.iOS/Extensions/ColorExtensions.cs
index bb4342ab..2b8b9101 100644
--- a/Xamarin.Forms.Platform.iOS/Extensions/ColorExtensions.cs
+++ b/Xamarin.Forms.Platform.iOS/Extensions/ColorExtensions.cs
@@ -1,16 +1,27 @@
using System;
using CoreGraphics;
-using UIKit;
using PointF = CoreGraphics.CGPoint;
using RectangleF = CoreGraphics.CGRect;
using SizeF = CoreGraphics.CGSize;
-
+#if __MOBILE__
+using UIKit;
namespace Xamarin.Forms.Platform.iOS
+#else
+using AppKit;
+using UIColor = AppKit.NSColor;
+
+namespace Xamarin.Forms.Platform.MacOS
+#endif
{
public static class ColorExtensions
{
+#if __MOBILE__
internal static readonly UIColor Black = UIColor.Black;
internal static readonly UIColor SeventyPercentGrey = new UIColor(0.7f, 0.7f, 0.7f, 1);
+#else
+ internal static readonly NSColor Black = NSColor.Black;
+ internal static readonly NSColor SeventyPercentGrey = NSColor.FromRgba(0.7f, 0.7f, 0.7f, 1);
+#endif
public static CGColor ToCGColor(this Color color)
{
@@ -23,10 +34,15 @@ namespace Xamarin.Forms.Platform.iOS
nfloat green;
nfloat blue;
nfloat alpha;
+#if __MOBILE__
color.GetRGBA(out red, out green, out blue, out alpha);
+#else
+ color.GetRgba(out red, out green, out blue, out alpha);
+#endif
return new Color(red, green, blue, alpha);
}
+#if __MOBILE__
public static UIColor ToUIColor(this Color color)
{
return new UIColor((float)color.R, (float)color.G, (float)color.B, (float)color.A);
@@ -47,6 +63,28 @@ namespace Xamarin.Forms.Platform.iOS
return color.ToUIColor();
}
+#else
+ public static NSColor ToNSColor(this Color color)
+ {
+ return NSColor.FromRgba((float)color.R, (float)color.G, (float)color.B, (float)color.A);
+ }
+
+ public static NSColor ToNSColor(this Color color, Color defaultColor)
+ {
+ if (color.IsDefault)
+ return defaultColor.ToNSColor();
+
+ return color.ToNSColor();
+ }
+
+ public static NSColor ToNSColor(this Color color, NSColor defaultColor)
+ {
+ if (color.IsDefault)
+ return defaultColor;
+
+ return color.ToNSColor();
+ }
+#endif
}
public static class PointExtensions
@@ -55,6 +93,11 @@ namespace Xamarin.Forms.Platform.iOS
{
return new Point(point.X, point.Y);
}
+
+ public static PointF ToPointF(this Point point)
+ {
+ return new PointF(point.X, point.Y);
+ }
}
public static class SizeExtensions
diff --git a/Xamarin.Forms.Platform.iOS/Extensions/DateExtensions.cs b/Xamarin.Forms.Platform.iOS/Extensions/DateExtensions.cs
index bb0dfff9..73ca347c 100644
--- a/Xamarin.Forms.Platform.iOS/Extensions/DateExtensions.cs
+++ b/Xamarin.Forms.Platform.iOS/Extensions/DateExtensions.cs
@@ -1,7 +1,12 @@
using System;
using Foundation;
+#if __MOBILE__
namespace Xamarin.Forms.Platform.iOS
+#else
+
+namespace Xamarin.Forms.Platform.MacOS
+#endif
{
public static class DateExtensions
{
diff --git a/Xamarin.Forms.Platform.iOS/Extensions/LayoutExtensions.cs b/Xamarin.Forms.Platform.iOS/Extensions/LayoutExtensions.cs
index 823c3f30..d65caf12 100644
--- a/Xamarin.Forms.Platform.iOS/Extensions/LayoutExtensions.cs
+++ b/Xamarin.Forms.Platform.iOS/Extensions/LayoutExtensions.cs
@@ -1,10 +1,19 @@
using System.Collections.Generic;
using CoreGraphics;
+#if __MOBILE__
using UIKit;
-
+using Xamarin.Forms.Platform.iOS;
namespace Xamarin.Forms.Platform.iOS
+#else
+using AppKit;
+using UIView = AppKit.NSView;
+using Xamarin.Forms.Platform.MacOS;
+
+namespace Xamarin.Forms.Platform.MacOS
+#endif
{
- public delegate SizeRequest? GetDesiredSizeDelegate(NativeViewWrapperRenderer renderer, double widthConstraint, double heightConstraint);
+ public delegate SizeRequest? GetDesiredSizeDelegate(
+ NativeViewWrapperRenderer renderer, double widthConstraint, double heightConstraint);
public delegate CGSize? SizeThatFitsDelegate(CGSize size);
@@ -12,13 +21,15 @@ namespace Xamarin.Forms.Platform.iOS
public static class LayoutExtensions
{
- public static void Add(this IList<View> children, UIView view, GetDesiredSizeDelegate getDesiredSizeDelegate = null, SizeThatFitsDelegate sizeThatFitsDelegate = null,
- LayoutSubviewsDelegate layoutSubViews = null)
+ public static void Add(this IList<View> children, UIView view, GetDesiredSizeDelegate getDesiredSizeDelegate = null,
+ SizeThatFitsDelegate sizeThatFitsDelegate = null,
+ LayoutSubviewsDelegate layoutSubViews = null)
{
children.Add(view.ToView(getDesiredSizeDelegate, sizeThatFitsDelegate, layoutSubViews));
}
- public static View ToView(this UIView view, GetDesiredSizeDelegate getDesiredSizeDelegate = null, SizeThatFitsDelegate sizeThatFitsDelegate = null, LayoutSubviewsDelegate layoutSubViews = null)
+ public static View ToView(this UIView view, GetDesiredSizeDelegate getDesiredSizeDelegate = null,
+ SizeThatFitsDelegate sizeThatFitsDelegate = null, LayoutSubviewsDelegate layoutSubViews = null)
{
return new NativeViewWrapper(view, getDesiredSizeDelegate, sizeThatFitsDelegate, layoutSubViews);
}
diff --git a/Xamarin.Forms.Platform.iOS/Extensions/PlatformConfigurationExtensions.cs b/Xamarin.Forms.Platform.iOS/Extensions/PlatformConfigurationExtensions.cs
index f61837f2..f2932e3a 100644
--- a/Xamarin.Forms.Platform.iOS/Extensions/PlatformConfigurationExtensions.cs
+++ b/Xamarin.Forms.Platform.iOS/Extensions/PlatformConfigurationExtensions.cs
@@ -1,11 +1,18 @@
+#if __MOBILE__
+using CurrentPlatform = Xamarin.Forms.PlatformConfiguration.iOS;
namespace Xamarin.Forms.Platform.iOS
+#else
+using CurrentPlatform = Xamarin.Forms.PlatformConfiguration.macOS;
+
+namespace Xamarin.Forms.Platform.MacOS
+#endif
{
public static class PlatformConfigurationExtensions
{
- public static IPlatformElementConfiguration<PlatformConfiguration.iOS, T> OnThisPlatform<T>(this T element)
+ public static IPlatformElementConfiguration<CurrentPlatform, T> OnThisPlatform<T>(this T element)
where T : Element, IElementConfiguration<T>
{
- return (element).On<PlatformConfiguration.iOS>();
+ return (element).On<CurrentPlatform>();
}
}
} \ No newline at end of file
diff --git a/Xamarin.Forms.Platform.iOS/Extensions/UIViewExtensions.cs b/Xamarin.Forms.Platform.iOS/Extensions/UIViewExtensions.cs
index 4c3eed98..8248af11 100644
--- a/Xamarin.Forms.Platform.iOS/Extensions/UIViewExtensions.cs
+++ b/Xamarin.Forms.Platform.iOS/Extensions/UIViewExtensions.cs
@@ -2,10 +2,15 @@ using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
-using UIKit;
using static System.String;
-
+#if __MOBILE__
+using UIKit;
namespace Xamarin.Forms.Platform.iOS
+#else
+using UIView = AppKit.NSView;
+
+namespace Xamarin.Forms.Platform.MacOS
+#endif
{
public static class UIViewExtensions
{
@@ -16,15 +21,28 @@ namespace Xamarin.Forms.Platform.iOS
return self.Subviews.Concat(self.Subviews.SelectMany(s => s.Descendants()));
}
- public static SizeRequest GetSizeRequest(this UIView self, double widthConstraint, double heightConstraint, double minimumWidth = -1, double minimumHeight = -1)
+ public static SizeRequest GetSizeRequest(this UIView self, double widthConstraint, double heightConstraint,
+ double minimumWidth = -1, double minimumHeight = -1)
{
- var s = self.SizeThatFits(new SizeF((float)widthConstraint, (float)heightConstraint));
- var request = new Size(s.Width == float.PositiveInfinity ? double.PositiveInfinity : s.Width, s.Height == float.PositiveInfinity ? double.PositiveInfinity : s.Height);
- var minimum = new Size(minimumWidth < 0 ? request.Width : minimumWidth, minimumHeight < 0 ? request.Height : minimumHeight);
+ CoreGraphics.CGSize s;
+#if __MOBILE__
+ s = self.SizeThatFits(new SizeF((float)widthConstraint, (float)heightConstraint));
+#else
+ var control = self as AppKit.NSControl;
+ if (control != null)
+ s = control.SizeThatFits(new CoreGraphics.CGSize(widthConstraint, heightConstraint));
+ else
+ s = self.FittingSize;
+#endif
+ var request = new Size(s.Width == float.PositiveInfinity ? double.PositiveInfinity : s.Width,
+ s.Height == float.PositiveInfinity ? double.PositiveInfinity : s.Height);
+ var minimum = new Size(minimumWidth < 0 ? request.Width : minimumWidth,
+ minimumHeight < 0 ? request.Height : minimumHeight);
return new SizeRequest(request, minimum);
}
- public static void SetBinding(this UIView view, string propertyName, BindingBase bindingBase, string updateSourceEventName = null)
+ public static void SetBinding(this UIView view, string propertyName, BindingBase bindingBase,
+ string updateSourceEventName = null)
{
var binding = bindingBase as Binding;
//This will allow setting bindings from Xaml by reusing the MarkupExtension
@@ -51,6 +69,7 @@ namespace Xamarin.Forms.Platform.iOS
view.AddObserver(nativePropertyListener, key, Foundation.NSKeyValueObservingOptions.New, IntPtr.Zero);
}
}
+#if __MOBILE__
catch (Foundation.MonoTouchException ex)
{
nativePropertyListener = null;
@@ -61,7 +80,12 @@ namespace Xamarin.Forms.Platform.iOS
}
throw ex;
}
-
+#else
+ catch (Exception ex)
+ {
+ throw ex;
+ }
+#endif
}
NativeBindingHelpers.SetBinding(view, propertyName, bindingBase, nativePropertyListener);
@@ -77,7 +101,8 @@ namespace Xamarin.Forms.Platform.iOS
NativeBindingHelpers.SetValue(target, targetProperty, value);
}
- public static void SetBindingContext(this UIView target, object bindingContext, Func<UIView, IEnumerable<UIView>> getChildren = null)
+ public static void SetBindingContext(this UIView target, object bindingContext,
+ Func<UIView, IEnumerable<UIView>> getChildren = null)
{
NativeBindingHelpers.SetBindingContext(target, bindingContext, getChildren);
}
@@ -107,6 +132,7 @@ namespace Xamarin.Forms.Platform.iOS
return null;
}
+#if __MOBILE__
internal static UIView FindFirstResponder(this UIView view)
{
if (view.IsFirstResponder)
@@ -121,5 +147,6 @@ namespace Xamarin.Forms.Platform.iOS
return null;
}
+#endif
}
} \ No newline at end of file