Calling a View

I have a button in MyViewA and after clicking on the button search, I want to call MyViewB, passing the variable search. How can I call a different view after clicking a button ?

var search: String = "abc"

Button(action: {
    MyViewB(keyword: self.search)
}) {
    Text("Search")
}

Thank you

It depends on many things, but one possible way is to use sheet or fullScreenCover:

struct ContentView: View {
    @State var search: String = "abc"
    @State var isPresented: Bool = false

    var body: some View {
        VStack {
            Button(action: {
                self.isPresented = true
            }) {
                Text("Search")
            }
        }
        .fullScreenCover(isPresented: $isPresented, content: {
            MyViewB(keyword: self.search)
        })
    }
}

I tried to do that, but somehow the MyViewB (actually it's a list view) is opened but not active. What I mean by that is the listview is loaded inside (Sheet/FullScreenCover) but you can't select anything on it.

Calling a View
 
 
Q