0

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.

I Don't Tell
  • 264
  • 1
  • 15

2 Answers2

0

I found a workaround by using a state var as a toggle for a sheet.

I Don't Tell
  • 264
  • 1
  • 15
0

NavigationLink should warped in NavigationStack like code below:

NavigationStack {
    NavigationLink {
      TheViewIWantNavigate()
    } label: {
      MyCustomView()
  }
}

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”.


Remember the NavigationView will deprecated.

FradSer
  • 199
  • 1
  • 9