GridStack.swift 635 B

12345678910111213141516171819202122232425
  1. import SwiftUI
  2. struct GridStack<Content: View>: View {
  3. let rows: Int
  4. let columns: Int
  5. let content: (Int, Int) -> Content
  6. var body: some View {
  7. VStack {
  8. ForEach(0 ..< rows, id: \.self) { row in
  9. HStack {
  10. ForEach(0 ..< self.columns, id: \.self) { column in
  11. self.content(row, column)
  12. }
  13. }
  14. }
  15. }
  16. }
  17. init(rows: Int, columns: Int, @ViewBuilder content: @escaping (Int, Int) -> Content) {
  18. self.rows = rows
  19. self.columns = columns
  20. self.content = content
  21. }
  22. }