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

Commit 1f9807e

Browse files
authored
sectioned grid (#90)
1 parent 0b35d0d commit 1f9807e

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

GridDemo macOS/ContentView.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ struct ContentView: View {
1212
NavigationLink(destination: StaggeredGridView()) {
1313
Text("Staggered Grid")
1414
}
15+
16+
NavigationLink(destination: SectionedGridView()) {
17+
Text("Sectioned Grid")
18+
}
1519
}
1620
}
1721
.frame(minWidth: 200, maxWidth: 300)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import SwiftUI
2+
import Grid
3+
4+
struct SectionedGridView: View {
5+
var body: some View {
6+
ScrollView {
7+
ForEach(1..<8) { section in
8+
Section {
9+
HStack {
10+
Text("Section \(section)").font(.headline).fontWeight(.bold)
11+
Spacer()
12+
}
13+
14+
Grid(self.rangeFor(section: section), id: \.self) { index in
15+
Rectangle()
16+
.foregroundColor(.clear)
17+
.background(
18+
Image("\(index)")
19+
.renderingMode(.original)
20+
.resizable()
21+
.scaledToFill()
22+
)
23+
.clipped()
24+
.clipShape(RoundedRectangle(cornerRadius: 4))
25+
}
26+
27+
Spacer(minLength: 16)
28+
}
29+
}
30+
31+
.padding(8)
32+
}
33+
.gridStyle(
34+
ModularGridStyle(columns: .min(100), rows: .fixed(100), spacing: 4)
35+
)
36+
}
37+
38+
private func rangeFor(section: Int) -> Range<Int> {
39+
switch section {
40+
case 1: return Range(1...10)
41+
case 2: return Range(11...15)
42+
case 3: return Range(16...26)
43+
case 4: return Range(27...35)
44+
case 5: return Range(36...38)
45+
case 6: return Range(39...55)
46+
case 7: return Range(56...69)
47+
default:
48+
fatalError()
49+
}
50+
}
51+
}
52+
53+
struct SectionedGridView_Previews: PreviewProvider {
54+
static var previews: some View {
55+
SectionedGridView()
56+
}
57+
}

GridDemo.xcodeproj/project.pbxproj

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
FA6203C323F8AD77009CB0C9 /* Grid in Frameworks */ = {isa = PBXBuildFile; productRef = FA6203C223F8AD77009CB0C9 /* Grid */; };
11+
FA9FFB6D242FFECD0047D145 /* SectionedGrid.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA9FFB6C242FFECD0047D145 /* SectionedGrid.swift */; };
1112
FAA2C96C23DEAECC00FBDE39 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA2C96B23DEAECC00FBDE39 /* SceneDelegate.swift */; };
1213
FAA2C96E23DEAECC00FBDE39 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA2C96D23DEAECC00FBDE39 /* ContentView.swift */; };
1314
FAA2C97623DEAECD00FBDE39 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FAA2C97423DEAECD00FBDE39 /* LaunchScreen.storyboard */; };
@@ -113,6 +114,7 @@
113114
/* End PBXCopyFilesBuildPhase section */
114115

115116
/* Begin PBXFileReference section */
117+
FA9FFB6C242FFECD0047D145 /* SectionedGrid.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SectionedGrid.swift; sourceTree = "<group>"; };
116118
FAA2C96723DEAECC00FBDE39 /* GridDemo iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "GridDemo iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; };
117119
FAA2C96B23DEAECC00FBDE39 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
118120
FAA2C96D23DEAECC00FBDE39 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
@@ -169,7 +171,7 @@
169171
FAA2CA5323DEB66900FBDE39 /* StaggeredGridView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StaggeredGridView.swift; sourceTree = "<group>"; };
170172
FAA2CA5823DEB73200FBDE39 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
171173
FAAA2FCC241C42E4007021F7 /* ImageDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageDetailView.swift; sourceTree = "<group>"; };
172-
FAC9D4DC23DF8C750007B7DD /* */ = {isa = PBXFileReference; lastKnownFileType = folder; name = ""; sourceTree = "<group>"; };
174+
FAC9D4DC23DF8C750007B7DD /* */ = {isa = PBXFileReference; lastKnownFileType = folder; name = ""; sourceTree = SOURCE_ROOT; };
173175
/* End PBXFileReference section */
174176

175177
/* Begin PBXFrameworksBuildPhase section */
@@ -208,6 +210,14 @@
208210
/* End PBXFrameworksBuildPhase section */
209211

210212
/* Begin PBXGroup section */
213+
FA9FFB6B242FFE510047D145 /* SectionedGrid */ = {
214+
isa = PBXGroup;
215+
children = (
216+
FA9FFB6C242FFECD0047D145 /* SectionedGrid.swift */,
217+
);
218+
path = SectionedGrid;
219+
sourceTree = "<group>";
220+
};
211221
FAA2C93B23DEAD2600FBDE39 = {
212222
isa = PBXGroup;
213223
children = (
@@ -301,6 +311,7 @@
301311
FAA2C99D23DEB26200FBDE39 /* GridDemo macOS */ = {
302312
isa = PBXGroup;
303313
children = (
314+
FA9FFB6B242FFE510047D145 /* SectionedGrid */,
304315
FAA2C9B323DEB31800FBDE39 /* ModularGrid */,
305316
FAA2C9B623DEB31800FBDE39 /* StaggeredGrid */,
306317
FAA2C99E23DEB26200FBDE39 /* AppDelegate.swift */,
@@ -689,6 +700,7 @@
689700
isa = PBXSourcesBuildPhase;
690701
buildActionMask = 2147483647;
691702
files = (
703+
FA9FFB6D242FFECD0047D145 /* SectionedGrid.swift in Sources */,
692704
FAA2C9B023DEB26B00FBDE39 /* Item.swift in Sources */,
693705
FAA2C9AF23DEB26B00FBDE39 /* Color+Random.swift in Sources */,
694706
FAA2C9BB23DEB31900FBDE39 /* StaggeredGridSettingsView.swift in Sources */,

0 commit comments

Comments
 (0)