Created
November 21, 2023 18:59
-
-
Save valexa/d22a447249420f532fac07769548c815 to your computer and use it in GitHub Desktop.
NavigationStack example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ContentView.swift | |
// sandbox | |
// | |
// Created by vlad on 21/11/2023. | |
// | |
import SwiftUI | |
enum Route { | |
case preMatch | |
case playerInfo | |
case duringMatch | |
case afterMatch | |
@ViewBuilder | |
var view: some View { | |
switch self { | |
case .preMatch: PreMatchView() | |
case .playerInfo: PlayerInfoView() | |
case .duringMatch: DuringMatchView() | |
case .afterMatch: AfterMatchView() | |
} | |
} | |
} | |
struct PreMatchView: View { | |
var body: some View { | |
NavigationLink("Pre", value: Route.playerInfo) | |
} | |
} | |
struct PlayerInfoView: View { | |
var body: some View { | |
NavigationLink("Player", value: Route.duringMatch) | |
} | |
} | |
struct DuringMatchView: View { | |
var body: some View { | |
NavigationLink("During", value: Route.afterMatch) | |
} | |
} | |
struct AfterMatchView: View { | |
var body: some View { | |
NavigationLink("After", value: Route.preMatch) | |
} | |
} | |
struct ContentView: View { | |
var body: some View { | |
NavigationStack { | |
PreMatchView() | |
.navigationDestination(for: Route.self) { route in | |
route.view | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment