How to correctly programmatically push a path onto StackState #2794
-
I'm building a bit of a unique UI that's presented some navigational API challenges. Namely, my view has a header and footer that are used across the entire navigation flow and technically sit visually above the navigation stack so that they're not part of the cover transition. On the footer specifically, there's a "Next" button. The downside of that is now my header and footer aren't encapsulated inside the navigation stack and can't use The part I'm confused about though is how to create the @Dependency(\.stackElementID) var stackElementID
self.init(value: state.map { StackState.Component(id: stackElementID(), element: $0) }) {
_NavigationLinkStoreContent<P, L>(
state: state, label: { label() }, fileID: fileID, line: line
)
} So do I do the same thing, grab the stack element id and great a new component and grab the id via |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You cannot create a There are two ways to push elements onto |
Beta Was this translation helpful? Give feedback.
You cannot create a
StackElementID
yourself; it is deliberately an opaque type managed byStackState
. You can only reference them onceStackState
has created them.There are two ways to push elements onto
StackState
. One isNavigationLink
s. The other is thatStackState
conforms toRangeReplaceableCollection
, so you have access to methods on it such asappend(Self.Element)
. That second method sounds like what you want: your header and footer are living at the root view of theNavigationStack
, so when a button in them sends an action to the root feature reducer, you handle that action and simply append toStackState
programmatically, and that will cause SwiftUI to push the corresponding vie…