I’m trying to build a simple VisionOS app with a single window and i wanna navigate between SwiftUI Views by tapping a custom View embedded inside a NavigationLink as I always did with all SwiftUI apps.
The issue is that nothing happens when I tap on the view, here is the code:
NavigationLink {
TheViewIWantNavigate()
} label: {
MyCustomView()
}
I was able to recognize the tap with this code:
HomeButtonView(text: "Tap Here", image: "myImage")
.onTapGesture {
print("View Tapped")
}
Am I doing something wrong?
Thanks in advance.
2
Answers
I found a workaround by using a state var as a toggle for a sheet.
NavigationLink
should warped inNavigationView
like code below:If you want to explore more about navigation structures in SwiftUI, you can refer to Apple’s sample code: “Bringing robust navigation structure to your SwiftUI app”.