Skip to content
This repository was archived by the owner on Dec 27, 2020. It is now read-only.

Commit 865e259

Browse files
committed
readme
1 parent 4a00ef6 commit 865e259

File tree

5 files changed

+33
-22
lines changed

5 files changed

+33
-22
lines changed

Examples/GridExamples/BuilderLayoutView.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ struct BuilderLayoutView: View {
2828
.cornerRadius(self.cornerRadius)
2929
}
3030
.padding(self.padding)
31-
.gridStyle(DefaultGridStyle(minItemWidth: minItemWidth, itemHeight: itemHeight, hSpacing: hSpacing, vSpacing: vSpacing))
31+
.gridStyle(
32+
AutoColumnsGridStyle(minItemWidth: minItemWidth, itemHeight: itemHeight, hSpacing: hSpacing, vSpacing: vSpacing)
33+
)
3234

3335
VStack {
3436
Slider(value: $itemsCount, in: itemsCountRange)

Examples/GridExamples/PerformanceLayoutView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct PerformanceLayoutView: View {
88
.foregroundColor(.random)
99
}
1010
.gridStyle(
11-
DefaultGridStyle(minItemWidth: 16, itemHeight: 16, spacing: 0)
11+
AutoColumnsGridStyle(minItemWidth: 16, itemHeight: 16, spacing: 0)
1212
)
1313
}
1414
}

README.md

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,49 @@ SwiftUI Grid view layout with auto-sizing items and flexible column count.
66
<img src="Resources/iPad1.png"/>
77
</center>
88

9-
## Examples
9+
## GridStyles
1010

1111
Open `/Examples/GridExamples.xcodeproj` for more examples for both iOS and macOS
1212

13+
14+
### AutoColumnsGridStyle (Default)
15+
1316
```swift
14-
/// Simple grid.
17+
Grid(0...100) { _ in
18+
Rectangle()
19+
.foregroundColor(.blue)
20+
}
21+
```
1522

16-
Grid(0...100, minimumItemWidth: 100) { _ in
23+
```
24+
Grid(0...100) { _ in
1725
Rectangle()
1826
.foregroundColor(.red)
19-
.frame(height: 100)
2027
}
28+
.gridStyle(
29+
AutoColumnsGridStyle(minItemWidth: 160, itemHeight: 80, hSpacing: 8, vSpacing: 8)
30+
)
2131
```
32+
### FixedColumnsGridStyle
2233

2334
```swift
24-
Grid {
25-
ForEach(0...10, id: \.self) { _ in
26-
Rectangle()
27-
.foregroundColor(.random)
28-
.frame(height: 20)
29-
}
35+
36+
Grid(0...100) { number in
37+
Card(title: "\(number)")
3038
}
39+
.gridStyle(
40+
FixedColumnsGridStyle(columns: 3, itemHeight: 160)
41+
)
3142
```
43+
### SingleColumnGridStyle
3244

3345
```swift
34-
/// Grid with minimum item width and fixed item height.
35-
36-
Grid(self.planets, minimumItemWidth: 320, spacing: 16) {
37-
PlanetView(planet: $0)
38-
.frame(height: 400)
39-
.onTapGesture {
40-
print("Selection:", $0)
41-
}
46+
Grid(0...100) { number in
47+
Card(title: "\(number)")
4248
}
49+
.gridStyle(
50+
SingleColumnGridStyle(itemHeight: 160)
51+
)
4352
```
4453

4554
## Performance

Sources/Grid/DefaultGridStyle.swift renamed to Sources/Grid/AutoColumnsGridStyle.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import SwiftUI
22

33
/// The default `Grid` style.
44
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
5-
public struct DefaultGridStyle: GridStyle {
5+
public struct AutoColumnsGridStyle: GridStyle {
66
public var padding = EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)
77

88
let minItemWidth: CGFloat

Sources/Grid/Grid+Style.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extension View {
3535
}
3636

3737
struct GridStyleKey: EnvironmentKey {
38-
static let defaultValue: GridStyle = DefaultGridStyle()
38+
static let defaultValue: GridStyle = AutoColumnsGridStyle()
3939
}
4040

4141
extension EnvironmentValues {

0 commit comments

Comments
 (0)