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())
.onAppear {
if item == viewModel.items.last && viewModel.hasNextPage {
print("Last item visible, load more items.")
viewModel.requestNextPageAsync()
}
if item == viewModel.items.last && viewModel.hasNextPage {
viewModel.requestNextPageAsync()
}
}
}
}

View File

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