mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
replace searchable with a custom search bar
This commit is contained in:
parent
40eda0a6ca
commit
584aac6a3b
2 changed files with 53 additions and 13 deletions
|
|
@ -26,16 +26,16 @@ private let enableGrid = UIDevice.isIPad || FeatureFlag.enableGridCardsOnPhone
|
|||
.refreshable {
|
||||
loadItems(isRefresh: true)
|
||||
}
|
||||
.searchable(
|
||||
text: $viewModel.searchTerm
|
||||
) {
|
||||
if viewModel.searchTerm.isEmpty {
|
||||
Text("Inbox").searchCompletion("in:inbox ")
|
||||
Text("All").searchCompletion("in:all ")
|
||||
Text("Archived").searchCompletion("in:archive ")
|
||||
Text("Files").searchCompletion("type:file ")
|
||||
}
|
||||
}
|
||||
// .searchable(
|
||||
// text: $viewModel.searchTerm
|
||||
// ) {
|
||||
// if viewModel.searchTerm.isEmpty {
|
||||
// Text("Inbox").searchCompletion("in:inbox ")
|
||||
// Text("All").searchCompletion("in:all ")
|
||||
// Text("Archived").searchCompletion("in:archive ")
|
||||
// Text("Files").searchCompletion("type:file ")
|
||||
// }
|
||||
// }
|
||||
.onChange(of: viewModel.searchTerm) { _ in
|
||||
// Maybe we should debounce this, but
|
||||
// it feels like it works ok without
|
||||
|
|
@ -44,9 +44,6 @@ private let enableGrid = UIDevice.isIPad || FeatureFlag.enableGridCardsOnPhone
|
|||
.onChange(of: viewModel.selectedLabels) { _ in
|
||||
loadItems(isRefresh: true)
|
||||
}
|
||||
.onSubmit(of: .search) {
|
||||
loadItems(isRefresh: true)
|
||||
}
|
||||
.sheet(item: $viewModel.itemUnderLabelEdit) { item in
|
||||
ApplyLabelsView(mode: .item(item), onSave: nil)
|
||||
}
|
||||
|
|
@ -131,10 +128,13 @@ private let enableGrid = UIDevice.isIPad || FeatureFlag.enableGridCardsOnPhone
|
|||
@EnvironmentObject var dataService: DataService
|
||||
@Binding var prefersListLayout: Bool
|
||||
@State private var showLabelsSheet = false
|
||||
@State private var isSearching = false
|
||||
@ObservedObject var viewModel: HomeFeedViewModel
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 0) {
|
||||
SearchBar(searchTerm: $viewModel.searchTerm, isSearching: $isSearching)
|
||||
.padding(.bottom)
|
||||
ZStack(alignment: .bottom) {
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
HStack {
|
||||
|
|
|
|||
40
apple/OmnivoreKit/Sources/Views/SearchBar.swift
Normal file
40
apple/OmnivoreKit/Sources/Views/SearchBar.swift
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import SwiftUI
|
||||
|
||||
public struct SearchBar: View {
|
||||
@Binding var searchTerm: String
|
||||
@Binding var isSearching: Bool
|
||||
|
||||
public init(
|
||||
searchTerm: Binding<String>,
|
||||
isSearching: Binding<Bool>
|
||||
) {
|
||||
self._searchTerm = searchTerm
|
||||
self._isSearching = isSearching
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
HStack(spacing: 0) {
|
||||
TextField("Search", text: $searchTerm)
|
||||
.padding(.vertical, 8)
|
||||
.padding(.horizontal, 8)
|
||||
.background(Color(.systemGray6))
|
||||
.cornerRadius(8)
|
||||
.padding(.horizontal, 10)
|
||||
.onTapGesture {
|
||||
self.isSearching = true
|
||||
}
|
||||
|
||||
if isSearching {
|
||||
Button(
|
||||
action: {
|
||||
self.isSearching = false
|
||||
self.searchTerm = ""
|
||||
},
|
||||
label: { Text("Cancel") }
|
||||
)
|
||||
.padding(.trailing)
|
||||
.transition(.move(edge: .trailing))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue