Skip to content

Instantly share code, notes, and snippets.

@shaundon
Created July 24, 2022 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaundon/63e422864faa8b899c368a78b7a52172 to your computer and use it in GitHub Desktop.
Save shaundon/63e422864faa8b899c368a78b7a52172 to your computer and use it in GitHub Desktop.
Proof of concept of a NavigationStack not updating when a value changes
import SwiftUI
struct ContentView: View {
@State private var foo: String? = nil
var body: some View {
// Change this to `NavigationView` and it'll work.
NavigationStack {
if let foo { Text(foo) }
else { ProgressView() }
}
.task {
// Simulate loading some data asynchronously.
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
foo = "loaded"
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment