mirror of
https://github.com/cranci1/Sora.git
synced 2026-04-14 13:30:23 +00:00
add debounce to SearchBar (#81)
This commit is contained in:
parent
c582d45fb5
commit
ad07457cf7
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.5, repeats: false) { _ in
|
||||
// Perform the action after the delay (debouncing)
|
||||
onSearchButtonClicked()
|
||||
}
|
||||
}
|
||||
.overlay(
|
||||
HStack {
|
||||
Image(systemName: "magnifyingglass")
|
||||
|
|
|
|||
Loading…
Reference in a new issue