I have a problem to switch to another view without pressing a button in my SwiftUI app. I can take many examples of what I want to do : 1- Imagine a login form where we need to fill 2 textfields : username and password. When there's a perfect match we are automatically authenticated. 2- Take my example now. I have this view :
What I want to do : when I select a row in the list (ex. Lyon-Perrache TGV) AND if the two textfields are not empty => I'm redirected to another view.
There's many examples to know how to move to a view from another one, but always with a button click .. (with NavigationLink) I need to do this programatically exactly when the two textfields are filled AND when I select the destination textfield from the list.
that's a part of my code :
import SwiftUI
struct Search: View {
 @ObservedObject var webservice = Webservice()
 @State var Depart: String = ""
 @State var Destination: String = ""
 @State var listStation = [Station]()
 @State var predictedValues: Array<String> = []
 @State var isBeingEditedDeparture: Bool = false
 @State var isBeingEditedDestination: Bool = false
 @State var hey: Bool  = false
 @State var activate: Bool  = false
init() {
      UITableView.appearance().showsVerticalScrollIndicator = false
      UITableView.appearance().backgroundColor = .clear
      UITableViewCell.appearance().backgroundColor = .clear
      //UITableView.appearance().separatorColor = .clear
  }
var body: some View {
    VStack(alignment: .leading){
        PredictingTextField(listStation: self.$listStation , predictedValues: self.$predictedValues, 
        Depart: self.$Depart, Destination: self.$Destination, isBeingEditedDeparture: 
        self.$isBeingEditedDeparture, isBeingEditedDestination: self.$isBeingEditedDestination )
            .textFieldStyle(RoundedBorderTextFieldStyle())
        List() {
            ForEach(self.predictedValues, id: \.self){ value in
                Text(value)
                    .onTapGesture {
                        if(self.isBeingEditedDeparture == true)
                        {
                            self.Depart = value
                        }
                        else{
                            self.Destination = value
                            self.activate = true
                        }
                }
            }
        }.padding(.top, 10)
    }
}
I have declared a variable named "activate" to be the trigger point of moving to the new View. It's equal to true when we select a row in the list for "destination" textfield.
How can I do to go further ?
Thank you in advance !


 
    