This has been answered multiple times but never afais gives the response starting by pressing a Button to get to the next View. Adding this approach just in case someone ends up (just like me) on a Google search that has this answer as one the top links.
This approach is a combination of @State variable on the Initial View and the same variable as @Binding in the Ending View. You can always add a "Back" button on the ending View to return to the original.
struct InitialView: View {
@State private var isEndingViewActive = false
HStack {
var body: some View {
if isEndingViewActive {
EndingView(isEndingViewActive: $isEndingViewActive)
} else {
Button(“Going to End View”) {
isEndingViewActive = true
}
}
}
}
}
struct EndingView: View {
@Binding private var isEndingViewActive: Bool
HStack {
var body: some View {
Button(“Going Back to Initial View”) {
isEndingViewActive = false
}
}
}
}