Replies: 8 comments
-
Hey @gkaimakas! Thanks for providing a demo project :) This looks like it is more of a SwiftUI bug and is reproducible with the following: struct ContentView: View {
@State var isPresented = false
var body: some View {
NavigationStack {
NavigationLink("Go to destination", value: 42)
.navigationDestination(for: Int.self) { [foo = {}] _ in // capturing a reference
Button("Present sheet") {
isPresented = true
}
.sheet(isPresented: $isPresented) {
NavigationStack {
NavigationLink("Go to destination", value: "Blob")
.navigationDestination(for: String.self) { _ in // foo is implicitly captured
let _ = foo() // <- Comment out this line
Text("Hello, world!")
}
}
}
}
}
}
} In your example, it would be related to .navigationDestination(for: FeatureXDestination.self) { [foo = {}] view in
let _ = foo()
switch view {
case .featureY:
Text("help would be welcome")
}
} I'm not sure if this is a known issue or if there is a workaround. Maybe @mbrandonw, @stephencelis or @tgrapperon can help. I'd encourage you to check out swiftui-navigation if you haven't already. The docs provide some great info on state driven navigation. Incorporating SwiftUINavigation into your demo project would likely fix this issue. |
Beta Was this translation helpful? Give feedback.
-
I try to avoid making view properties "jump" across presentation boundaries by capture, because it usually breaks things from my experience. Issues can be even amplified with Footnotes
|
Beta Was this translation helpful? Give feedback.
-
@iampatbrown @tgrapperon thank you both for your replies. I've checked SwiftUINavigation but can't exactly wrap my head around on how to achieve both programmatic and user initiated navigation. Guess I will have to experiment a bit more with this. |
Beta Was this translation helpful? Give feedback.
-
In any case my workaround wasn't clear, I was suggesting to create: struct DestinationView: View {
let store: StoreOf<Root>
let destination: Destination
var body: some View {
switch destination {
case let .featureB(id):
… // Same code as in the original implementation
}
}
and in …
.navigationDestination(for: Destination.self) { destination in
DestinationView(store: store, destination: destination)
} instead of having all your destinations declared in You can totally nest AFAIK, As an aside, TCA ships with an utility called |
Beta Was this translation helpful? Give feedback.
-
@tgrapperon thanks for following up on that! Will check it out! |
Beta Was this translation helpful? Give feedback.
-
@gkaimakas |
Beta Was this translation helpful? Give feedback.
-
@dy-kim would love to move it a discussion but I don't have permission to do so |
Beta Was this translation helpful? Give feedback.
-
I'll convert it to a discussion :) |
Beta Was this translation helpful? Give feedback.
-
Description
I have built a small app with 5 features (A, B, C, X, Y). Features A, B & C are accessible through a NavigationStackABC and when in C a user can present another NavigationStackXY with X that can navigate to Y.
While both navigation stacks work as expected in isolation when I try to present NavigationStackXY from C, the app freezes until getting killed by the OS.
I have created a demo app and found that if instead of creating a view with a
Store
here, I create a vanilla SwiftUI view everything works as expected.Checklist
main
branch of this package.Expected behavior
The app should not freeze.
Actual behavior
The app freezes
Steps to reproduce
The Composable Architecture version information
0.49.2
Destination operating system
iOS 16.2
Xcode version information
Version 14.2 (14C18)
Swift Compiler version information
Beta Was this translation helpful? Give feedback.
All reactions