Skip to content

Commit

Permalink
Added Color Styling.
Browse files Browse the repository at this point in the history
- Added colours to Asset Catalog for light and dark mode.
- Added `Color` extension for referencing colors in code.
- Added `Style` view modifier to add to the root of each for to set background and foreground colors.
  • Loading branch information
richy486 committed Mar 26, 2024
1 parent da5c1e8 commit f0fcdff
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 4 deletions.
16 changes: 16 additions & 0 deletions MoreChess.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
B9FAC9472BB06C0C002A20F7 /* ClientView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9FAC9462BB06C0C002A20F7 /* ClientView.swift */; };
B9FAC9492BB06C91002A20F7 /* SimpleNavigationBackButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9FAC9482BB06C91002A20F7 /* SimpleNavigationBackButton.swift */; };
B9FAC94B2BB06FB2002A20F7 /* WaitingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9FAC94A2BB06FB2002A20F7 /* WaitingView.swift */; };
B9FAC94F2BB2E833002A20F7 /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9FAC94E2BB2E833002A20F7 /* Color.swift */; };
B9FAC9512BB2F46D002A20F7 /* Style.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9FAC9502BB2F46D002A20F7 /* Style.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -118,6 +120,8 @@
B9FAC9462BB06C0C002A20F7 /* ClientView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientView.swift; sourceTree = "<group>"; };
B9FAC9482BB06C91002A20F7 /* SimpleNavigationBackButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleNavigationBackButton.swift; sourceTree = "<group>"; };
B9FAC94A2BB06FB2002A20F7 /* WaitingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WaitingView.swift; sourceTree = "<group>"; };
B9FAC94E2BB2E833002A20F7 /* Color.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = "<group>"; };
B9FAC9502BB2F46D002A20F7 /* Style.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Style.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -171,6 +175,7 @@
B9ABF7A42BAEF04C00907C61 /* DataAccess */,
B9ABF7A52BAEF0C500907C61 /* Models */,
B9FAC91C2BAF0CDE002A20F7 /* Utils */,
B9FAC94D2BB2E821002A20F7 /* Resources */,
B95CE50F2AD4CB5B00978591 /* MoreChessApp.swift */,
B95CE5112AD4CB5E00978591 /* Assets.xcassets */,
B9FAC9182BAF070C002A20F7 /* Launch Screen.storyboard */,
Expand Down Expand Up @@ -338,6 +343,15 @@
path = Game;
sourceTree = "<group>";
};
B9FAC94D2BB2E821002A20F7 /* Resources */ = {
isa = PBXGroup;
children = (
B9FAC94E2BB2E833002A20F7 /* Color.swift */,
B9FAC9502BB2F46D002A20F7 /* Style.swift */,
);
path = Resources;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -498,6 +512,7 @@
buildActionMask = 2147483647;
files = (
B9FAC92A2BAF29DF002A20F7 /* Players.swift in Sources */,
B9FAC94F2BB2E833002A20F7 /* Color.swift in Sources */,
B9FAC93F2BB059CD002A20F7 /* GameService.swift in Sources */,
B9ABF7AB2BAEF1EB00907C61 /* BoardView.swift in Sources */,
B9FAC9172BAEFFAC002A20F7 /* LayoutState.swift in Sources */,
Expand Down Expand Up @@ -527,6 +542,7 @@
B94B61F52B68F8D700C998F3 /* PieceGenerator.swift in Sources */,
B9FAC9432BB06315002A20F7 /* LobbyRepository.swift in Sources */,
B9FAC91B2BAF0CA7002A20F7 /* Pieces.swift in Sources */,
B9FAC9512BB2F46D002A20F7 /* Style.swift in Sources */,
B9FAC91F2BAF0D6A002A20F7 /* Player.swift in Sources */,
B9FAC9152BAEF6C3002A20F7 /* PositioningInteractor.swift in Sources */,
);
Expand Down
45 changes: 45 additions & 0 deletions Shared/Assets.xcassets/AccentColor.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,51 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "1.000",
"green" : "0.253",
"red" : "1.000"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "light"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "1.000",
"green" : "0.253",
"red" : "1.000"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "1.000",
"green" : "0.993",
"red" : "0.451"
}
},
"idiom" : "universal"
}
],
Expand Down
38 changes: 38 additions & 0 deletions Shared/Assets.xcassets/Background.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.921",
"green" : "0.921",
"red" : "0.921"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.261",
"green" : "0.261",
"red" : "0.261"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
38 changes: 38 additions & 0 deletions Shared/Assets.xcassets/Foreground.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.261",
"green" : "0.261",
"red" : "0.261"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "1.000",
"green" : "1.000",
"red" : "1.000"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
2 changes: 0 additions & 2 deletions Shared/Presentation/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ struct ContentView: View {
Group {
if appState.lobbyState.inGame == false {
LobbyView(lobbyInteractor: LobbyInteractor(appState: appState))

} else {
GameView()
}

}
.environment(appState)
} // body
Expand Down
3 changes: 2 additions & 1 deletion Shared/Presentation/Elements/SolidButtonStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct SolidButtonStyle: ButtonStyle {
configuration.label
.padding()
.background(.tint)
.foregroundStyle(.background)
.foregroundStyle(Color.background)
.font(.headline)
.clipShape(Capsule())
.scaleEffect(configuration.isPressed ? 1.2 : 1)
Expand All @@ -24,4 +24,5 @@ struct SolidButtonStyle: ButtonStyle {
Button("Press Me") {
}
.buttonStyle(SolidButtonStyle())
.style()
}
1 change: 1 addition & 0 deletions Shared/Presentation/Game/GameView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct GameView: View {
Text("Row count: \(appState.gameState.rowCount), Column count: \(appState.gameState.columnCount)")

} // VStack
.style()
} // body

