diff options
Diffstat (limited to 'Xamarin.Forms.Platform.iOS')
-rw-r--r-- | Xamarin.Forms.Platform.iOS/ContextScrollViewDelegate.cs | 2 | ||||
-rw-r--r-- | Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs | 71 |
2 files changed, 45 insertions, 28 deletions
diff --git a/Xamarin.Forms.Platform.iOS/ContextScrollViewDelegate.cs b/Xamarin.Forms.Platform.iOS/ContextScrollViewDelegate.cs index bc04ede2..14f95a73 100644 --- a/Xamarin.Forms.Platform.iOS/ContextScrollViewDelegate.cs +++ b/Xamarin.Forms.Platform.iOS/ContextScrollViewDelegate.cs @@ -210,7 +210,7 @@ namespace Xamarin.Forms.Platform.iOS void ClearCloserRecognizer(UIScrollView scrollView) { - if (_globalCloser == null) + if (_globalCloser == null || _globalCloser.State == UIGestureRecognizerState.Cancelled) return; var cell = GetContextCell(scrollView); diff --git a/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs index fdbd116d..9374c362 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs @@ -95,11 +95,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); @@ -489,9 +503,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) { @@ -508,6 +519,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; @@ -747,12 +788,6 @@ namespace Xamarin.Forms.Platform.iOS } } - public bool IgnorePageBeingRemoved - { - get; - set; - } - public event EventHandler Appearing; public override void DidRotate(UIInterfaceOrientation fromInterfaceOrientation) @@ -808,24 +843,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) |