feat: for tvOS
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import SwiftUI
|
||||
|
||||
#if !os(tvOS)
|
||||
struct SearchView: View {
|
||||
@State private var viewModel = SearchViewModel()
|
||||
|
||||
@@ -59,3 +60,4 @@ struct SearchView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
74
DDYSClient/Views/Search/TVSearchView.swift
Normal file
74
DDYSClient/Views/Search/TVSearchView.swift
Normal file
@@ -0,0 +1,74 @@
|
||||
#if os(tvOS)
|
||||
import SwiftUI
|
||||
|
||||
struct TVSearchView: View {
|
||||
@State private var viewModel = SearchViewModel()
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
VStack(spacing: 24) {
|
||||
// 搜索输入框
|
||||
HStack {
|
||||
TextField("搜索电影、电视剧...", text: $viewModel.query)
|
||||
.textFieldStyle(.plain)
|
||||
.onSubmit {
|
||||
Task { await viewModel.search() }
|
||||
}
|
||||
}
|
||||
.padding(.horizontal)
|
||||
|
||||
// 搜索结果
|
||||
if viewModel.isSearching {
|
||||
ProgressView("搜索中...")
|
||||
.frame(maxWidth: .infinity, minHeight: 300)
|
||||
} else if let error = viewModel.error {
|
||||
VStack(spacing: 16) {
|
||||
Image(systemName: "exclamationmark.triangle")
|
||||
.font(.system(size: 48))
|
||||
.foregroundStyle(.secondary)
|
||||
Text(error)
|
||||
.foregroundStyle(.secondary)
|
||||
Button("重试") {
|
||||
Task { await viewModel.search() }
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, minHeight: 300)
|
||||
} else if viewModel.hasSearched && viewModel.results.isEmpty {
|
||||
VStack(spacing: 12) {
|
||||
Image(systemName: "magnifyingglass")
|
||||
.font(.system(size: 48))
|
||||
.foregroundStyle(.secondary)
|
||||
Text("未找到「\(viewModel.query)」的相关内容")
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.frame(maxWidth: .infinity, minHeight: 300)
|
||||
} else if !viewModel.results.isEmpty {
|
||||
ContentGridView(items: viewModel.results) {
|
||||
Task { await viewModel.loadMore() }
|
||||
}
|
||||
.padding(.horizontal)
|
||||
|
||||
if viewModel.isLoadingMore {
|
||||
ProgressView()
|
||||
.padding()
|
||||
}
|
||||
} else {
|
||||
VStack(spacing: 16) {
|
||||
Image(systemName: "magnifyingglass")
|
||||
.font(.system(size: 48))
|
||||
.foregroundStyle(.tertiary)
|
||||
Text("输入关键词搜索影片")
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.frame(maxWidth: .infinity, minHeight: 300)
|
||||
}
|
||||
}
|
||||
.padding(.vertical)
|
||||
}
|
||||
.navigationTitle("搜索")
|
||||
.navigationDestination(for: ContentItem.self) { item in
|
||||
DetailView(item: item)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user