I'm using iOS 15 and trying out the new searchable
modifier on Lists in SwiftUI. It looks like when you attach searchable(text: $searchText)
to a NavigationView the search bar renders on the screen by default below the navigation bar title. When I've tried using it and I run the simulator, the search bar isn't rendered on the screen. Only when I start scrolling down on the screen through the list, does the search bar appear on the screen.
Is this expected behavior?
Here's the code.
@State private var searchText = ""
let data = (1...50).map( {_ in Int.random(in: 1...10)} )
var body: some View {
NavigationView {
List {
ForEach(data, id: \.self) { d in
Text("\(d)")
}
}
}.searchable(text: $searchText)
}
Before scrolling
After scrolling