Home > AI > IOS > SwiftUI >

NavigationLink working with onTapGesture

struct ContentView: View {
    @State var sum: Int = 0
    @State var number1: Int = 0
    @State var number2: Int = 0
    @State var isTapped: Bool = false
    
    var body: some View {
       
        NavigationView {
            NavigationLink(destination: Text("\(self.sum)")) {
                Text("Add Two Numbers")
                    .padding()
                    .foregroundColor(.blue)
                    .background(isTapped ? Color.orange : Color.gray)
                    .font(.title)
                    .border(Color.blue, width: 5)
                    .shadow(radius: 10)
                }
                .simultaneousGesture(TapGesture().onEnded{
                    print("I am here in the action")
                    self.isTapped.toggle()
                    
                    self.sum = number1 + number2
                    print("\(self.sum)")
                
                })
        }
    }
}

Leave a Reply