Skip to content

Instantly share code, notes, and snippets.

@nteissler
Created May 28, 2024 04:22
Show Gist options
  • Save nteissler/0634aeafe5eae385d2b147459e8f7b6c to your computer and use it in GitHub Desktop.
Save nteissler/0634aeafe5eae385d2b147459e8f7b6c to your computer and use it in GitHub Desktop.
Day 8 of 21 Days of SwiftUI Navigation on Mastodon
import SwiftUI
struct Day8: View {
@State private var path: [String] = []
@State var presentedItem: Int? = nil
var body: some View {
NavigationStack(path: $path) {
List {
NavigationLink("Value-destination Link", value: "Hello")
Button("Populate item binding") {
presentedItem = 5
}
}
.navigationTitle("Root View")
.navigationDestination(for: String.self) { str in
VStack(alignment: .leading, spacing: 10) {
Text("Value Destination view for String values")
Text("""
You can push additional value-destinations
onto the stack from this view
""")
NavigationLink("Push another value", value: "World")
}
}
.navigationDestination(item: $presentedItem) { int in
VStack(alignment: .leading, spacing: 10) {
Text("View destination view for bound-int")
Text("""
You can not push more value-destinations. You
may continue to push view-destination views
""")
NavigationLink("Another view destintion") {
Color.mint.navigationBarTitleDisplayMode(.inline)
}
}
}
}
}
}
#Preview {
Day8()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment