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

Commit 9784cc9

Browse files
authored
examples (#32)
1 parent 6dd579e commit 9784cc9

File tree

6 files changed

+50
-51
lines changed

6 files changed

+50
-51
lines changed

Examples/GridExamples iOS/ModularGridView.swift

+3-21
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,14 @@ import SwiftUI
22
import Grid
33

44
struct ModularGridView: View {
5-
@State var selection: Int = 0
6-
@State var items: [(Int, Color)] = (0...100).map { ($0, .random) }
5+
@State var items: [Item] = (0...100).map { Item(number: $0) }
76

87
var body: some View {
98
NavigationView {
10-
Grid(items, id: \.0) { item in
11-
Card(title: "\(item.0)", color: item.1)
12-
.onTapGesture {
13-
self.selection = item.0
14-
}
9+
Grid(items) { item in
10+
Card(title: "\(item.number)", color: item.color)
1511
}
1612
.navigationBarTitle("Modular Grid", displayMode: .inline)
17-
.overlayPreferenceValue(GridItemBoundsPreferencesKey.self) { preferences in
18-
RoundedRectangle(cornerRadius: 16)
19-
.strokeBorder(lineWidth: 4)
20-
.foregroundColor(.white)
21-
.frame(
22-
width: preferences[self.selection].width,
23-
height: preferences[self.selection].height
24-
)
25-
.position(
26-
x: preferences[self.selection].midX,
27-
y: preferences[self.selection].midY
28-
)
29-
.animation(.linear)
30-
}
3113
}
3214
.gridStyle(
3315
ModularGridStyle(columns: .auto(.min(100)), rows: .auto(.min(100)))

Examples/GridExamples macOS/ModularGridView.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import Grid
33

44
struct ModularGridView: View {
55
@State var selection: Int = 0
6-
@State var items: [(Int, Color)] = (0...100).map { ($0, .random) }
6+
@State var items: [Item] = (0...100).map { Item(number: $0) }
77

88
var body: some View {
9-
Grid(items, id: \.0) { item in
10-
Card(title: "\(item.0)", color: item.1)
9+
Grid(items) { item in
10+
Card(title: "\(item.number)", color: item.color)
1111
.onTapGesture {
12-
self.selection = item.0
12+
self.selection = item.number
1313
}
1414
}
1515
.overlayPreferenceValue(GridItemBoundsPreferencesKey.self) { preferences in

Examples/GridExamples tvOS/ModularGridView.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import Grid
33

44
struct ModularGridView: View {
55
@State var selection: Int = 0
6-
@State var items: [(Int, Color)] = (0...100).map { ($0, .random) }
6+
@State var items: [Item] = (0...100).map { Item(number: $0) }
77

88
var body: some View {
9-
Grid(items, id: \.0) { item in
10-
Card(title: "\(item.0)", color: item.1)
9+
Grid(items) { item in
10+
Card(title: "\(item.number)", color: item.color)
1111
.focusable(true) { focus in
1212
if focus {
13-
self.selection = item.0
13+
self.selection = item.number
1414
}
1515
}
1616
}

Examples/GridExamples watchOS WatchKit Extension/ModularGridView.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import Grid
33

44
struct ModularGridView: View {
55
@State var selection: Int = 0
6-
@State var items: [(Int, Color)] = (0...100).map { ($0, .random) }
6+
@State var items: [Item] = (0...100).map { Item(number: $0) }
77

88
var body: some View {
9-
Grid(items, id: \.0) { item in
9+
Grid(items) { item in
1010
Rectangle()
11-
.foregroundColor(item.1)
11+
.foregroundColor(item.color)
1212
.cornerRadius(4)
1313
.onTapGesture {
14-
self.selection = item.0
14+
self.selection = item.number
1515
}
1616
}
1717
.overlayPreferenceValue(GridItemBoundsPreferencesKey.self) { preferences in

Examples/GridExamples.xcodeproj/project.pbxproj

+28-18
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
FA902162230B379D00BF9341 /* Color+Random.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA902160230B379D00BF9341 /* Color+Random.swift */; };
5757
FA902164230B389900BF9341 /* Card.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA902163230B389900BF9341 /* Card.swift */; };
5858
FA902165230B389900BF9341 /* Card.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA902163230B389900BF9341 /* Card.swift */; };
59+
FAAF755F2381E9F500DFDE03 /* Item.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAAF755E2381E9F500DFDE03 /* Item.swift */; };
60+
FAAF75602381E9F500DFDE03 /* Item.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAAF755E2381E9F500DFDE03 /* Item.swift */; };
61+
FAAF75612381E9F500DFDE03 /* Item.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAAF755E2381E9F500DFDE03 /* Item.swift */; };
62+
FAAF75622381E9F500DFDE03 /* Item.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAAF755E2381E9F500DFDE03 /* Item.swift */; };
5963
/* End PBXBuildFile section */
6064

6165
/* Begin PBXContainerItemProxy section */
@@ -122,15 +126,15 @@
122126
FA61E97323134508006A5B6B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
123127
FA61E97623134508006A5B6B /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
124128
FA61E97823134508006A5B6B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
125-
FA61E994231351FC006A5B6B /* GridExamples tvOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "GridExamples tvOS.app"; sourceTree = BUILT_PRODUCTS_DIR; };
129+
FA61E994231351FC006A5B6B /* GridExamples.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GridExamples.app; sourceTree = BUILT_PRODUCTS_DIR; };
126130
FA61E996231351FC006A5B6B /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
127131
FA61E998231351FC006A5B6B /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
128132
FA61E99A231351FD006A5B6B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
129133
FA61E99D231351FD006A5B6B /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
130134
FA61E9A0231351FD006A5B6B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
131135
FA61E9A2231351FD006A5B6B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
132136
FA6ED895231197C600651DD9 /* GridExamples iOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "GridExamples iOS.entitlements"; sourceTree = "<group>"; };
133-
FA902111230B32EA00BF9341 /* GridExamples iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "GridExamples iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; };
137+
FA902111230B32EA00BF9341 /* GridExamples.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GridExamples.app; sourceTree = BUILT_PRODUCTS_DIR; };
134138
FA902114230B32EA00BF9341 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
135139
FA902116230B32EA00BF9341 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
136140
FA902118230B32EA00BF9341 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
@@ -139,7 +143,7 @@
139143
FA902120230B32EC00BF9341 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
140144
FA902122230B32EC00BF9341 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
141145
FA902129230B335C00BF9341 /* grid */ = {isa = PBXFileReference; lastKnownFileType = folder; name = grid; path = ..; sourceTree = "<group>"; };
142-
FA902146230B341C00BF9341 /* GridExamples macOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "GridExamples macOS.app"; sourceTree = BUILT_PRODUCTS_DIR; };
146+
FA902146230B341C00BF9341 /* GridExamples.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GridExamples.app; sourceTree = BUILT_PRODUCTS_DIR; };
143147
FA902148230B341C00BF9341 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
144148
FA90214A230B341C00BF9341 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
145149
FA90214C230B341D00BF9341 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@@ -150,6 +154,7 @@
150154
FA902160230B379D00BF9341 /* Color+Random.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Color+Random.swift"; sourceTree = "<group>"; };
151155
FA902163230B389900BF9341 /* Card.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Card.swift; sourceTree = "<group>"; };
152156
FA90216F230B4AC300BF9341 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
157+
FAAF755E2381E9F500DFDE03 /* Item.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Item.swift; sourceTree = "<group>"; };
153158
/* End PBXFileReference section */
154159

155160
/* Begin PBXFrameworksBuildPhase section */
@@ -263,12 +268,12 @@
263268
FA902112230B32EA00BF9341 /* Products */ = {
264269
isa = PBXGroup;
265270
children = (
266-
FA902111230B32EA00BF9341 /* GridExamples iOS.app */,
267-
FA902146230B341C00BF9341 /* GridExamples macOS.app */,
268-
FA61E95623134504006A5B6B /* GridExamples watchOS.app */,
269-
FA61E95923134505006A5B6B /* GridExamples watchOS WatchKit App.app */,
270-
FA61E96823134507006A5B6B /* GridExamples watchOS WatchKit Extension.appex */,
271-
FA61E994231351FC006A5B6B /* GridExamples tvOS.app */,
271+
FA902111230B32EA00BF9341 /* GridExamples.app */,
272+
FA902146230B341C00BF9341 /* GridExamples.app */,
273+
FA61E95623134504006A5B6B /* GridExamples.app */,
274+
FA61E95923134505006A5B6B /* GridExamples.app */,
275+
FA61E96823134507006A5B6B /* GridExamples.appex */,
276+
FA61E994231351FC006A5B6B /* GridExamples.app */,
272277
);
273278
name = Products;
274279
sourceTree = "<group>";
@@ -333,6 +338,7 @@
333338
isa = PBXGroup;
334339
children = (
335340
FA902160230B379D00BF9341 /* Color+Random.swift */,
341+
FAAF755E2381E9F500DFDE03 /* Item.swift */,
336342
FA902163230B389900BF9341 /* Card.swift */,
337343
FA0FB89E23811E5900B6E84F /* SharedAssets.xcassets */,
338344
);
@@ -413,7 +419,7 @@
413419
FA61E9A623135319006A5B6B /* Grid */,
414420
);
415421
productName = "GridExamples tvOS";
416-
productReference = FA61E994231351FC006A5B6B /* GridExamples tvOS.app */;
422+
productReference = FA61E994231351FC006A5B6B /* GridExamples.app */;
417423
productType = "com.apple.product-type.application";
418424
};
419425
FA902110230B32EA00BF9341 /* GridExamples iOS */ = {
@@ -433,7 +439,7 @@
433439
FA66B37C235653DC00AB542A /* Grid */,
434440
);
435441
productName = "GridExamples iOS";
436-
productReference = FA902111230B32EA00BF9341 /* GridExamples iOS.app */;
442+
productReference = FA902111230B32EA00BF9341 /* GridExamples.app */;
437443
productType = "com.apple.product-type.application";
438444
};
439445
FA902145230B341C00BF9341 /* GridExamples macOS */ = {
@@ -453,7 +459,7 @@
453459
FA90215A230B346600BF9341 /* Grid */,
454460
);
455461
productName = "GridExamples macOS";
456-
productReference = FA902146230B341C00BF9341 /* GridExamples macOS.app */;
462+
productReference = FA902146230B341C00BF9341 /* GridExamples.app */;
457463
productType = "com.apple.product-type.application";
458464
};
459465
/* End PBXNativeTarget section */
@@ -583,6 +589,7 @@
583589
FA61E98A23134CF8006A5B6B /* Color+Random.swift in Sources */,
584590
FA61E97023134507006A5B6B /* HostingController.swift in Sources */,
585591
FA0FB8A723812DFA00B6E84F /* StaggeredGridView.swift in Sources */,
592+
FAAF75612381E9F500DFDE03 /* Item.swift in Sources */,
586593
FA61E96E23134507006A5B6B /* ContentView.swift in Sources */,
587594
FA61E97223134507006A5B6B /* ExtensionDelegate.swift in Sources */,
588595
);
@@ -594,6 +601,7 @@
594601
files = (
595602
FA61E9A82313535F006A5B6B /* Color+Random.swift in Sources */,
596603
FA61E999231351FC006A5B6B /* ContentView.swift in Sources */,
604+
FAAF75622381E9F500DFDE03 /* Item.swift in Sources */,
597605
FA61E997231351FC006A5B6B /* AppDelegate.swift in Sources */,
598606
FA31E123237E5381005799AD /* ModularGridView.swift in Sources */,
599607
FA0FB8A923812F3700B6E84F /* StaggeredGridView.swift in Sources */,
@@ -610,6 +618,7 @@
610618
FA902164230B389900BF9341 /* Card.swift in Sources */,
611619
FA902117230B32EA00BF9341 /* SceneDelegate.swift in Sources */,
612620
FA0FB89D23811DC800B6E84F /* StaggeredGridView.swift in Sources */,
621+
FAAF755F2381E9F500DFDE03 /* Item.swift in Sources */,
613622
FA902119230B32EA00BF9341 /* ContentView.swift in Sources */,
614623
FA902161230B379D00BF9341 /* Color+Random.swift in Sources */,
615624
);
@@ -621,6 +630,7 @@
621630
files = (
622631
FA31E11F237E511B005799AD /* ModularGridView.swift in Sources */,
623632
FA902162230B379D00BF9341 /* Color+Random.swift in Sources */,
633+
FAAF75602381E9F500DFDE03 /* Item.swift in Sources */,
624634
FA90214B230B341C00BF9341 /* ContentView.swift in Sources */,
625635
FA902165230B389900BF9341 /* Card.swift in Sources */,
626636
FA902149230B341C00BF9341 /* AppDelegate.swift in Sources */,
@@ -1149,7 +1159,7 @@
11491159
MTL_FAST_MATH = YES;
11501160
ONLY_ACTIVE_ARCH = YES;
11511161
PRODUCT_BUNDLE_IDENTIFIER = com.swiftuiextensions.grid.examples.tvos;
1152-
PRODUCT_NAME = "$(TARGET_NAME)";
1162+
PRODUCT_NAME = GridExamples;
11531163
SDKROOT = appletvos;
11541164
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
11551165
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
@@ -1216,7 +1226,7 @@
12161226
MTL_ENABLE_DEBUG_INFO = NO;
12171227
MTL_FAST_MATH = YES;
12181228
PRODUCT_BUNDLE_IDENTIFIER = com.swiftuiextensions.grid.examples.tvos;
1219-
PRODUCT_NAME = "$(TARGET_NAME)";
1229+
PRODUCT_NAME = GridExamples;
12201230
SDKROOT = appletvos;
12211231
SWIFT_COMPILATION_MODE = wholemodule;
12221232
SWIFT_OPTIMIZATION_LEVEL = "-O";
@@ -1358,7 +1368,7 @@
13581368
MTL_FAST_MATH = YES;
13591369
ONLY_ACTIVE_ARCH = YES;
13601370
PRODUCT_BUNDLE_IDENTIFIER = com.swiftuiextensions.grid.examples.ios;
1361-
PRODUCT_NAME = "$(TARGET_NAME)";
1371+
PRODUCT_NAME = GridExamples;
13621372
SDKROOT = iphoneos;
13631373
SUPPORTS_MACCATALYST = YES;
13641374
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
@@ -1428,7 +1438,7 @@
14281438
MTL_ENABLE_DEBUG_INFO = NO;
14291439
MTL_FAST_MATH = YES;
14301440
PRODUCT_BUNDLE_IDENTIFIER = com.swiftuiextensions.grid.examples.ios;
1431-
PRODUCT_NAME = "$(TARGET_NAME)";
1441+
PRODUCT_NAME = GridExamples;
14321442
SDKROOT = iphoneos;
14331443
SUPPORTS_MACCATALYST = YES;
14341444
SWIFT_COMPILATION_MODE = wholemodule;
@@ -1508,7 +1518,7 @@
15081518
MTL_FAST_MATH = YES;
15091519
ONLY_ACTIVE_ARCH = YES;
15101520
PRODUCT_BUNDLE_IDENTIFIER = com.swiftuiextensions.grid.examples.macos;
1511-
PRODUCT_NAME = "$(TARGET_NAME)";
1521+
PRODUCT_NAME = GridExamples;
15121522
SDKROOT = macosx;
15131523
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
15141524
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
@@ -1578,7 +1588,7 @@
15781588
MTL_ENABLE_DEBUG_INFO = NO;
15791589
MTL_FAST_MATH = YES;
15801590
PRODUCT_BUNDLE_IDENTIFIER = com.swiftuiextensions.grid.examples.macos;
1581-
PRODUCT_NAME = "$(TARGET_NAME)";
1591+
PRODUCT_NAME = GridExamples;
15821592
SDKROOT = macosx;
15831593
SWIFT_COMPILATION_MODE = wholemodule;
15841594
SWIFT_OPTIMIZATION_LEVEL = "-O";

Examples/GridExamples/Item.swift

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import SwiftUI
2+
3+
struct Item: Identifiable {
4+
let number: Int
5+
let id: UUID = UUID()
6+
let color: Color = .random
7+
}

0 commit comments

Comments
 (0)