ExpandedSearchable opens up the capabilities of the SwiftUI searchable modifier and allows for additions of more properties such as custom scope bars. Since this is a reimplementation of UISearchController, changes to SwiftUI should not affect search bars that rely on the scope bar to always be present. Signed-off-by: kingbri <bdashore3@proton.me>
69 lines
2.2 KiB
Swift
69 lines
2.2 KiB
Swift
//
|
|
// ContentView.swift
|
|
// Ferrite
|
|
//
|
|
// Created by Brian Dashore on 7/1/22.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct ContentView: View {
|
|
@EnvironmentObject var scrapingModel: ScrapingViewModel
|
|
@EnvironmentObject var debridManager: DebridManager
|
|
@EnvironmentObject var navModel: NavigationViewModel
|
|
@EnvironmentObject var pluginManager: PluginManager
|
|
@EnvironmentObject var logManager: LoggingManager
|
|
|
|
@AppStorage("Behavior.AutocorrectSearch") var autocorrectSearch: Bool = false
|
|
|
|
@State private var isSearching = false
|
|
@State private var dismissAction: () -> () = {}
|
|
|
|
var body: some View {
|
|
NavView {
|
|
List {
|
|
SearchResultsView()
|
|
}
|
|
.listStyle(.insetGrouped)
|
|
.inlinedList(inset: 20)
|
|
.navigationTitle("Search")
|
|
.expandedSearchable(
|
|
text: $scrapingModel.searchText,
|
|
isSearching: $isSearching,
|
|
prompt: navModel.searchPrompt,
|
|
dismiss: $dismissAction,
|
|
scopeBarContent: {
|
|
SearchFilterHeaderView()
|
|
},
|
|
onSubmit: {
|
|
if let runningSearchTask = scrapingModel.runningSearchTask, runningSearchTask.isCancelled {
|
|
scrapingModel.runningSearchTask = nil
|
|
return
|
|
}
|
|
|
|
scrapingModel.runningSearchTask = Task {
|
|
let sources = pluginManager.fetchInstalledSources()
|
|
await scrapingModel.scanSources(
|
|
sources: sources,
|
|
debridManager: debridManager
|
|
)
|
|
|
|
logManager.hideIndeterminateToast()
|
|
scrapingModel.runningSearchTask = nil
|
|
}
|
|
}
|
|
)
|
|
.autocorrectionDisabled(!autocorrectSearch)
|
|
.esAutocapitalization(autocorrectSearch ? .sentences : .none)
|
|
.onAppear {
|
|
navModel.getSearchPrompt()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct ContentView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
ContentView()
|
|
}
|
|
}
|