diff options
author | Rui Marinho <me@ruimarinho.net> | 2016-11-18 20:32:48 +0000 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-11-18 12:32:48 -0800 |
commit | fc66448bbde1834737a155b8d183e16b1a6c3e5e (patch) | |
tree | 4e62d97e8ab854a08b498d8f475d062871369b76 /Xamarin.Forms.Platform.iOS | |
parent | 54e1e4a56c1e77b395f9f3830ccb2b81b581cdc0 (diff) | |
download | xamarin-forms-fc66448bbde1834737a155b8d183e16b1a6c3e5e.tar.gz xamarin-forms-fc66448bbde1834737a155b8d183e16b1a6c3e5e.tar.bz2 xamarin-forms-fc66448bbde1834737a155b8d183e16b1a6c3e5e.zip |
[iOS] Revert changes in popping navigation (#547)
* [iOS] Revert changes in popping navigation
* [iOS] Remove unified if
Diffstat (limited to 'Xamarin.Forms.Platform.iOS')
-rw-r--r-- | Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs | 71 |
1 files changed, 44 insertions, 27 deletions
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs index 18000b7f..adf32192 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs @@ -97,11 +97,25 @@ namespace Xamarin.Forms.Platform.iOS return OnPopToRoot(page, animated); } + public override UIViewController[] PopToRootViewController(bool animated) + { + if (!_ignorePopCall && ViewControllers.Length > 1) + RemoveViewControllers(animated); + + return base.PopToRootViewController(animated); + } + public Task<bool> PopViewAsync(Page page, bool animated = true) { return OnPopViewAsync(page, animated); } + public override UIViewController PopViewController(bool animated) + { + RemoveViewControllers(animated); + return base.PopViewController(animated); + } + public Task<bool> PushPageAsync(Page page, bool animated = true) { return OnPushAsync(page, animated); @@ -501,9 +515,6 @@ namespace Xamarin.Forms.Platform.iOS // In the future we may want to make RemovePageAsync and deprecate RemovePage to handle cases where Push/Pop is called // during a remove cycle. - var parentingVC = target as ParentingViewController; - if (parentingVC != null) - parentingVC.IgnorePageBeingRemoved = true; if (_removeControllers == null) { @@ -520,6 +531,36 @@ namespace Xamarin.Forms.Platform.iOS UpdateLeftBarButtonItem(parentingViewController, page); } + void RemoveViewControllers(bool animated) + { + var controller = TopViewController as ParentingViewController; + if (controller == null || controller.Child == null) + return; + + // Gesture in progress, lets not be proactive and just wait for it to finish + var count = ViewControllers.Length; + var task = GetAppearedOrDisappearedTask(controller.Child); + task.ContinueWith(async t => + { + // task returns true if the user lets go of the page and is not popped + // however at this point the renderer is already off the visual stack so we just need to update the NavigationPage + // Also worth noting this task returns on the main thread + if (t.Result) + return; + _ignorePopCall = true; + // because iOS will just chain multiple animations together... + var removed = count - ViewControllers.Length; + for (var i = 0; i < removed; i++) + { + // lets just pop these suckers off, do not await, the true is there to make this fast + await ((INavigationPageController)Element).PopAsyncInner(animated, true); + } + // because we skip the normal pop process we need to dispose ourselves + controller.Dispose(); + _ignorePopCall = false; + }, TaskScheduler.FromCurrentSynchronizationContext()); + } + void UpdateBackgroundColor() { var color = Element.BackgroundColor == Color.Default ? Color.White : Element.BackgroundColor; @@ -761,12 +802,6 @@ namespace Xamarin.Forms.Platform.iOS } } - public bool IgnorePageBeingRemoved - { - get; - set; - } - public event EventHandler Appearing; public override void DidRotate(UIInterfaceOrientation fromInterfaceOrientation) @@ -822,24 +857,6 @@ namespace Xamarin.Forms.Platform.iOS base.ViewWillAppear(animated); } - public override async void DidMoveToParentViewController(UIViewController parent) - { - //If Parent of our child is already null we removed this using our API - //If we still have parent and we are removing our render we need to update our navigation - if (parent == null && !IgnorePageBeingRemoved) - { - NavigationRenderer n; - if (_navigation.TryGetTarget(out n)) - { - var navController = n.Element as INavigationPageController; - await navController?.PopAsyncInner(true, true); - } - - } - base.DidMoveToParentViewController(parent); - - } - protected override void Dispose(bool disposing) { if (disposing) |