init: init proj
This commit is contained in:
31
DDYSClient/Views/Browse/ContentGridView.swift
Normal file
31
DDYSClient/Views/Browse/ContentGridView.swift
Normal file
@@ -0,0 +1,31 @@
|
||||
import SwiftUI
|
||||
|
||||
struct ContentGridView: View {
|
||||
let items: [ContentItem]
|
||||
var onNearEnd: (() -> Void)?
|
||||
|
||||
private let columns = [
|
||||
GridItem(.adaptive(minimum: 130, maximum: 180), spacing: 12)
|
||||
]
|
||||
|
||||
var body: some View {
|
||||
LazyVGrid(columns: columns, spacing: 16) {
|
||||
ForEach(items) { item in
|
||||
NavigationLink(value: item) {
|
||||
ContentCardView(item: item)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.onAppear {
|
||||
if let onNearEnd, isNearEnd(item) {
|
||||
onNearEnd()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func isNearEnd(_ item: ContentItem) -> Bool {
|
||||
guard let index = items.firstIndex(where: { $0.id == item.id }) else { return false }
|
||||
return index >= items.count - 4
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user