Created
May 28, 2024 04:22
-
-
Save nteissler/0634aeafe5eae385d2b147459e8f7b6c to your computer and use it in GitHub Desktop.
Day 8 of 21 Days of SwiftUI Navigation on Mastodon
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
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