summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS/Forms.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.iOS/Forms.cs')
-rw-r--r--Xamarin.Forms.Platform.iOS/Forms.cs57
1 files changed, 44 insertions, 13 deletions
diff --git a/Xamarin.Forms.Platform.iOS/Forms.cs b/Xamarin.Forms.Platform.iOS/Forms.cs
index 2c8fc6f..d6e7e07 100644
--- a/Xamarin.Forms.Platform.iOS/Forms.cs
+++ b/Xamarin.Forms.Platform.iOS/Forms.cs
@@ -11,11 +11,18 @@ using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
-using CoreFoundation;
+using Xamarin.Forms.Internals;
using Foundation;
+#if __MOBILE__
using UIKit;
-using Xamarin.Forms.Internals;
using Xamarin.Forms.Platform.iOS;
+using TNativeView = UIKit.UIView;
+#else
+using AppKit;
+using Xamarin.Forms.Platform.MacOS;
+using TNativeView = AppKit.NSView;
+
+#endif
namespace Xamarin.Forms
{
@@ -24,7 +31,11 @@ namespace Xamarin.Forms
//Preserve GetCallingAssembly
static readonly bool nevertrue = false;
+ public static bool IsInitialized { get; private set; }
+
+#if __MOBILE__
static bool? s_isiOS9OrNewer;
+#endif
static Forms()
{
@@ -32,8 +43,7 @@ namespace Xamarin.Forms
Assembly.GetCallingAssembly();
}
- public static bool IsInitialized { get; private set; }
-
+#if __MOBILE__
internal static bool IsiOS9OrNewer
{
get
@@ -43,6 +53,7 @@ namespace Xamarin.Forms
return s_isiOS9OrNewer.Value;
}
}
+#endif
public static void Init()
{
@@ -53,19 +64,22 @@ namespace Xamarin.Forms
Log.Listeners.Add(new DelegateLogListener((c, m) => Trace.WriteLine(m, c)));
+#if __MOBILE__
+ Device.Idiom = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? TargetIdiom.Tablet : TargetIdiom.Phone;
+#else
+ Device.Idiom = TargetIdiom.Desktop;
+#endif
Device.PlatformServices = new IOSPlatformServices();
Device.Info = new IOSDeviceInfo();
- Registrar.RegisterAll(new[] { typeof(ExportRendererAttribute), typeof(ExportCellAttribute), typeof(ExportImageSourceHandlerAttribute) });
-
- Device.Idiom = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? TargetIdiom.Tablet : TargetIdiom.Phone;
-
+ Registrar.RegisterAll(new[]
+ { typeof(ExportRendererAttribute), typeof(ExportCellAttribute), typeof(ExportImageSourceHandlerAttribute) });
ExpressionSearch.Default = new iOSExpressionSearch();
}
public static event EventHandler<ViewInitializedEventArgs> ViewInitialized;
- internal static void SendViewInitialized(this VisualElement self, UIView nativeView)
+ internal static void SendViewInitialized(this VisualElement self, TNativeView nativeView)
{
ViewInitialized?.Invoke(self, new ViewInitializedEventArgs { View = self, NativeView = nativeView });
}
@@ -99,16 +113,22 @@ namespace Xamarin.Forms
internal class IOSDeviceInfo : DeviceInfo
{
+#if __MOBILE__
readonly NSObject _notification;
+#endif
readonly Size _scaledScreenSize;
readonly double _scalingFactor;
public IOSDeviceInfo()
{
+#if __MOBILE__
_notification = UIDevice.Notifications.ObserveOrientationDidChange((sender, args) => CurrentOrientation = UIDevice.CurrentDevice.Orientation.ToDeviceOrientation());
-
_scalingFactor = UIScreen.MainScreen.Scale;
_scaledScreenSize = new Size(UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height);
+#else
+ _scalingFactor = NSScreen.MainScreen.BackingScaleFactor;
+ _scaledScreenSize = new Size(NSScreen.MainScreen.Frame.Width, NSScreen.MainScreen.Frame.Height);
+#endif
PixelScreenSize = new Size(_scaledScreenSize.Width * _scalingFactor, _scaledScreenSize.Height * _scalingFactor);
}
@@ -120,7 +140,9 @@ namespace Xamarin.Forms
protected override void Dispose(bool disposing)
{
+#if __MOBILE__
_notification.Dispose();
+#endif
base.Dispose(disposing);
}
}
@@ -198,11 +220,19 @@ namespace Xamarin.Forms
public bool IsInvokeRequired => !NSThread.IsMain;
+#if __MOBILE__
public string RuntimePlatform => Device.iOS;
+#else
+ public string RuntimePlatform => Device.macOS;
+#endif
public void OpenUriAction(Uri uri)
{
+#if __MOBILE__
UIApplication.SharedApplication.OpenUrl(new NSUrl(uri.AbsoluteUri));
+#else
+ NSWorkspace.SharedWorkspace.OpenUrl(new NSUrl(uri.AbsoluteUri));
+#endif
}
public void StartTimer(TimeSpan interval, Func<bool> callback)
@@ -217,11 +247,11 @@ namespace Xamarin.Forms
HttpClient GetHttpClient()
{
- var proxy = CFNetwork.GetSystemProxySettings();
+ var proxy = CoreFoundation.CFNetwork.GetSystemProxySettings();
var handler = new HttpClientHandler();
if (!string.IsNullOrEmpty(proxy.HTTPProxy))
{
- handler.Proxy = CFNetwork.GetDefaultProxy();
+ handler.Proxy = CoreFoundation.CFNetwork.GetDefaultProxy();
handler.UseProxy = true;
}
return new HttpClient(handler);
@@ -272,7 +302,8 @@ namespace Xamarin.Forms
public Task<Stream> OpenFileAsync(string path, FileMode mode, FileAccess access, FileShare share)
{
- Stream stream = _isolatedStorageFile.OpenFile(path, (System.IO.FileMode)mode, (System.IO.FileAccess)access, (System.IO.FileShare)share);
+ Stream stream = _isolatedStorageFile.OpenFile(path, (System.IO.FileMode)mode, (System.IO.FileAccess)access,
+ (System.IO.FileShare)share);
return Task.FromResult(stream);
}
}