Skip to content

Commit 39c7253

Browse files
committed
Updated README.md (+9 squashed commits)
Squashed commits: [38234d4] Updated README.md [5ab0717] Set ScrollDirection enum as public [abe7b3f] Fixed ScrollDirection enum [386f277] Removed accidentally added colons [3c54a3c] Use scrollDirection instead of scrollable parameter [0b520c1] Set scrollable initialization to init scrollable parameter [5831c5f] Added scrollable initialization with value true [fd01b01] Renamed scrollAxes to self.scrollAxes [0d036f8] Fixed incorrect variable names
1 parent 23d7a24 commit 39c7253

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ struct PeopleView: View {
8080
vSpacing: 50,
8181
hSpacing: 20,
8282
vPadding: 100,
83-
hPadding: 20) { person in
83+
hPadding: 20,
84+
scrollDirection: .horizontal) { person in
8485
GridCell(person: person)
8586
}
8687
}
@@ -130,7 +131,6 @@ struct PeopleView: View {
130131
Version `0.1.1` of `QGrid ` contains a very limited set of features. It could be extended by implementing the following tasks:
131132

132133
     ☘️ Parameterize spacing&padding configuration depending on the device orientation
133-
     ☘️ Add the option to specify scroll direction
134134
     ☘️ Add content-only initializer to QGrid struct, without a collection of identified data as argument (As in SwiftUI’s `List`)
135135
     ☘️ Add support for other platforms (watchOS)
136136
     ☘️ Add `Stack` layout option (as in `UICollectionView`)

Sources/QGrid/QGrid.swift

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import SwiftUI
3232
public struct QGrid<Data, Content>: View
3333
where Data : RandomAccessCollection, Content : View, Data.Element : Identifiable {
3434
private struct QGridIndex : Identifiable { var id: Int }
35+
public enum ScrollDirection { case vertical, horizontal, both, none }
3536

3637
// MARK: - STORED PROPERTIES
3738

@@ -41,7 +42,7 @@ public struct QGrid<Data, Content>: View
4142
private let hSpacing: CGFloat
4243
private let vPadding: CGFloat
4344
private let hPadding: CGFloat
44-
private let scrollable: Bool
45+
private let scrollDirection: ScrollDirection
4546

4647
private let data: [Data.Element]
4748
private let content: (Data.Element) -> Content
@@ -59,6 +60,7 @@ public struct QGrid<Data, Content>: View
5960
/// - hSpacing: Horizontal spacing: The distance between each cell in grid's row. If not provided, the default value will be used.
6061
/// - vPadding: Vertical padding: The distance between top/bottom edge of the grid and the parent view. If not provided, the default value will be used.
6162
/// - hPadding: Horizontal padding: The distance between leading/trailing edge of the grid and the parent view. If not provided, the default value will be used.
63+
/// - scrollDirection: Scrolling direction: The direction of scrolling behaviour. If not provided, the default `.vertical` value will be used.
6264
/// - content: A closure returning the content of the individual cell
6365
public init(_ data: Data,
6466
columns: Int,
@@ -67,7 +69,7 @@ public struct QGrid<Data, Content>: View
6769
hSpacing: CGFloat = 10,
6870
vPadding: CGFloat = 10,
6971
hPadding: CGFloat = 10,
70-
scrollable: Bool = true,
72+
scrollDirection: ScrollDirection = .vertical,
7173
content: @escaping (Data.Element) -> Content) {
7274
self.data = data.map { $0 }
7375
self.content = content
@@ -77,6 +79,7 @@ public struct QGrid<Data, Content>: View
7779
self.hSpacing = hSpacing
7880
self.vPadding = vPadding
7981
self.hPadding = hPadding
82+
self.scrollDirection = scrollDirection
8083
}
8184

8285
// MARK: - COMPUTED PROPERTIES
@@ -98,7 +101,7 @@ public struct QGrid<Data, Content>: View
98101
/// Declares the content and behavior of this view.
99102
public var body : some View {
100103
GeometryReader { geometry in
101-
ScrollView(axes, showsIndicators: false) {
104+
ScrollView(self.scrollAxes, showsIndicators: false) {
102105
VStack(spacing: self.vSpacing) {
103106
ForEach((0..<self.rows).map { QGridIndex(id: $0) }) { row in
104107
self.rowAtIndex(row.id * self.cols,
@@ -141,7 +144,18 @@ public struct QGrid<Data, Content>: View
141144
}
142145

143146
private var scrollAxes: Axis.Set {
144-
return shouldScroll ? .vertical : []
147+
switch scrollDirection {
148+
case .vertical:
149+
return [.vertical]
150+
case .horizontal:
151+
return [.horizontal]
152+
case .both:
153+
return [.vertical, .horizontal]
154+
case .none:
155+
return []
156+
default:
157+
return [.vertical]
158+
}
145159
}
146160
}
147161

0 commit comments

Comments
 (0)