skip to Main Content

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


  1. Chosen as BEST ANSWER

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


  2. NavigationLink should warped in NavigationView like code below:

    NavigationView {
        VStack {
            NavigationLink(destination: SecondView()) {
                Text("Go to Second View")
            }
        }
        .navigationBarTitle("First View")
    }
    

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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search