Closed PhilipDukhov closed 8 months ago
update: looks like changing state declared outside of .destination
doesn't trigger recomposition when modified from inside destination
.
Yea this is a known issue. I believe it's because the UIHostingController
that pushed the destination view is no longer in the view hierarchy so SwiftUI updates no longer take place.
The expected workaround is to use the @Environment(\.destinationCoordinator)
to pop the view programatically. I havent found a good fix to allow mutating a @State in a previous hosting controller like your example shows.
Ok I actually stumbled upon a nice fix. In 1.1.1
, wrap your NavigationContainer
like so:
struct NavigationContainer<Content: View>: View {
@ViewBuilder let content: Content
var body: some View {
ViewGraphBridgeAdapter {
content
} content: { content in
Wrapper(content: content)
}
}
struct Wrapper<C: View>: UIViewControllerRepresentable {
let content: C
func makeUIViewController(context: Context) -> UINavigationController { }
func updateUIViewController(_ uiViewController: UINavigationController, context: Context) { }
}
}
Steps to reproduce:
Expected result: view will pop to root. Actual result: nothing happens.