diff --git a/yobble/Components/TopBarView.swift b/yobble/Components/TopBarView.swift index 2e114ce..dd56610 100644 --- a/yobble/Components/TopBarView.swift +++ b/yobble/Components/TopBarView.swift @@ -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 + } } } } diff --git a/yobble/Views/Tab/ChatsTab.swift b/yobble/Views/Tab/ChatsTab.swift index 415f115..ab6140f 100644 --- a/yobble/Views/Tab/ChatsTab.swift +++ b/yobble/Views/Tab/ChatsTab.swift @@ -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