add dont close search

This commit is contained in:
cheykrym 2025-10-08 07:15:20 +03:00
parent 8c03574e6a
commit 21d120cb3d
2 changed files with 23 additions and 0 deletions

View File

@ -113,10 +113,16 @@ struct TopBarView: View {
}
.background(Color(UIColor.systemBackground))
.onChange(of: isChatsTab) { isChats in
let hasSearchText = !chatSearchText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
if !isChats {
guard !hasSearchText else { return }
withAnimation(.spring(response: 0.35, dampingFraction: 0.75)) {
chatSearchRevealProgress = 0
}
} else if hasSearchText {
withAnimation(.spring(response: 0.35, dampingFraction: 0.75)) {
chatSearchRevealProgress = 1
}
}
}
}

View File

@ -46,6 +46,12 @@ struct ChatsTab: View {
}
.onChange(of: searchText) { newValue in
handleSearchQueryChange(newValue)
let trimmed = newValue.trimmingCharacters(in: .whitespacesAndNewlines)
if !trimmed.isEmpty && searchRevealProgress < 1 {
withAnimation(.spring(response: 0.35, dampingFraction: 0.75)) {
searchRevealProgress = 1
}
}
}
.onDisappear {
globalSearchTask?.cancel()
@ -156,12 +162,23 @@ struct ChatsTab: View {
let delta = verticalTranslation / searchRevealDistance
let newProgress = searchDragStartProgress + delta
if isSearching && newProgress < 1 {
searchRevealProgress = 1
return
}
searchRevealProgress = max(0, min(1, newProgress))
}
.onEnded { _ in
guard isSearchGestureActive else { return }
isSearchGestureActive = false
if isSearching {
withAnimation(.spring(response: 0.35, dampingFraction: 0.75)) {
searchRevealProgress = 1
}
return
}
let target: CGFloat = searchRevealProgress > 0.5 ? 1 : 0
withAnimation(.spring(response: 0.35, dampingFraction: 0.75)) {
searchRevealProgress = target