Skip to content

Instantly share code, notes, and snippets.

@mattyoung
Created June 25, 2022 17:15
Show Gist options
  • Select an option

  • Save mattyoung/a29122ed12d8dab5ca52461df57adc28 to your computer and use it in GitHub Desktop.

Select an option

Save mattyoung/a29122ed12d8dab5ca52461df57adc28 to your computer and use it in GitHub Desktop.
import SwiftUI
struct ChildView: View {
@Binding var path: NavigationPath
let string: String
var body: some View {
VStack {
Text(string)
Button("Go deeper") {
path.append("Deeper")
}
Button("Pop to root") {
path.removeLast(path.count)
}
}
}
}
struct FloWritesCodeNavigationStackExample: View {
@State private var path = NavigationPath()
var body: some View {
NavigationStack(path: $path) {
List {
NavigationLink("Simple String", value: "Simple String")
}
.navigationDestination(for: String.self) { string in
ChildView(path: $path, string: string)
}
}
}
}
struct FloWritesCodeNavigationStackExample_Previews: PreviewProvider {
static var previews: some View {
FloWritesCodeNavigationStackExample()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment