cleanup some row math

This commit is contained in:
jhays 2021-10-14 22:28:36 -05:00
parent ffde1c468d
commit 2cfc69640d
2 changed files with 7 additions and 7 deletions

View File

@ -65,10 +65,9 @@ struct LibraryView: View {
} }
.buttonStyle(PlainNavigationLinkButtonStyle()) .buttonStyle(PlainNavigationLinkButtonStyle())
.onAppear { .onAppear {
if item == viewModel.items.last && viewModel.hasNextPage { if item == viewModel.items.last && viewModel.hasNextPage {
print("Last item visible, load more items.") viewModel.requestNextPageAsync()
viewModel.requestNextPageAsync() }
}
} }
} }
} }

View File

@ -144,15 +144,16 @@ final class LibraryViewModel: ViewModel {
let rowCount = items.count / columns let rowCount = items.count / columns
var calculatedRows = [LibraryRow]() var calculatedRows = [LibraryRow]()
for i in (0...rowCount) { for i in (0...rowCount) {
let firstItemIndex = i * columns let firstItemIndex = i * columns
var lastItemIndex = firstItemIndex + columns var lastItemIndex = firstItemIndex + columns
if lastItemIndex >= items.count { if lastItemIndex > items.count {
lastItemIndex = items.count - 1 lastItemIndex = items.count
} }
calculatedRows.append( calculatedRows.append(
LibraryRow( LibraryRow(
section: i, section: i,
items: Array(items[firstItemIndex...lastItemIndex]) items: Array(items[firstItemIndex..<lastItemIndex])
) )
) )
} }