HStack NavigationLink in Form tappable area small

Viewed 515

I would like to be able to tap the entire row in this form to navigate to the next view; what am I doing wrong? It only allows me to navigate if I tap the symbol at the end. This code should compile and run in your simulator. Thanks.

import SwiftUI

struct SwiftUIView: View {
    let selectedTags = ["A", "B", "C"]

    var body: some View {
        NavigationView {
            Form {
                NavigationLink(destination: DetailView()) {
                    ScrollView(.horizontal) {
                        HStack {
                            ForEach(selectedTags, id: \.self) { tag in
                                Text(tag)
                            }
                        }
                    }
                }
            }
        }
    }
}

struct DetailView: View {
    var body: some View {
        Text("Welcome")
    }
}

struct SwiftUIView_Previews: PreviewProvider {
    static var previews: some View {
        SwiftUIView()
    }
}
1 Answers

copy - paste - run

import SwiftUI

struct ContentView: View {
    let selectedTags = ["A", "B", "C"]
    @State var active = false
    var body: some View {
        NavigationView {
            Form {
                NavigationLink( destination: DetailView(), isActive: $active) {
                    ScrollView(.horizontal) {
                        HStack {
                            ForEach(selectedTags, id: \.self) { tag in
                                Text(tag)
                            }
                        }
                    }.onTapGesture {
                        self.active.toggle()
                    }
                }
            }
        }
    }
}

struct DetailView: View {
    var body: some View {
        Text("Welcome")
    }
}
struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
Related