Skip to content

Commit 23d7a24

Browse files
committed
Added scrollable enabler/disabler
1 parent 40607ae commit 23d7a24

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Sources/QGrid/QGrid.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public struct QGrid<Data, Content>: View
4141
private let hSpacing: CGFloat
4242
private let vPadding: CGFloat
4343
private let hPadding: CGFloat
44+
private let scrollable: Bool
4445

4546
private let data: [Data.Element]
4647
private let content: (Data.Element) -> Content
@@ -66,6 +67,7 @@ public struct QGrid<Data, Content>: View
6667
hSpacing: CGFloat = 10,
6768
vPadding: CGFloat = 10,
6869
hPadding: CGFloat = 10,
70+
scrollable: Bool = true,
6971
content: @escaping (Data.Element) -> Content) {
7072
self.data = data.map { $0 }
7173
self.content = content
@@ -96,7 +98,7 @@ public struct QGrid<Data, Content>: View
9698
/// Declares the content and behavior of this view.
9799
public var body : some View {
98100
GeometryReader { geometry in
99-
ScrollView(showsIndicators: false) {
101+
ScrollView(axes, showsIndicators: false) {
100102
VStack(spacing: self.vSpacing) {
101103
ForEach((0..<self.rows).map { QGridIndex(id: $0) }) { row in
102104
self.rowAtIndex(row.id * self.cols,
@@ -137,5 +139,9 @@ public struct QGrid<Data, Content>: View
137139
let width = geometry.size.width - hSpacings - hPadding * 2
138140
return width / CGFloat(self.cols)
139141
}
142+
143+
private var scrollAxes: Axis.Set {
144+
return shouldScroll ? .vertical : []
145+
}
140146
}
141147

0 commit comments

Comments
 (0)