add search to top bar
This commit is contained in:
		
							parent
							
								
									c60358c7de
								
							
						
					
					
						commit
						6583ce38bb
					
				@ -12,6 +12,8 @@ struct TopBarView: View {
 | 
			
		||||
    
 | 
			
		||||
    // Привязка для управления боковым меню
 | 
			
		||||
    @Binding var isSideMenuPresented: Bool
 | 
			
		||||
 | 
			
		||||
    @State private var searchText: String = ""
 | 
			
		||||
    
 | 
			
		||||
    var isHomeTab: Bool {
 | 
			
		||||
        return title == "Home"
 | 
			
		||||
@ -103,12 +105,45 @@ struct TopBarView: View {
 | 
			
		||||
            .padding()
 | 
			
		||||
            .frame(height: 50) // Стандартная высота для нав. бара
 | 
			
		||||
            
 | 
			
		||||
            if isChatsTab {
 | 
			
		||||
                searchBar
 | 
			
		||||
                    .padding(.horizontal)
 | 
			
		||||
                    .padding(.bottom, 8)
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Divider()
 | 
			
		||||
        }
 | 
			
		||||
        .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 {
 | 
			
		||||
    static var previews: some View {
 | 
			
		||||
        /*@START_MENU_TOKEN@*/Text("Hello, World!")/*@END_MENU_TOKEN@*/
 | 
			
		||||
 | 
			
		||||
@ -115,16 +115,16 @@ struct ChatsTab: View {
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        .listStyle(.plain)
 | 
			
		||||
        .safeAreaInset(edge: .top) {
 | 
			
		||||
            VStack(spacing: 0) {
 | 
			
		||||
                searchBar
 | 
			
		||||
                    .padding(.horizontal, 16)
 | 
			
		||||
                    .padding(.top, 8)
 | 
			
		||||
                    .padding(.bottom, 8)
 | 
			
		||||
                Divider()
 | 
			
		||||
            }
 | 
			
		||||
            .background(Color(UIColor.systemBackground))
 | 
			
		||||
        }
 | 
			
		||||
//        .safeAreaInset(edge: .top) {
 | 
			
		||||
//            VStack(spacing: 0) {
 | 
			
		||||
//                searchBar
 | 
			
		||||
//                    .padding(.horizontal, 16)
 | 
			
		||||
//                    .padding(.top, 8)
 | 
			
		||||
//                    .padding(.bottom, 8)
 | 
			
		||||
//                Divider()
 | 
			
		||||
//            }
 | 
			
		||||
//            .background(Color(UIColor.systemBackground))
 | 
			
		||||
//        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private var searchBar: some View {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user