I have MainView and where I have NavigationStack. I need to make it so that when I press the Search button, another view is shown and when I press the Cancel button, it is hidden again.
var body: some View {
NavigationStack {
if ($searchText.wrappedValue.isEmpty) {
ScrollView(.vertical, showsIndicators: true){
something()
}.navigationBarTitle("Summary")}
else { Text("Find: \(searchText)") }
if (showView==true) {
showSomethingView()
}
}
.searchable(text: $searchText, placement: .navigationBarDrawer(displayMode: .always), prompt: "Look for something")
.onSubmit(of: .search) { showView=true }
}
I need to perform a search after the user clicks the Search button. At the same time there is no such thing as onCancel.