From 0dc7eab1cddce5a9e7cfc16cccf6ec15a2e78a01 Mon Sep 17 00:00:00 2001 From: jhays Date: Fri, 15 Oct 2021 08:22:08 -0500 Subject: [PATCH] add loading cell as last item --- JellyfinPlayer tvOS/LibraryView.swift | 23 ++++++++++++++--------- Shared/ViewModels/LibraryViewModel.swift | 22 ++++++++++++++++++++-- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/JellyfinPlayer tvOS/LibraryView.swift b/JellyfinPlayer tvOS/LibraryView.swift index 1e908ec3..e7035067 100644 --- a/JellyfinPlayer tvOS/LibraryView.swift +++ b/JellyfinPlayer tvOS/LibraryView.swift @@ -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 diff --git a/Shared/ViewModels/LibraryViewModel.swift b/Shared/ViewModels/LibraryViewModel.swift index 828d32e3..48a0f5d4 100644 --- a/Shared/ViewModels/LibraryViewModel.swift +++ b/Shared/ViewModels/LibraryViewModel.swift @@ -12,7 +12,13 @@ import Foundation import JellyfinAPI import SwiftUICollection -typealias LibraryRow = CollectionRow +typealias LibraryRow = CollectionRow + +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..