QuickSearch is a SwiftUI SDK that lets you type into a .searchable
text field without first having to focus on it, which is how many native utilty apps behave.
This is convenient, since .searchable
text fields lack focus control and doesn't allow you to focus programmatically.
QuickSearch can be installed with the Swift Package Manager:
https://github.com/danielsaidi/QuickSearch.git
All you have to do to make QuickSearch work, is to apply a .quickSearch
view modifier after .searchable
:
struct ContentView: View {
@State
var query = ""
@State
var text = ""
@FocusState
var isTextFieldFocused
var body: some View {
NavigationStack {
VStack {
TextField("Type here...", text: $text)
}
.quickSearch(text: $query)
.searchable(text: $query)
}
}
}
If you can add .quickSearch
directly next to .searchable
, you can use .searchable(text:quickSearch:...)
instead. It is not as flexible as .searchable
, but works well to apply basic .searchable
capabilities.
For more information, please see the documentation.
The online documentation has more information, articles, code examples, etc.
The demo app lets you explore the library. To try it out, just open and run the Demo
project.
You can sponsor me on GitHub Sponsors or reach out for paid support, to help support my open-source projects.
Your support makes it possible for me to put more work into these projects and make them the best they can be.
Feel free to reach out if you have questions or want to contribute in any way:
- Website: danielsaidi.com
- Mastodon: @danielsaidi@mastodon.social
- Twitter: @danielsaidi
- E-mail: daniel.saidi@gmail.com
QuickSearch is available under the MIT license. See the LICENSE file for more info.