-
-
Save helje5/38295beb7473a83ad7d236f99172d256 to your computer and use it in GitHub Desktop.
Sample showing how programmatic SwiftUI navigation doesn't work and ignores the source of truth.
Author
Author
This has a sequence of pages: A => B => C => D. The goal is to directly jump to D (usually w/o animation, but depends).
The truth which link is active is stored in an observable object. This is then bound to the NavigationLink isActive.
What happens? Seems to depends on the SwiftUI version and the moon phase.
- sometimes it jumps to just B and stays there. When pressing "next", it jumps to D, but then pops back to C, then B.
- SwiftUI 3 sometimes crashes with an Env Object not being bound, this can be fixed by explicitly passing it along (in the destination view,
.environmentObject(navState). - if this is done, pressing "go to d", jumps to B, then C, then D, then pops to C, and then pops to B
Author
Someone suggested adding:
NavigationView {
...
}
.navigationViewStyle(StackNavigationViewStyle())but that doesn't help. In a 14.5 simulator it still just jumps to B.
My FB# on the matter: FB9197698
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Full project by @DjukicMiroslav over here: RouterTest
FB9148980
The behaviour is slightly different between Xcode 12 & 13 but doesn't fully work in either.
The core issue seems to be that
NavigationLinkupon creation doesn't bother visiting the source of truth.