Previewing the layout in a navigation view
Some views are designed to be presented in a navigation stack but are not themselves part of a navigation view. One solution to this problem would be to run the application and navigate to the view in question. However, previews provide a time-saving way to figure out how the view would be displayed without running the app.
In this recipe, we will create an app with a view that is part of the navigation stack and preview it in a navigation view.
Getting ready
Let's create a SwiftUI app called PreviewingInNavigationView
.
How to do it…
We will add a NavigationView
and NavigationLink
components to ContentView
that lead to a second view. The second view will not contain a navigation view but will be previewed in one. The steps are as follows:
- Replace the
Text
view inContentView
with a navigation view containing aVStack
component andNavigationLink
to a view calledSecondView
:NavigationView { &...