add search to top bar

This commit is contained in:
cheykrym 2025-10-07 03:54:46 +03:00
parent c60358c7de
commit 6583ce38bb
2 changed files with 45 additions and 10 deletions

View File

@ -12,6 +12,8 @@ struct TopBarView: View {
// Привязка для управления боковым меню // Привязка для управления боковым меню
@Binding var isSideMenuPresented: Bool @Binding var isSideMenuPresented: Bool
@State private var searchText: String = ""
var isHomeTab: Bool { var isHomeTab: Bool {
return title == "Home" return title == "Home"
@ -103,12 +105,45 @@ struct TopBarView: View {
.padding() .padding()
.frame(height: 50) // Стандартная высота для нав. бара .frame(height: 50) // Стандартная высота для нав. бара
if isChatsTab {
searchBar
.padding(.horizontal)
.padding(.bottom, 8)
}
Divider() Divider()
} }
.background(Color(UIColor.systemBackground)) .background(Color(UIColor.systemBackground))
} }
} }
private extension TopBarView {
var searchBar: some View {
HStack(spacing: 8) {
Image(systemName: "magnifyingglass")
.foregroundColor(.secondary)
TextField(NSLocalizedString("Поиск", comment: ""), text: $searchText)
.textFieldStyle(.plain)
.textInputAutocapitalization(.never)
.autocorrectionDisabled()
if !searchText.isEmpty {
Button(action: { searchText = "" }) {
Image(systemName: "xmark.circle.fill")
.foregroundColor(.secondary)
}
.buttonStyle(.plain)
}
}
.padding(.horizontal, 12)
.padding(.vertical, 6)
.frame(minHeight: 36)
.background(
RoundedRectangle(cornerRadius: 12, style: .continuous)
.fill(Color(UIColor.secondarySystemBackground))
)
}
}
struct TopBarView_Previews: PreviewProvider { struct TopBarView_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
/*@START_MENU_TOKEN@*/Text("Hello, World!")/*@END_MENU_TOKEN@*/ /*@START_MENU_TOKEN@*/Text("Hello, World!")/*@END_MENU_TOKEN@*/

View File

@ -115,16 +115,16 @@ struct ChatsTab: View {
} }
} }
.listStyle(.plain) .listStyle(.plain)
.safeAreaInset(edge: .top) { // .safeAreaInset(edge: .top) {
VStack(spacing: 0) { // VStack(spacing: 0) {
searchBar // searchBar
.padding(.horizontal, 16) // .padding(.horizontal, 16)
.padding(.top, 8) // .padding(.top, 8)
.padding(.bottom, 8) // .padding(.bottom, 8)
Divider() // Divider()
} // }
.background(Color(UIColor.systemBackground)) // .background(Color(UIColor.systemBackground))
} // }
} }
private var searchBar: some View { private var searchBar: some View {