Impressia/Vernissage/Views/SearchView/SearchView.swift

74 lines
2.3 KiB
Swift
Raw Normal View History

2023-03-06 16:00:53 +01:00
//
// https://mczachurski.dev
// Copyright © 2023 Marcin Czachurski and the repository contributors.
// Licensed under the MIT License.
//
import SwiftUI
struct SearchView: View {
@State private var query = String.empty()
@FocusState private var focusedField: FocusField?
enum FocusField: Hashable {
case unknown
case search
}
var body: some View {
List {
Section {
HStack {
TextField("Search...", text: $query)
.padding(8)
2023-03-06 16:29:37 +01:00
.focused($focusedField, equals: .search)
2023-03-06 16:00:53 +01:00
.keyboardType(.default)
.autocapitalization(.none)
.autocorrectionDisabled()
2023-03-06 16:29:37 +01:00
.onAppear() {
self.focusedField = .search
}
2023-03-06 16:00:53 +01:00
Spacer()
Button {
} label: {
Text("Search")
}
.buttonStyle(.bordered)
}
}
if self.query.isEmpty == false {
Section {
NavigationLink(value: RouteurDestinations.search) {
Label("Users with \"\(query)\"", systemImage: "person.3.sequence")
}
NavigationLink(value: RouteurDestinations.search) {
Label("Go to user \"\(query)\"", systemImage: "person.crop.circle")
}
}
Section {
NavigationLink(value: RouteurDestinations.search) {
Label("Hashtags with \"\(query)\"", systemImage: "tag")
}
NavigationLink(value: RouteurDestinations.search) {
Label("Hashtags with \"\(query)\"", systemImage: "tag.circle")
}
}
}
2023-03-06 16:29:37 +01:00
}
.onTapGesture {
self.focusedField = .unknown
hideKeyboard()
2023-03-06 16:00:53 +01:00
}
.navigationTitle("Search")
}
}