@ViewBuilder func playConditionView() -> some View {
Expand Down
1 change: 1 addition & 0 deletions Shared/Presentation/Lobby/ClientView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct ClientView: View {
.navigationTitle("Join")
.navigationBarTitleDisplayMode(.inline)
.simpleNavigationBackButton(dismiss: dismiss)
.style()
.onAppear(perform: lobbyInteractor.fetchAvailableGames)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Shared/Presentation/Lobby/HostingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ struct HostingView: View {
VStack {
Text("Hosting")
Text("share this code to other player: \(gameService.gameId)-\(gameService.clientId)")

Spacer().frame(height: 20)

HStack {
Expand All @@ -28,6 +27,7 @@ struct HostingView: View {
.navigationTitle("Host")
.navigationBarTitleDisplayMode(.inline)
.simpleNavigationBackButton(dismiss: dismiss)
.style()
.onAppear {
lobbyInteractor.checkForOpponentClient(gameService: gameService)
}
Expand Down
3 changes: 3 additions & 0 deletions Shared/Presentation/Lobby/LobbyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct LobbyView: View {

var body: some View {
NavigationStack(path: pathBinding()) {

home()
.navigationDestination(for: LobbyState.LobbyPages.self) { destination in
switch destination {
Expand All @@ -31,6 +32,7 @@ struct LobbyView: View {
private func home() -> some View {
VStack {
Text("Host or join a new game")

HStack {
Button("Host") {
lobbyInteractor.select(serviceType: .host)
Expand All @@ -43,6 +45,7 @@ struct LobbyView: View {
.buttonStyle(SolidButtonStyle())
} // HStack
}
.style()
.navigationTitle("More Chess 🐴")
.navigationBarTitleDisplayMode(.inline)
}
Expand Down
13 changes: 13 additions & 0 deletions Shared/Resources/Color.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Color.swift
// MoreChess (iOS)
//
// Created by Richard Adem on 3/26/24.
//

import SwiftUI

extension Color {
static let foreground = Color("Foreground")
static let background = Color("Background")
}
24 changes: 24 additions & 0 deletions Shared/Resources/Style.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Style.swift
// MoreChess (iOS)
//
// Created by Richard Adem on 3/26/24.
//

import SwiftUI

// Add this to the root of your view.
struct StyleModifier: ViewModifier {
func body(content: Content) -> some View {
content
.frame(maxWidth: .infinity, maxHeight: .infinity) // TODO: add option to disable this line.
.background(Color.background)
.foregroundStyle(Color.foreground)
}
}

extension View {
func style() -> some View {
modifier(StyleModifier())
}
}

0 comments on commit f0fcdff

Please sign in to comment.