mirror of
https://github.com/cranci1/Sora.git
synced 2026-05-20 08:41:46 +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 {
|
struct SearchBar: View {
|
||||||
|
@State private var debounceTimer: Timer?
|
||||||
@Binding var text: String
|
@Binding var text: String
|
||||||
var onSearchButtonClicked: () -> Void
|
var onSearchButtonClicked: () -> Void
|
||||||
|
|
||||||
|
|
@ -321,6 +322,14 @@ struct SearchBar: View {
|
||||||
.padding(.horizontal, 25)
|
.padding(.horizontal, 25)
|
||||||
.background(Color(.systemGray6))
|
.background(Color(.systemGray6))
|
||||||
.cornerRadius(8)
|
.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(
|
.overlay(
|
||||||
HStack {
|
HStack {
|
||||||
Image(systemName: "magnifyingglass")
|
Image(systemName: "magnifyingglass")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue