From fcaaec16f92e2b1c56cbbcd05bd13cb05e4bbb12 Mon Sep 17 00:00:00 2001 From: johnpatrickmorgan Date: Mon, 30 Jan 2023 00:27:28 +0000 Subject: [PATCH] Only truncates stack if on-screen (#30) --- Sources/NavigationBackport/Node.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sources/NavigationBackport/Node.swift b/Sources/NavigationBackport/Node.swift index 3489321..5206e24 100644 --- a/Sources/NavigationBackport/Node.swift +++ b/Sources/NavigationBackport/Node.swift @@ -6,6 +6,8 @@ struct Node: View { let truncateToIndex: (Int) -> Void let index: Int let screen: Screen? + + @State var isAppeared = false init(allScreens: [Screen], truncateToIndex: @escaping (Int) -> Void, index: Int) { self.allScreens = allScreens @@ -20,6 +22,7 @@ struct Node: View { set: { isShowing in guard !isShowing else { return } guard allScreens.count > index + 1 else { return } + guard isAppeared else { return } truncateToIndex(index + 1) } ) @@ -36,6 +39,8 @@ struct Node: View { NavigationLink(destination: next, isActive: isActiveBinding, label: EmptyView.init) .hidden() ) + .onAppear { isAppeared = true } + .onDisappear { isAppeared = false } } } }