mirror of
https://github.com/yattee/yattee.git
synced 2025-08-06 10:44:06 +00:00
Add placeholders
This commit is contained in:
@@ -9,11 +9,12 @@ struct VerticalCells: View {
|
||||
@Environment(\.loadMoreContentHandler) private var loadMoreContentHandler
|
||||
|
||||
var items = [ContentItem]()
|
||||
var allowEmpty = false
|
||||
|
||||
var body: some View {
|
||||
ScrollView(.vertical, showsIndicators: scrollViewShowsIndicators) {
|
||||
LazyVGrid(columns: columns, alignment: .center) {
|
||||
ForEach(items.sorted { $0 < $1 }) { item in
|
||||
ForEach(contentItems) { item in
|
||||
ContentItemView(item: item)
|
||||
.onAppear { loadMoreContentItemsIfNeeded(current: item) }
|
||||
}
|
||||
@@ -27,6 +28,14 @@ struct VerticalCells: View {
|
||||
#endif
|
||||
}
|
||||
|
||||
var contentItems: [ContentItem] {
|
||||
items.isEmpty ? (allowEmpty ? items : placeholders) : items.sorted { $0 < $1 }
|
||||
}
|
||||
|
||||
var placeholders: [ContentItem] {
|
||||
(0 ..< 9).map { _ in .init() }
|
||||
}
|
||||
|
||||
func loadMoreContentItemsIfNeeded(current item: ContentItem) {
|
||||
let thresholdIndex = items.index(items.endIndex, offsetBy: -5)
|
||||
if items.firstIndex(where: { $0.id == item.id }) == thresholdIndex {
|
||||
|
Reference in New Issue
Block a user