3

I want to push a View when I tap on an Image. My Code so far:

struct Home: View {
    var body: some View {
        NavigationView {
            VStack {
                Image("image")
                    .onTapGesture {
                   //navigation code here
                }
                Text("Tap on image to find details")
            }
        }
    }
}

How to achieve that navigation? Thanks!

1 Answer 1

5

Why can't you use standard NavigationLink as below?

NavigationView {
    VStack {
        NavigationLink(destination: SomeDestinationViewHere()) {
            Image("image")
        }
        Text("Tap on image to find details")
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

If I could, I would have. This image is a member of a nested view. I need to pass along the navigation code from where I want this to happen.
For the truth I've not got your use-case, but to my mind it is easier to pass image here, which is model data, and use regular approach, than trying to hack system framework. Anyway, it is up to you.
Okay. If there is no other way, I'll implement NavigationLink. Thanks for the help! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.