Skip to content

Instantly share code, notes, and snippets.

@valexa
Created November 21, 2023 18:59
Show Gist options
  • Save valexa/d22a447249420f532fac07769548c815 to your computer and use it in GitHub Desktop.
Save valexa/d22a447249420f532fac07769548c815 to your computer and use it in GitHub Desktop.
NavigationStack example
//
// 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