增加注解

This commit is contained in:
JinJiangHuang
2026-03-01 22:23:38 +08:00
parent 99a8cc799b
commit ee8c71dcd4
23 changed files with 374 additions and 24 deletions
+11
View File
@@ -2,13 +2,16 @@ import SwiftUI
/// - Android SearchActivity
struct SearchView: View {
///
@StateObject private var viewModel = SearchViewModel()
#if os(iOS)
/// iOS
private let columns = [
GridItem(.adaptive(minimum: 120, maximum: 160), spacing: 12)
]
#else
/// macOS
private let columns = [
GridItem(.adaptive(minimum: 140, maximum: 180), spacing: 16)
]
@@ -29,6 +32,7 @@ struct SearchView: View {
} else if !viewModel.results.isEmpty {
searchResults
} else if viewModel.keyword.isEmpty {
//
searchHistorySection
} else if let error = viewModel.errorMessage {
Spacer()
@@ -53,6 +57,7 @@ struct SearchView: View {
// MARK: -
///
private var searchBar: some View {
HStack(spacing: 12) {
HStack(spacing: 10) {
@@ -114,6 +119,7 @@ struct SearchView: View {
// MARK: -
///
private var searchResults: some View {
ScrollView {
LazyVGrid(columns: columns, spacing: 16) {
@@ -134,6 +140,7 @@ struct SearchView: View {
// MARK: -
///
private var searchHistorySection: some View {
VStack(alignment: .leading, spacing: 12) {
if !viewModel.searchHistory.isEmpty {
@@ -183,13 +190,16 @@ struct SearchView: View {
///
struct FlowLayout: Layout {
///
var spacing: CGFloat = 8
///
func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
let result = arrangement(proposal: proposal, subviews: subviews)
return result.size
}
///
func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {
let result = arrangement(proposal: ProposedViewSize(width: bounds.width, height: bounds.height), subviews: subviews)
for (index, position) in result.positions.enumerated() {
@@ -197,6 +207,7 @@ struct FlowLayout: Layout {
}
}
///
private func arrangement(proposal: ProposedViewSize, subviews: Subviews) -> (size: CGSize, positions: [CGPoint]) {
let maxWidth = proposal.width ?? .infinity
var positions: [CGPoint] = []