search_top_bar #1

Merged
cheykrym merged 7 commits from search_top_bar into main 2025-10-07 04:47:37 +03:00
2 changed files with 39 additions and 1 deletions
Showing only changes of commit 3d24e0afce - Show all commits

View File

@ -14,6 +14,7 @@ struct TopBarView: View {
@Binding var isSideMenuPresented: Bool
@State private var searchText: String = ""
@State private var isSearchBarVisible: Bool = false
var isHomeTab: Bool {
return title == "Home"
@ -105,15 +106,34 @@ struct TopBarView: View {
.padding()
.frame(height: 50) // Стандартная высота для нав. бара
if isChatsTab {
if isChatsTab && isSearchBarVisible {
searchBar
.padding(.horizontal)
.padding(.bottom, 8)
.transition(.move(edge: .top).combined(with: .opacity))
}
Divider()
}
.background(Color(UIColor.systemBackground))
.animation(.spring(response: 0.35, dampingFraction: 0.85), value: isSearchBarVisible)
.onReceive(NotificationCenter.default.publisher(for: .chatsTabRevealSearchBar)) { _ in
guard isChatsTab else { return }
withAnimation {
isSearchBarVisible = true
}
}
.onReceive(NotificationCenter.default.publisher(for: .chatsTabHideSearchBar)) { _ in
guard isChatsTab else { return }
withAnimation {
isSearchBarVisible = false
}
}
.onChange(of: isChatsTab) { isChats in
if !isChats {
isSearchBarVisible = false
}
}
}
}

View File

@ -115,6 +115,7 @@ struct ChatsTab: View {
}
}
.listStyle(.plain)
.simultaneousGesture(searchBarGesture)
// .safeAreaInset(edge: .top) {
// VStack(spacing: 0) {
// searchBar
@ -152,6 +153,21 @@ struct ChatsTab: View {
)
}
private var searchBarGesture: some Gesture {
DragGesture(minimumDistance: 24)
.onEnded { value in
let verticalTranslation = value.translation.height
let horizontalTranslation = value.translation.width
guard abs(verticalTranslation) > abs(horizontalTranslation) else { return }
if verticalTranslation > 24 {
NotificationCenter.default.post(name: .chatsTabRevealSearchBar, object: nil)
} else if verticalTranslation < -24 {
NotificationCenter.default.post(name: .chatsTabHideSearchBar, object: nil)
}
}
}
private var isSearching: Bool {
!searchText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
}
@ -620,4 +636,6 @@ private struct ChatPlaceholderView: View {
extension Notification.Name {
static let debugRefreshChats = Notification.Name("debugRefreshChats")
static let chatsTabRevealSearchBar = Notification.Name("chatsTabRevealSearchBar")
static let chatsTabHideSearchBar = Notification.Name("chatsTabHideSearchBar")
}