From 8d1ddb2f5a517b1493b11312d7de32491bf9405a Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Wed, 1 Nov 2017 17:04:39 +0100 Subject: [PATCH 1/3] Make it possible to customise the window on iOS --- .../FormsApplicationDelegate.cs | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/Xamarin.Forms.Platform.iOS/FormsApplicationDelegate.cs b/Xamarin.Forms.Platform.iOS/FormsApplicationDelegate.cs index a4ffd895d8f..0203c01b3fb 100644 --- a/Xamarin.Forms.Platform.iOS/FormsApplicationDelegate.cs +++ b/Xamarin.Forms.Platform.iOS/FormsApplicationDelegate.cs @@ -9,9 +9,20 @@ namespace Xamarin.Forms.Platform.iOS { public class FormsApplicationDelegate : UIApplicationDelegate { - Application _application; + Application _application; bool _isSuspended; UIWindow _window; + public override UIWindow Window + { + get + { + return _window; + } + set + { + _window = value; + } + } protected FormsApplicationDelegate() { @@ -37,7 +48,8 @@ public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary // prepare you apps window and views for display // keep lightweight, anything long winded should be executed asynchronously on a secondary thread. // application:didFinishLaunchingWithOptions - _window = new UIWindow(UIScreen.MainScreen.Bounds); + if(Window == null) + Window = new UIWindow(UIScreen.MainScreen.Bounds); if (_application == null) throw new InvalidOperationException("You MUST invoke LoadApplication () before calling base.FinishedLaunching ()"); @@ -156,7 +168,7 @@ void CheckForAppLink(NSUserActivity userActivity) void SetMainPage() { UpdateMainPage(); - _window.MakeKeyAndVisible(); + Window.MakeKeyAndVisible(); } void UpdateMainPage() @@ -164,12 +176,10 @@ void UpdateMainPage() if (_application.MainPage == null) return; - var platformRenderer = (PlatformRenderer)_window.RootViewController; + if(Window.RootViewController is PlatformRenderer platformRenderer) + ((IDisposable)platformRenderer.Platform).Dispose(); - if (platformRenderer != null) - ((IDisposable)platformRenderer.Platform).Dispose(); - - _window.RootViewController = _application.MainPage.CreateViewController(); + Window.RootViewController = _application.MainPage.CreateViewController(); } } } \ No newline at end of file From 54c1b9842763e11d694ac724e40e08137db62346 Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Fri, 3 Nov 2017 13:02:12 +0100 Subject: [PATCH 2/3] Fix formatting --- .../FormsApplicationDelegate.cs | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Xamarin.Forms.Platform.iOS/FormsApplicationDelegate.cs b/Xamarin.Forms.Platform.iOS/FormsApplicationDelegate.cs index 0203c01b3fb..997579773ef 100644 --- a/Xamarin.Forms.Platform.iOS/FormsApplicationDelegate.cs +++ b/Xamarin.Forms.Platform.iOS/FormsApplicationDelegate.cs @@ -9,20 +9,20 @@ namespace Xamarin.Forms.Platform.iOS { public class FormsApplicationDelegate : UIApplicationDelegate { - Application _application; + Application _application; bool _isSuspended; UIWindow _window; - public override UIWindow Window - { - get - { - return _window; - } - set - { - _window = value; - } - } + public override UIWindow Window + { + get + { + return _window; + } + set + { + _window = value; + } + } protected FormsApplicationDelegate() { @@ -48,8 +48,8 @@ public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary // prepare you apps window and views for display // keep lightweight, anything long winded should be executed asynchronously on a secondary thread. // application:didFinishLaunchingWithOptions - if(Window == null) - Window = new UIWindow(UIScreen.MainScreen.Bounds); + if(Window == null) + Window = new UIWindow(UIScreen.MainScreen.Bounds); if (_application == null) throw new InvalidOperationException("You MUST invoke LoadApplication () before calling base.FinishedLaunching ()"); @@ -168,7 +168,7 @@ void CheckForAppLink(NSUserActivity userActivity) void SetMainPage() { UpdateMainPage(); - Window.MakeKeyAndVisible(); + Window.MakeKeyAndVisible(); } void UpdateMainPage() @@ -176,10 +176,10 @@ void UpdateMainPage() if (_application.MainPage == null) return; - if(Window.RootViewController is PlatformRenderer platformRenderer) - ((IDisposable)platformRenderer.Platform).Dispose(); + if(Window.RootViewController is PlatformRenderer platformRenderer) + ((IDisposable)platformRenderer.Platform).Dispose(); - Window.RootViewController = _application.MainPage.CreateViewController(); + Window.RootViewController = _application.MainPage.CreateViewController(); } } } \ No newline at end of file From 10bf58e2411527dc7ee6640313421c6107f481ac Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Fri, 3 Nov 2017 18:36:41 +0100 Subject: [PATCH 3/3] Update to not use C#7 --- Xamarin.Forms.Platform.iOS/FormsApplicationDelegate.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Xamarin.Forms.Platform.iOS/FormsApplicationDelegate.cs b/Xamarin.Forms.Platform.iOS/FormsApplicationDelegate.cs index 997579773ef..314c816a65c 100644 --- a/Xamarin.Forms.Platform.iOS/FormsApplicationDelegate.cs +++ b/Xamarin.Forms.Platform.iOS/FormsApplicationDelegate.cs @@ -48,7 +48,7 @@ public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary // prepare you apps window and views for display // keep lightweight, anything long winded should be executed asynchronously on a secondary thread. // application:didFinishLaunchingWithOptions - if(Window == null) + if (Window == null) Window = new UIWindow(UIScreen.MainScreen.Bounds); if (_application == null) @@ -176,7 +176,8 @@ void UpdateMainPage() if (_application.MainPage == null) return; - if(Window.RootViewController is PlatformRenderer platformRenderer) + var platformRenderer = Window.RootViewController as PlatformRenderer; + if (platformRenderer != null) ((IDisposable)platformRenderer.Platform).Dispose(); Window.RootViewController = _application.MainPage.CreateViewController();