Skip to content

Commit 2a31f4c

Browse files
committed
- fix long press back navigation
1 parent 218b913 commit 2a31f4c

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRenderer.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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
{

src/Controls/src/Core/Shell/ShellSection.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,32 @@ void IShellSectionController.SendInsetChanged(Thickness inset, double tabThickne
111111
_lastTabThickness = tabThickness;
112112
}
113113

114+
internal void SyncStackDownTo(Page page)
115+
{
116+
if (_navStack.Count <= 1)
117+
throw new Exception("Nav Stack consistency error");
118+
119+
var oldStack = _navStack;
120+
121+
int index = oldStack.IndexOf(page);
122+
_navStack = new List<Page> { null };
123+
124+
for (int i = 1; i <= index; i++)
125+
{
126+
_navStack.Add(oldStack[i]);
127+
}
128+
129+
for (int i = index + 1; i < oldStack.Count; i++)
130+
oldStack[i].SendDisappearing();
131+
132+
UpdateDisplayedPage();
133+
134+
for (int i = index + 1; i < oldStack.Count; i++)
135+
RemovePage(oldStack[i]);
136+
137+
(Parent?.Parent as IShellController)?.UpdateCurrentState(ShellNavigationSource.Pop);
138+
}
139+
114140
async void IShellSectionController.SendPopping(Task poppingCompleted)
115141
{
116142
if (_navStack.Count <= 1)

0 commit comments

Comments
 (0)