From 5ec989c455f53c212becb14e7ec6e119bbe64fb5 Mon Sep 17 00:00:00 2001 From: Andrei Date: Tue, 13 Nov 2018 04:06:04 +0300 Subject: [PATCH] [MacOs] Implemented InsertPageBefore (#4242) * implemented InsertPage for MacOs * Removed TODO * fixed insert before method for mac - fixes #4030 --- .../Renderers/NavigationPageRenderer.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Xamarin.Forms.Platform.MacOS/Renderers/NavigationPageRenderer.cs b/Xamarin.Forms.Platform.MacOS/Renderers/NavigationPageRenderer.cs index a6ba4a6ec..f38ec2268 100644 --- a/Xamarin.Forms.Platform.MacOS/Renderers/NavigationPageRenderer.cs +++ b/Xamarin.Forms.Platform.MacOS/Renderers/NavigationPageRenderer.cs @@ -213,13 +213,28 @@ namespace Xamarin.Forms.Platform.MacOS return pageRenderer; } - //TODO: Implement InserPageBefore void InsertPageBefore(Page page, Page before) { if (before == null) throw new ArgumentNullException(nameof(before)); if (page == null) throw new ArgumentNullException(nameof(page)); + + var currentList = _currentStack.Reverse().ToList(); + var beforePageIndex = currentList.IndexOf(p => p.Page == before); + var pageWrapper = new NavigationChildPageWrapper(page); + currentList.Insert(beforePageIndex, pageWrapper); + _currentStack = new Stack(currentList); + + var vc = CreateViewControllerForPage(page); + vc.SetElementSize(new Size(View.Bounds.Width, View.Bounds.Height)); + page.Layout(new Rectangle(0, 0, View.Bounds.Width, View.Frame.Height)); + + var beforeViewController = Platform.GetRenderer(before).ViewController; + var beforeControllerIndex = ChildViewControllers.IndexOf(beforeViewController); + + InsertChildViewController(vc.ViewController, beforeControllerIndex); + View.AddSubview(vc.NativeView); } void OnInsertPageBeforeRequested(object sender, NavigationRequestedEventArgs e)