Skip to content

Commit

Permalink
Introduce SearchBar view
Browse files Browse the repository at this point in the history
  • Loading branch information
lunij committed Sep 21, 2024
1 parent 6731a6b commit 2bac0ba
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
38 changes: 38 additions & 0 deletions Sources/Netbob/Core/UI/SearchBar.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// Copyright © Marc Schultz. All rights reserved.
//

import SwiftUI

struct SearchBar: View {
@Binding var text: String

var body: some View {
TextField("Search ...", text: $text)
.padding(7)
.padding(.horizontal, 25)
.background(Color(.systemGray6))
.cornerRadius(8)
.overlay(
HStack {
Image(systemName: "magnifyingglass")
.foregroundColor(.gray)
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
.padding(.leading, 8)

if !text.isEmpty {
Button { text = "" } label: {
Image(systemName: "xmark.circle.fill")
.foregroundColor(.gray)
.padding(.trailing, 8)
}
}
}
)
}
}

#Preview {
SearchBar(text: .constant(""))
SearchBar(text: .constant("fake"))
}
17 changes: 3 additions & 14 deletions Sources/Netbob/Modules/List/ListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ struct ListView: View {
@StateObject var state: ListViewStateAbstract

var body: some View {
searchBar
SearchBar(text: $state.searchText)
.padding(.horizontal)

List {
ForEach(state.connections) { viewData in
NavigationLink(destination: DetailView(state: .init(connection: viewData.connection))) {
Expand Down Expand Up @@ -47,19 +49,6 @@ struct ListView: View {
}
.font(.system(size: 20, weight: .light))
}

var searchBar: some View {
HStack {
Image(systemName: "magnifyingglass")
TextField("Search by address", text: $state.searchText)
}
.font(.headline)
.padding(.top)
.background(
RoundedRectangle(cornerRadius: 25)
.fill(Color.white)
)
}
}

struct ListRow: View {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2bac0ba

Please sign in to comment.