mirror of
https://github.com/cranci1/Sora.git
synced 2026-05-07 18:49:39 +00:00
add debounce to SearchBar
This commit is contained in:
parent
0f85714268
commit
6640a8a4b7
1 changed files with 9 additions and 0 deletions
|
|
@ -311,6 +311,7 @@ struct SearchView: View {
|
|||
}
|
||||
|
||||
struct SearchBar: View {
|
||||
@State private var debounceTimer: Timer?
|
||||
@Binding var text: String
|
||||
var onSearchButtonClicked: () -> Void
|
||||
|
||||
|
|
@ -321,6 +322,14 @@ struct SearchBar: View {
|
|||
.padding(.horizontal, 25)
|
||||
.background(Color(.systemGray6))
|
||||
.cornerRadius(8)
|
||||
.onChange(of: text){newValue in
|
||||
debounceTimer?.invalidate()
|
||||
// Start a new timer to wait before performing the action
|
||||
debounceTimer = Timer.scheduledTimer(withTimeInterval: 0.25, repeats: false) { _ in
|
||||
// Perform the action after the delay (debouncing)
|
||||
onSearchButtonClicked()
|
||||
}
|
||||
}
|
||||
.overlay(
|
||||
HStack {
|
||||
Image(systemName: "magnifyingglass")
|
||||
|
|
|
|||
Loading…
Reference in a new issue