Roman R
Roman R

Reputation: 51

how to make 'onTapGesture' start another view

I have a NavigationView with a card of Info and then a list, I would like to tap the info and go to another view, or you could tap an item of a list and see more info about an item. So, if I give 'onTapGesture' modifier to the card view it does print"onTap pressed', but I can't figure our how to make it start another view

  var body: some View {
    NavigationView {
        VStack {
            TopResultsCard(games: self.games)
                .padding(.top, 10)
                .onTapGesture({
                    print("onTap tapped")
                })
            ResultsListItem(games: self.games)
        }.navigationBarTitle("", displayMode: .inline)
            .navigationBarItems(trailing:
                Button(action: {
                    self.showNewResult.toggle()
                }) {
                    Image(systemName: "plus.circle")
                    Text("Add result")
                }
                .sheet(isPresented: $showNewResult) {AddResultView(games: self.games)}
                .font(.caption))
    }
}

Upvotes: 0

Views: 687

Answers (1)

Asperi
Asperi

Reputation: 257693

Here is possible approach. Use your destination view instead of demo Text("Next view here") below.

@State private var isActive = false

var body: some View {
    NavigationView {
        VStack {
            TopResultsCard(games: self.games)
                .padding(.top, 10)
                .onTapGesture { self.isActive.toggle() }
                .background(NavigationLink(destination:
                    Text("Next view here"), isActive: $isActive) { EmptyView() })

            ResultsListItem(games: self.games)
        }.navigationBarTitle("", displayMode: .inline)
            .navigationBarItems(trailing:
                Button(action: {
                    self.showNewResult.toggle()
                }) {
                    Image(systemName: "plus.circle")
                    Text("Add result")
                }
                .sheet(isPresented: $showNewResult) {AddResultView(games: self.games)}
                .font(.caption))
    }
}

Upvotes: 1

Related Questions