@@ -109,7 +109,22 @@ public bool ShouldPopItem(UINavigationBar _, UINavigationItem __)
109109 [ Export ( "navigationBar:didPopItem:" ) ]
110110 [ Internals . Preserve ( Conditional = true ) ]
111111 bool DidPopItem ( UINavigationBar _ , UINavigationItem __ )
112- => PopRequested || SendPop ( ) ;
112+ {
113+ if ( _shellSection . Stack . Count == NavigationBar . Items . Length )
114+ return true ;
115+
116+ var pages = _shellSection . Stack . ToList ( ) ;
117+
118+ _shellSection . SyncStackDownTo ( pages [ NavigationBar . Items . Length - 1 ] ) ;
119+
120+ for ( int i = pages . Count - 1 ; i >= NavigationBar . Items . Length ; i -- )
121+ {
122+ var page = pages [ i ] ;
123+ DisposePage ( page ) ;
124+ }
125+
126+ return true ;
127+ }
113128
114129 internal bool SendPop ( )
115130 {
@@ -394,7 +409,6 @@ protected virtual void OnNavigationRequested(object sender, NavigationRequestedE
394409
395410 protected virtual async void OnPopRequested ( NavigationRequestedEventArgs e )
396411 {
397- PopRequested = true ;
398412 var page = e . Page ;
399413 var animated = e . Animated ;
400414
@@ -435,7 +449,6 @@ async void ProcessPopToRoot()
435449
436450 protected virtual async void OnPopToRootRequested ( NavigationRequestedEventArgs e )
437451 {
438- PopRequested = true ;
439452 var animated = e . Animated ;
440453 var task = new TaskCompletionSource < bool > ( ) ;
441454 var pages = _shellSection . Stack . ToList ( ) ;
@@ -597,7 +610,6 @@ public override UIViewController[] PopToViewController(UIViewController viewCont
597610 public override void PushViewController ( UIViewController viewController , bool animated )
598611 {
599612 _pendingViewControllers = null ;
600- PopRequested = false ;
601613 if ( IsInMoreTab && ParentViewController is UITabBarController tabBarController )
602614 {
603615 tabBarController . MoreNavigationController . PushViewController ( viewController , animated ) ;
@@ -610,7 +622,6 @@ public override void PushViewController(UIViewController viewController, bool an
610622
611623 public override UIViewController PopViewController ( bool animated )
612624 {
613- PopRequested = true ;
614625 _pendingViewControllers = null ;
615626 if ( IsInMoreTab && ParentViewController is UITabBarController tabBarController )
616627 {
0 commit comments