I want to implement navigation in the left ornament, but I have an issue. The NavigationStack is not working there. It broke something in the app itself.
The app structure looks like this:
The first view has a navigation stack(1) The second view that is shown from the navigation stack(1) has a left ornament that is shown by default. The left ornament content has a navigation stack(2)
The issue looks like this:
The issue happens when I show the second view, altering the path
variable of the Root View.
In the logs, I see:
unbalanced calls to begin/end appearance transitions for <_MRUIPlatterOrnamentRootViewController: 0x10848a940>.
The animations that show the ornament and navigation stack inside of it do not work as expected. It basically broke the appearance of the second view. It is not showing on the screen but works somewhere in the memory.
Simplified Code example
struct RootView: View {
var path = NavigationPath
var body: some View {
NavigationStack(path: path) {
View1()
.navigationDestination(for: NavigationItem.self) { item in
switch item {
case 1:
View2()
}
}
}
}
}
struct View2: View {
@State private var leftPanelVisibility: Visibility = .visible
var body: some View {
VStack {
}
.ornament(
visibility: leftPanelVisibility,
attachmentAnchor: .scene(.trailing),
contentAlignment: .leading
) {
VStack {
// Just having this NavigationStack in the views hierarchy broke the navigation
NavigationStack {
Text("TBD Match")
}
}
}
}
What I tried
The strange thing is that navigation stack(2) replaced by NavigationView
makes the app work. But it is deprecated, and I can't use it in the project (target VisionOS 1, iOS 17).
Using NavigationBackport instead of the navigation stack(2) causes the same issue.
Moving the ornament outside the navigation stack(1) works fine. I don't see it as a solution because each view is supposed to have its own ornaments by design.
So, the problem is interconnected with navigation stacks and the Ornament being inside of one.
It looks similar to NavigationStack inside view of another NavigationStack but has some differences.
What I am expecting
The navigation works inside the Ornament. Is there a way around it without implementing a custom navigation logic?
You have to implement custom Navigation to have this work as you intend.
Ornament
is a child of the parentNavigationStack
it doesn’t work like asheet
or apopover
which are separate.