Skip to content

Instantly share code, notes, and snippets.

@mattyoung
Last active August 8, 2021 10:32
Show Gist options
  • Save mattyoung/99c6a449a99fa671f528013d04b5b794 to your computer and use it in GitHub Desktop.
Save mattyoung/99c6a449a99fa671f528013d04b5b794 to your computer and use it in GitHub Desktop.
import SwiftUI
struct Child: View {
@Binding var binding: Int
var body: some View {
VStack {
Text("x = \(binding)")
Button("Mutate parent view .x") {
binding += 1 // this will cause a new child view push onto the nav stack
}
}
}
}
struct ContentView: View {
@State var x = 100
var body: some View {
NavigationView {
VStack {
Text("Hello, x = \(x)")
}
.navigationTitle(Text("Nav Stack Keep Pushing"))
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
NavigationLink(destination: Child(binding: $x)) {
// image interpolation here doesn't work
// Text("Child\(Image(systemName: "chevron.right"))")
// so have to use a HStack
HStack(spacing: 0) {
Text("Child")
Image(systemName: "chevron.right") }
}
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
@zntfdr
Copy link

zntfdr commented Aug 8, 2021

Fixed in iOS 15b4!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment