0

I have a small game app that uses a navigation Stack to show different views. This is the home file

NavigationStack {
    VStack {
        Image(systemName: "globe")
            .imageScale(.large)
            .foregroundColor(.accentColor)
        Text("Hello, world!")
        NavigationLink("Start the game", destination: PlayView(scoreModel: ScoreModel()))
    }
}

this is the navigation of the PlayView I use to display the game and when the score is bigger then 2 switch to the WinWiev

ZStack {
    if scoreModel.score < 2 {
        gameView(scoreModel: scoreModel)
    } else {
        WinView()
    }
}

and in the WinView I would like to have a button that switches back to the beginning without showing a back button up top. I watched some explanation for the navigation Stack but the only work with empty arrays and lists and append and remove strings to the array and move back to root with .removeAll()

Because I am only one view deep I can dismiss the view with this code

@Environment(\.dismiss) var dismiss

var body: some View {
    Button("Dismiss Me") {
        dismiss()
    }
Cruder
  • 29
  • 5

0 Answers0