Post not yet marked as solved
I started to develop an application using iOS15 and the new .searchable modifier.
I have a simple layout with some placeholder results on the main page and a search field attached to the navigationBar.
Currently, if the user loads the page and looks at the results (even scrolls a bit) will not be able find the search field as it's hidden by default. The user needs to scroll in reverse for the search bar to appear.
How is this a good for UX?
The only workaround is the drawer placement with .always, but that will make the navigation title inline.
I really want to achieve the result from the Notes app, that has the search bar visible all the time.
Any workaround? Was this feature really tested by anyone in a real app?
Post not yet marked as solved
Dear all,
I want to add a Picker view under the search bar similarly as seen on the Files app:
I would be happy with one of the two options - 1) to have a picker view to be visible under the search bar all the time (ie. even when the search bar is not activated), 2) to have the picker view to be visible when search bar is active.
I tried to implement this by using the toolbar modifier but without luck.
NavigationView {
List {
...
}
.searchable(text: $searchText)
.toolbar {
ToolbarItem {
Picker(selection: $selectedScope) {
...
} label: {
...
}
.pickerStyle(.segmented)
}
}
}
I have also tried the workaround by adding the Picker view within the List/Form but in this case the Picker view disappears when the user scrolls the list down.
List {
Section {
Picker(selection: $selectedScope) {
...
} label: {
...
}
.pickerStyle(.segmented)
}
...
}
.searchable(text: $searchText)
}
One last thing I tried was to put the picker view within the search bar’s suggestions parameter. This however, obscures the search results under the suggestions view.
List {
...
}
.searchable(text: $searchText), suggestions:
Picker(selection: $selectedScope) {
...
} label: {
...
}
.pickerStyle(.segmented)
})
}
Any ideas?
Post not yet marked as solved
Hi,
Does anyone knows if it is possible (or there are plans) to enable associating a .searchable modifier with a keyboard shortcut?
It seems a no brainer and very useful for iPadOS or Catalyst.
Thanks
Hello - I am new to Swift so my apologies in advance if this is an easy fix.
I am intrigued by the new .searchable modifier in SwiftUI as this seems like the most logical way to implement search in a SwiftUI-based app (instead of integrating with UIKit etc.)
I tried running the following code
import SwiftUI
struct SearchableView: View {
@State var searchTerm: String = ""
@Environment(\.isSearching)
private var isSearching: Bool
var body: some View {
NavigationView {
Text("\(String(describing: isSearching))")
}.searchable(text: $searchTerm)
}
}
However, the value of isSearching doesn't seem to be changing when I click on the search bar and start typing.
I tried adding @State to the isSearching variable but this resulted in an error.
I would be very grateful for any suggestions!
Thank you