Closed PhilipDukhov closed 11 months ago
It works fine as long as content is static, but when I add any state change it stops working
Current example is working for me, no issues. Tested on iOS simulator and physical device. Am I missing a state change?
It works fine as long as content is static, but when I add any state change it stops working
Current example is working for me, no issues. Tested on iOS simulator and physical device. Am I missing a state change?
hm, I created a new project, added Transmission v1.0.0 as a dependency and can reproduce it both on simulator and on a real device
this state change is enough to make it fail:
.task {
state += 1
}
https://github.com/nathantannar4/Transmission/assets/6103621/dc1798d3-8ede-45aa-8137-e785a6ac775d
Ok I can reproduce. Seems like the @State
value must also be read for the issue to reproduce. Very strange, not sure what's going on.
Seems like another obscure NavigationStack
bug I'm not sure how to work around. Workaround is to install the presentation
modifier outside of the NavigationStack
@available(iOS 16.0, *)
struct PresentedNavigationPathKey: ViewOutputKey {
struct Content: View {
var isPresented: Binding<Bool>
var body: AnyView
init<V: View>(isPresented: Binding<Bool>, @ViewBuilder body: () -> V) {
self.isPresented = isPresented
self.body = AnyView(body())
}
}
}
@available(iOS 16.0, *)
struct ParentView: View {
@State var path = NavigationPath()
var body: some View {
ViewOutputKeyReader(PresentedNavigationPathKey.self) { value in
NavigationStack(path: $path) {
VStack {
ChildView(id: "A")
ChildView(id: "B")
}
.navigationTitle("Parent")
}
.background {
ViewOutputKeyValueReader(value) { list in
ForEach(list) { destination in
Color.clear
.presentation(
transition: .sheet,
isPresented: destination.content.isPresented
) {
destination
}
}
}
}
}
}
}
@available(iOS 16.0, *)
struct ChildView: View {
var id: String
@State var path = NavigationPath()
@State var isPresented = false
var body: some View {
Button {
withAnimation {
isPresented = true
}
} label: {
Text("Show Stack")
}
.viewOutput(PresentedNavigationPathKey.self) {
PresentedNavigationPathKey.Content(
isPresented: $isPresented
) {
NavigationStack(path: $path) {
Button {
withAnimation {
path.append("Some")
}
} label: {
Text("Button \(id)")
}
.navigationDestination(for: String.self) { value in
Text(value)
}
.navigationTitle("Child")
}
}
}
}
}
Seems like another obscure
NavigationStack
bug I'm not sure how to work around. Workaround is to install thepresentation
modifier outside of theNavigationStack
thank you for looking though, and for the workaround!
It works fine as long as content is static, but when I add any state change it stops working