Skip to content

Commit 02f4d5b

Browse files
committed
Added Sidebar implementation
1 parent 4230b5d commit 02f4d5b

File tree

5 files changed

+208
-21
lines changed

5 files changed

+208
-21
lines changed

Examples/GKMatchMaker/GKMatchMaker.xcodeproj/project.pbxproj

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
150315F72617E3B100EC5D2E /* SidebarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 150315F62617E3B100EC5D2E /* SidebarView.swift */; };
11+
150315FC2617E7C900EC5D2E /* SidebarMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 150315FB2617E7C900EC5D2E /* SidebarMenu.swift */; };
12+
150316002617E88100EC5D2E /* SidebarRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 150315FF2617E88100EC5D2E /* SidebarRow.swift */; };
1013
1507A0BD25E410CA006DDBFC /* GKMatchMakerApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1507A0BC25E410CA006DDBFC /* GKMatchMakerApp.swift */; };
1114
1507A0BE25E410CA006DDBFC /* GKMatchMakerApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1507A0BC25E410CA006DDBFC /* GKMatchMakerApp.swift */; };
1215
1507A0C625E419E5006DDBFC /* AuthenticationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1507A0C525E419E5006DDBFC /* AuthenticationView.swift */; };
@@ -34,6 +37,10 @@
3437
/* End PBXBuildFile section */
3538

3639
/* Begin PBXFileReference section */
40+
150315F32617DB1E00EC5D2E /* Config.xcconfig-example */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Config.xcconfig-example"; sourceTree = "<group>"; };
41+
150315F62617E3B100EC5D2E /* SidebarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarView.swift; sourceTree = "<group>"; };
42+
150315FB2617E7C900EC5D2E /* SidebarMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarMenu.swift; sourceTree = "<group>"; };
43+
150315FF2617E88100EC5D2E /* SidebarRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarRow.swift; sourceTree = "<group>"; };
3744
1507A0BC25E410CA006DDBFC /* GKMatchMakerApp.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GKMatchMakerApp.swift; sourceTree = "<group>"; };
3845
1507A0C525E419E5006DDBFC /* AuthenticationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthenticationView.swift; sourceTree = "<group>"; };
3946
151CAA8D25E39837002A7FDC /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@@ -78,9 +85,20 @@
7885
/* End PBXFrameworksBuildPhase section */
7986

8087
/* Begin PBXGroup section */
88+
150315FA2617E7B200EC5D2E /* Sidebar */ = {
89+
isa = PBXGroup;
90+
children = (
91+
150315F62617E3B100EC5D2E /* SidebarView.swift */,
92+
150315FB2617E7C900EC5D2E /* SidebarMenu.swift */,
93+
150315FF2617E88100EC5D2E /* SidebarRow.swift */,
94+
);
95+
path = Sidebar;
96+
sourceTree = "<group>";
97+
};
8198
151CAA8525E39835002A7FDC = {
8299
isa = PBXGroup;
83100
children = (
101+
150315F32617DB1E00EC5D2E /* Config.xcconfig-example */,
84102
151CAAD025E39928002A7FDC /* Config.xcconfig */,
85103
151CAAD825E399DF002A7FDC /* GameKitUI.swift */,
86104
151CAA8A25E39835002A7FDC /* Shared */,
@@ -203,6 +221,7 @@
203221
15D90EAC2610B77E0010E6C9 /* Views */ = {
204222
isa = PBXGroup;
205223
children = (
224+
150315FA2617E7B200EC5D2E /* Sidebar */,
206225
15D90EAD2610B77E0010E6C9 /* ContentView.swift */,
207226
);
208227
path = Views;
@@ -276,7 +295,7 @@
276295
};
277296
};
278297
};
279-
buildConfigurationList = 151CAA8925E39835002A7FDC /* Build configuration list for PBXProject "GKMatchMaker" */;
298+
buildConfigurationList = 151CAA8925E39835002A7FDC /* Build configuration list for PBXProject "GKMatchmaker" */;
280299
compatibilityVersion = "Xcode 9.3";
281300
developmentRegion = en;
282301
hasScannedForEncodings = 0;
@@ -336,12 +355,15 @@
336355
buildActionMask = 2147483647;
337356
files = (
338357
15F85DE7260272D20009A734 /* GKMatchMakerAppModel.swift in Sources */,
358+
150316002617E88100EC5D2E /* SidebarRow.swift in Sources */,
339359
1507A0C725E419E5006DDBFC /* AuthenticationView.swift in Sources */,
340360
151F91FA25E4EC070015DD88 /* AuthenticationViewModel.swift in Sources */,
341361
151D89602602660B00979718 /* MatchView.swift in Sources */,
342362
152736882607D07C0068853D /* MatchMakingView.swift in Sources */,
343363
15D90EAE2610B7850010E6C9 /* ContentView.swift in Sources */,
344364
15D90EB52610BBC60010E6C9 /* PrimaryButtonStyle.swift in Sources */,
365+
150315F72617E3B100EC5D2E /* SidebarView.swift in Sources */,
366+
150315FC2617E7C900EC5D2E /* SidebarMenu.swift in Sources */,
345367
1507A0BE25E410CA006DDBFC /* GKMatchMakerApp.swift in Sources */,
346368
15A6F7F225E39E0500FE5387 /* MatchMakingViewModel.swift in Sources */,
347369
);
@@ -567,7 +589,7 @@
567589
/* End XCBuildConfiguration section */
568590

