add loading cell as last item
This commit is contained in:
parent
2cfc69640d
commit
0dc7eab1cd
|
@ -57,18 +57,23 @@ struct LibraryView: View {
|
|||
section.orthogonalScrollingBehavior = .continuous
|
||||
section.boundarySupplementaryItems = [header]
|
||||
return section
|
||||
} cell: { _, item in
|
||||
} cell: { _, cell in
|
||||
GeometryReader { _ in
|
||||
if item.type != "Folder" {
|
||||
NavigationLink(destination: LazyView { ItemView(item: item) }) {
|
||||
PortraitItemElement(item: item)
|
||||
}
|
||||
.buttonStyle(PlainNavigationLinkButtonStyle())
|
||||
.onAppear {
|
||||
if item == viewModel.items.last && viewModel.hasNextPage {
|
||||
viewModel.requestNextPageAsync()
|
||||
if let item = cell.item {
|
||||
if item.type != "Folder" {
|
||||
NavigationLink(destination: LazyView { ItemView(item: item) }) {
|
||||
PortraitItemElement(item: item)
|
||||
}
|
||||
.buttonStyle(PlainNavigationLinkButtonStyle())
|
||||
.onAppear {
|
||||
if item == viewModel.items.last && viewModel.hasNextPage {
|
||||
viewModel.requestNextPageAsync()
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if cell.loadingCell {
|
||||
ProgressView()
|
||||
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center)
|
||||
}
|
||||
}
|
||||
} supplementaryView: { _, indexPath in
|
||||
|
|
|
@ -12,7 +12,13 @@ import Foundation
|
|||
import JellyfinAPI
|
||||
import SwiftUICollection
|
||||
|
||||
typealias LibraryRow = CollectionRow<Int, BaseItemDto>
|
||||
typealias LibraryRow = CollectionRow<Int, LibraryRowCell>
|
||||
|
||||
struct LibraryRowCell: Hashable {
|
||||
let id = UUID()
|
||||
let item: BaseItemDto?
|
||||
var loadingCell: Bool = false
|
||||
}
|
||||
|
||||
final class LibraryViewModel: ViewModel {
|
||||
var parentID: String?
|
||||
|
@ -150,10 +156,22 @@ final class LibraryViewModel: ViewModel {
|
|||
if lastItemIndex > items.count {
|
||||
lastItemIndex = items.count
|
||||
}
|
||||
|
||||
var rowCells = [LibraryRowCell]()
|
||||
for item in items[firstItemIndex..<lastItemIndex] {
|
||||
let newCell = LibraryRowCell(item: item)
|
||||
rowCells.append(newCell)
|
||||
}
|
||||
if i == rowCount {
|
||||
var loadingCell = LibraryRowCell(item: nil)
|
||||
loadingCell.loadingCell = true
|
||||
rowCells.append(loadingCell)
|
||||
}
|
||||
|
||||
calculatedRows.append(
|
||||
LibraryRow(
|
||||
section: i,
|
||||
items: Array(items[firstItemIndex..<lastItemIndex])
|
||||
items: rowCells
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue