56 lines
1.8 KiB
Swift
56 lines
1.8 KiB
Swift
//
|
|
// SearchView.swift
|
|
// tg_test
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct SearchView: View {
|
|
@State private var searchText = ""
|
|
private let categories = ["SwiftUI", "Xcode", "iOS 18", "Design", "Swift", "Animations"]
|
|
|
|
var filteredCategories: [String] {
|
|
if searchText.isEmpty {
|
|
return categories
|
|
} else {
|
|
return categories.filter { $0.localizedCaseInsensitiveContains(searchText) }
|
|
}
|
|
}
|
|
|
|
var body: some View {
|
|
NavigationStack {
|
|
ScrollView {
|
|
VStack(alignment: .leading, spacing: 16) {
|
|
Text("Browse Categories")
|
|
.font(.headline)
|
|
.padding(.horizontal)
|
|
|
|
LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible())], spacing: 12) {
|
|
ForEach(filteredCategories, id: \.self) { category in
|
|
VStack {
|
|
Image(systemName: "folder.fill")
|
|
.font(.largeTitle)
|
|
.foregroundStyle(.blue)
|
|
Text(category)
|
|
.font(.callout)
|
|
.bold()
|
|
}
|
|
.frame(maxWidth: .infinity)
|
|
.padding()
|
|
.background(Color(.secondarySystemBackground))
|
|
.clipShape(RoundedRectangle(cornerRadius: 12))
|
|
}
|
|
}
|
|
.padding(.horizontal)
|
|
}
|
|
.padding(.top)
|
|
}
|
|
.navigationTitle("Search")
|
|
.searchable(text: $searchText, prompt: "Search topics...")
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
SearchView()
|
|
}
|