Thanks for the extensive response!
My situation is #2. I don't use NavigationDestination, because most of my NavigationLinks are single-use ones invoked with a button, which go to a specific view to handle a certain task.
In my application, the user is preparing a message to send to another user or contact. From the root view (where the NavigationStack is declared), the user goes through a series of screens to pick a message recipient and a communication method.
Because each child view needs access to the NavigationPath, I enclose it in an object I can pass through the hierarchy (because I think environment variables are hokey):
@Observable
class NavPathController
{
var path: NavigationPath
init()
{
path = NavigationPath()
}
func popOne()
{
path.removeLast()
}
func popAll()
{
path.removeLast(path.count)
}
}
In my root view, I do:
@State private var viewStack = NavPathController()
var body: some View
{
NavigationStack(path: $viewStack.path)
{
NavigationLink(destination: UserFindingView(withMessage: theMessage, viewPathController: viewStack), label: { Text("Pick a recipient") })
...
}
}
and then each child view looks something like
struct UserFindingView: View
{
private var theMessage: Message
private var pathControl: NavPathController?
init(withMessage: Message, viewPathController: NavPathController? = nil)
{
theMessage = withMessage
self.pathControl = viewPathController
}
var body: some View
{
NavigationLink(destination: ContactsStartView(withMessage: theMessage, viewPathController: pathControl), label: { Text("Use your contacts...") })
}
But as the user follows the NavigationLinks, nothing appears to be added to the path. At the end of the hierarchy (the topmost overlaid view), the path has zero elements. So... how does one address that?