Replies: 1 comment 8 replies
-
Hi @wtruppel, this is unfortunately just yet another a SwiftUI navigation bug. TCA's navigation tools are just a light layer on top of SwiftUI's native tools and do not try to fix any of their bugs, so you still have to be mindful of their limitations. Here is a vanilla SwiftUI application that reproduces the same problem: class Model: ObservableObject, Identifiable {
@Published var child: Model?
init(child: Model? = nil) { self.child = child }
var id: ObjectIdentifier { ObjectIdentifier(self) }
}
struct ModelView: View {
@ObservedObject var model: Model
var body: some View {
Button("Tap") {
self.model.child = Model()
}
.navigationDestination(
isPresented: Binding(
get: { self.model.child != nil },
set: {
if !$0 { self.model.child = nil }
}
)
) {
if let child = self.model.child {
ModelView(model: child)
}
}
}
}
struct ContentView: View {
@ObservedObject var model: Model
var body: some View {
NavigationStack {
ModelView(model: self.model)
}
}
} |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello :)
I've been giving the pre-release 1.0 branch and the new navigation tools a spin and I found a few problems relating to deep-linking:
AppFeature
->SceneA
->SceneB
->SceneC
)Interestingly, tests pass for both scenarios.
I'm attaching to this post a very simple toy project that you can use to verify those issues. Before I describe the two problems in more detail, here's a brief walk-through of the toy app's code. The app has an
AppFeature
module and theAppFeature
scene can presentSceneA
:Then there are modules for various scenes, A through F, with each scene able to present the next, except for
SceneF
, which is a leaf scene. So, all scenes A through E look identical in structure:Finally, there's the leaf scene,
SceneF
:As for the views, they just show buttons to present the next scene and to dismiss the current scene:
Now, for the two issues.
deep-linking from the start appears to work only up to at most 3 levels deep (
AppFeature
->SceneA
->SceneB
->SceneC
)If you start the app with the deep-linked state (
AppFeature
->SceneA
->SceneB
->SceneC
->SceneD
->SceneE
->SceneF
)you'll see that it shows
SceneC
, notSceneF
:The same is true if you deep link into any scene beyond
SceneC
. Yet, no errors or runtime warnings happen. Moreover, if you attempt to presentSceneD
from this point, it does not work (no scene transition happens) and you do get a runtime warningprogrammatically attempting to deep-link causes the runtime warning "A "ifLet" at ... received a presentation action when destination state was absent."
If you start the app with no deep links,
then navigate to
SceneF
,and from there try to simulate the app receiving a deep-link to another scene, it does appear to work (the scenes transition correctly) but you also get a runtime warning
Can anyone please shed some light on what may be happening?
Many thanks in advance.
NewTCANav-forum.zip
Beta Was this translation helpful? Give feedback.
All reactions