Skip to content

Commit

Permalink
Only truncates stack if on-screen (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnpatrickmorgan committed Jan 30, 2023
1 parent 3627422 commit fcaaec1
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Sources/NavigationBackport/Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ struct Node<Screen>: 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
Expand All @@ -20,6 +22,7 @@ struct Node<Screen>: View {
set: { isShowing in
guard !isShowing else { return }
guard allScreens.count > index + 1 else { return }
guard isAppeared else { return }
truncateToIndex(index + 1)
}
)
Expand All @@ -36,6 +39,8 @@ struct Node<Screen>: View {
NavigationLink(destination: next, isActive: isActiveBinding, label: EmptyView.init)
.hidden()
)
.onAppear { isAppeared = true }
.onDisappear { isAppeared = false }
}
}
}
Expand Down

0 comments on commit fcaaec1

Please sign in to comment.