Hi all,
In Day 96, Paul implements a .searchable search bar that shows ideal behavior (imo) - the search bar stays hidden until the user pulls down slightly on the view, causing the search bar to appear to slide out from under the navigation bar into view.
I noticed that this behavior does not seem to still be present in the current version of Swift - when using .searchable, the search bar is always visible. A forum post from about a year ago seems to note this as well, but I'm having trouble confirming this elsewhere. Am I crazy, does this behavior still exist?
Paul's code, in case you'd like to test it yourself:
struct ContentView: View {
@State private var searchText = ""
let allNames = ["Subh", "Vina", "Melvin", "Stefanie"]
var body: some View {
NavigationView {
List(filteredNames, id: \.self) { name in
Text(name)
}
.searchable(text: $searchText, prompt: "Look for something")
.navigationTitle("Searching")
}
}
var filteredNames: [String] {
if searchText.isEmpty {
return allNames
} else {
return allNames.filter { $0.contains(searchText) }
}
}
}
Thanks!