Skip to content

Commit

Permalink
Merge pull request #19 from danurna/fix-stride-error
Browse files Browse the repository at this point in the history
Fix stride error
  • Loading branch information
pietropizzi authored Feb 21, 2022
2 parents 011a397 + 662ebd4 commit 777c3b9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
6 changes: 5 additions & 1 deletion Sources/GridStack/Array+chunked.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
extension Array {
func chunked(into size: Int) -> [[Element]] {
stride(from: 0, to: count, by: size).map {
guard size > 0 else {
return [self]
}

return stride(from: 0, to: count, by: size).map {
Array(self[$0 ..< Swift.min($0 + size, count)])
}
}
Expand Down
18 changes: 10 additions & 8 deletions Sources/GridStack/GridStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,16 @@ private struct InnerGrid<Content>: View where Content: View {
var body : some View {
ScrollView(.vertical) {
VStack(alignment: alignment, spacing: spacing) {
ForEach(rows, id: \.self) { row in
HStack(spacing: self.spacing) {
ForEach(row, id: \.self) { item in
// Pass the index and the cell width to the content
self.content(item, self.columnWidth)
.frame(width: self.columnWidth)
}
}.padding(.horizontal, self.spacing)
if self.columnWidth > 0 {
ForEach(rows, id: \.self) { row in
HStack(spacing: self.spacing) {
ForEach(row, id: \.self) { item in
// Pass the index and the cell width to the content
self.content(item, self.columnWidth)
.frame(width: self.columnWidth)
}
}.padding(.horizontal, self.spacing)
}
}
}
.padding(.top, spacing)
Expand Down

0 comments on commit 777c3b9

Please sign in to comment.