569591
/* Begin XCConfigurationList section */
570-
151CAA8925E39835002A7FDC /* Build configuration list for PBXProject "GKMatchMaker" */ = {
592+
151CAA8925E39835002A7FDC /* Build configuration list for PBXProject "GKMatchmaker" */ = {
571593
isa = XCConfigurationList;
572594
buildConfigurations = (
573595
151CAAA425E39837002A7FDC /* Debug */,

Examples/GKMatchMaker/macOS/Views/ContentView.swift

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
/// SOFTWARE.
2323
///
24-
/// Created by Sascha Müllner on 24.11.20.
24+
/// Created by Sascha Müllner on 03.04.21.
2525

2626
import SwiftUI
2727
import GameKit
@@ -30,24 +30,8 @@ import GameKitUI
3030
struct ContentView: View {
3131

3232
var body: some View {
33-
NavigationView {
34-
ZStack {
35-
Color("BackgroundColor").edgesIgnoringSafeArea(.all)
36-
VStack(alignment: .center, spacing: 32) {
37-
NavigationLink(destination: AuthenticationView()) {
38-
Text("Authentication")
39-
}
40-
.buttonStyle(PrimaryButtonStyle())
41-
NavigationLink(destination: MatchMakingView()) {
42-
Text("Match Making")
43-
}
44-
.buttonStyle(PrimaryButtonStyle())
45-
}
46-
}
47-
AuthenticationView()
48-
}
49-
.navigationTitle(Text("GameKit"))
50-
.frame(minWidth: 800, maxWidth: .infinity, minHeight: 500, maxHeight: .infinity)
33+
SidebarView()
34+
.frame(minWidth: 800, maxWidth: .infinity, minHeight: 500, maxHeight: .infinity)
5135
}
5236
}
5337

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
///
2+
/// MIT License
3+
///
4+
/// Copyright (c) 2020 Sascha Müllner
5+
///
6+
/// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
/// of this software and associated documentation files (the "Software"), to deal
8+
/// in the Software without restriction, including without limitation the rights
9+
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
/// copies of the Software, and to permit persons to whom the Software is
11+
/// furnished to do so, subject to the following conditions:
12+
///
13+
/// The above copyright notice and this permission notice shall be included in all
14+
/// copies or substantial portions of the Software.
15+
///
16+
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
/// SOFTWARE.
23+
///
24+
/// Created by Sascha Müllner on 03.04.21.
25+
26+
import Foundation
27+
import SwiftUI
28+
29+
enum SidebarMenu: Int, CaseIterable, Identifiable {
30+
31+
var id: Int {
32+
return self.rawValue
33+
}
34+
35+
36+
case authentication, matchMaking
37+
38+
var title: String {
39+
switch self {
40+
case .authentication: return "Authentication"
41+
case .matchMaking: return "Match Making"
42+
}
43+
}
44+
45+
var image: String {
46+
switch self {
47+
case .authentication: return "lock.fill"
48+
case .matchMaking: return "personalhotspot"
49+
}
50+
}
51+
52+
@ViewBuilder
53+
var contentView: some View {
54+
switch self {
55+
case .authentication: AuthenticationView()
56+
case .matchMaking: MatchMakingView()
57+
}
58+
}
59+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
///
2+
/// MIT License
3+
///
4+
/// Copyright (c) 2020 Sascha Müllner
5+
///
6+
/// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
/// of this software and associated documentation files (the "Software"), to deal
8+
/// in the Software without restriction, including without limitation the rights
9+
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
/// copies of the Software, and to permit persons to whom the Software is
11+
/// furnished to do so, subject to the following conditions:
12+
///
13+
/// The above copyright notice and this permission notice shall be included in all
14+
/// copies or substantial portions of the Software.
15+
///
16+
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
/// SOFTWARE.
23+
///
24+
/// Created by Sascha Müllner on 03.04.21.
25+
26+
import SwiftUI
27+
28+
struct SidebarRow : View {
29+
let item: SidebarMenu
30+
@Binding var selectedMenu: SidebarMenu
31+
32+
var isSelected: Bool {
33+
selectedMenu == item
34+
}
35+
36+
var body: some View {
37+
HStack {
38+
Group {
39+
Image(systemName: item.image)
40+
.imageScale(.large)
41+
.foregroundColor(isSelected ? .secondary : .primary)
42+
}
43+
.frame(width: 40)
44+
Text(item.title)
45+
.font(.headline)
46+
.foregroundColor(isSelected ? .secondary : .primary)
47+
}
48+
.padding()
49+
.onTapGesture {
50+
self.selectedMenu = self.item
51+
}
52+
}
53+
}
54+
55+
#if DEBUG
56+
struct SidebarRow_Previews : PreviewProvider {
57+
static var previews: some View {
58+
SidebarRow(item: .matchMaking, selectedMenu: .constant(.matchMaking))
59+
}
60+
}
61+
#endif
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
///
2+
/// MIT License
3+
///
4+
/// Copyright (c) 2020 Sascha Müllner
5+
///
6+
/// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
/// of this software and associated documentation files (the "Software"), to deal
8+
/// in the Software without restriction, including without limitation the rights
9+
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
/// copies of the Software, and to permit persons to whom the Software is
11+
/// furnished to do so, subject to the following conditions:
12+
///
13+
/// The above copyright notice and this permission notice shall be included in all
14+
/// copies or substantial portions of the Software.
15+
///
16+
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
/// SOFTWARE.
23+
///
24+
/// Created by Sascha Müllner on 03.04.21.
25+
26+
import SwiftUI
27+
28+
struct SidebarView: View {
29+
@State var selectedMenu: SidebarMenu = .authentication
30+
31+
@ViewBuilder
32+
var body: some View {
33+
HStack(spacing: 0) {
34+
ScrollView(showsIndicators: false) {
35+
VStack(alignment: .leading) {
36+
ForEach(SidebarMenu.allCases) { menu in
37+
ZStack(alignment: .leading) {
38+
SidebarRow(item: menu, selectedMenu: self.$selectedMenu)
39+
.frame(height: 50)
40+
if menu == self.selectedMenu {
41+
Rectangle()
42+
.foregroundColor(Color.secondary.opacity(0.1))
43+
.frame(height: 50)
44+
}
45+
}
46+
}
47+
}
48+
.padding(.top, 32)
49+
.frame(width: 300)
50+
}
51+
.background(Color.primary.opacity(0.1))
52+
selectedMenu.contentView
53+
}
54+
}
55+
}
56+
57+
struct SidebarView_Previews: PreviewProvider {
58+
static var previews: some View {
59+
SidebarView()
60+
}
61+
}

0 commit comments

Comments
 (0)