-
Notifications
You must be signed in to change notification settings - Fork 3
App Themes #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
oscarvgg
wants to merge
8
commits into
main
Choose a base branch
from
feature/themes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
App Themes #9
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
05b5424
Implement themes
oscarvgg 98508a2
Implement theme repo
oscarvgg 74467a0
Implement inject state property wrapper
oscarvgg ea8f39c
Implement theme mediator
oscarvgg 88a1142
Theme as environment value
oscarvgg a2ce03e
Implement theme modifier
oscarvgg 4fce15b
Implement inject theme modifier
oscarvgg 667f65c
Use logic on mediator instead of view model
oscarvgg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Oscar Gonzalez on 09/03/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public enum AppTheme: Equatable { | ||
case free | ||
case pro | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Oscar Gonzalez on 09/03/23. | ||
// | ||
|
||
import Foundation | ||
import DomainModels | ||
import Combine | ||
import Repositories | ||
|
||
public class AppThemeLogic { | ||
|
||
@Published public private(set) var currentTheme: AppTheme | ||
|
||
private let appThemeRepository: AppThemeRepository | ||
|
||
public init(appThemeRepository: AppThemeRepository) { | ||
self.appThemeRepository = appThemeRepository | ||
|
||
currentTheme = appThemeRepository.currentTheme | ||
appThemeRepository.$currentTheme.dropFirst().assign(to: &$currentTheme) | ||
} | ||
|
||
public func changeAppTheme(to theme: AppTheme) { | ||
return appThemeRepository.setTheme(theme) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
Packages/Repositories/Sources/Repositories/AppThemeRepository.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Oscar Gonzalez on 09/03/23. | ||
// | ||
|
||
import Foundation | ||
import DomainModels | ||
|
||
public class AppThemeRepository { | ||
@Published public private(set) var currentTheme = AppTheme.free | ||
|
||
public init() {} | ||
|
||
public func setTheme(_ appTheme: AppTheme) { | ||
currentTheme = appTheme | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
Packages/UIComponents/Sources/UIComponents/Stylesheet/ColorPalette.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// SwiftUIView.swift | ||
// | ||
// | ||
// Created by Oscar Gonzalez on 08/03/23. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ColorPalette { | ||
|
||
struct malachite { | ||
static let brightness500 = Color(hex: 0x06D16F) | ||
static let brightness700 = Color(hex: 0x00A756) | ||
} | ||
|
||
struct bearHoney { | ||
static let brightness500 = Color(hex: 0xE9A142) | ||
static let brightness700 = Color(hex: 0xDA7C00) | ||
} | ||
|
||
struct orange { | ||
static let brightness500 = Color(hex: 0xEC7C3C) | ||
static let brightness700 = Color(hex: 0xBB4C0C) | ||
} | ||
|
||
static let freeAccent = Color(hex: 0x007AFF) | ||
static let proAccent = Color(hex: 0xFA0002) | ||
static let latexPurple = Color(hex: 0x7708E7) | ||
static let darkGray = Color(hex: 0x1E1E1E) | ||
static let lightGray = Color(hex: 0xD2D2D2) | ||
static let midgray = Color(hex: 0x4D4D4D) | ||
static let white = Color.white | ||
static let black = Color.black | ||
static let green = Color(hex: 0x00FF00) | ||
} |
24 changes: 24 additions & 0 deletions
24
Packages/UIComponents/Sources/UIComponents/Stylesheet/InjectTheme.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Oscar Gonzalez on 09/03/23. | ||
// | ||
|
||
import Foundation | ||
import DomainModels | ||
import ViewModels | ||
import SwiftUI | ||
import Utils | ||
|
||
@propertyWrapper | ||
public struct InjectTheme: DynamicProperty { | ||
|
||
@InjectStateObject private var themeViewModel: AppThemeViewModel | ||
|
||
public init() {} | ||
|
||
public var wrappedValue: Theme { | ||
get { return ThemeFactory.build(theme: themeViewModel.currentTheme) } | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Packages/UIComponents/Sources/UIComponents/Stylesheet/Themes/FreeTheme.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Oscar Gonzalez on 08/03/23. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
public struct FreeTheme: Theme { | ||
public struct Color: ThemeColor { | ||
public let accent = ColorPalette.freeAccent | ||
public let content = ColorPalette.black | ||
public let scheme: ColorScheme = .light | ||
} | ||
|
||
public let color: ThemeColor = FreeTheme.Color() | ||
|
||
public init() {} | ||
} |
21 changes: 21 additions & 0 deletions
21
Packages/UIComponents/Sources/UIComponents/Stylesheet/Themes/ProTheme.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Oscar Gonzalez on 08/03/23. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
public struct ProTheme: Theme { | ||
public struct Color: ThemeColor { | ||
public let accent = ColorPalette.proAccent | ||
public let content = ColorPalette.white | ||
public let scheme: ColorScheme = .dark | ||
} | ||
|
||
public let color: ThemeColor = ProTheme.Color() | ||
|
||
public init() {} | ||
} |
31 changes: 31 additions & 0 deletions
31
Packages/UIComponents/Sources/UIComponents/Stylesheet/Themes/Theme.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Oscar Gonzalez on 08/03/23. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
import DomainModels | ||
|
||
public protocol Theme { | ||
var color: ThemeColor { get } | ||
} | ||
|
||
public protocol ThemeColor { | ||
var accent: Color { get } | ||
var content: Color { get } | ||
var scheme: ColorScheme { get } | ||
} | ||
|
||
public struct ThemeFactory { | ||
public static func build(theme: AppTheme) -> Theme { | ||
switch theme { | ||
case .free: | ||
return FreeTheme() | ||
case .pro: | ||
return ProTheme() | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Packages/UIComponents/Sources/UIComponents/Utils/Color+Hex.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Oscar Gonzalez on 08/03/23. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
extension Color { | ||
init(hex: UInt, alpha: Double = 1) { | ||
self.init( | ||
.sRGB, | ||
red: Double((hex >> 16) & 0xff) / 255, | ||
green: Double((hex >> 08) & 0xff) / 255, | ||
blue: Double((hex >> 00) & 0xff) / 255, | ||
opacity: alpha | ||
) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Packages/UIComponents/Sources/UIComponents/Utils/Environment+Theme.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Oscar Gonzalez on 09/03/23. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
private struct ThemeKey: EnvironmentKey { | ||
static var defaultValue: Theme = FreeTheme() | ||
} | ||
|
||
public extension EnvironmentValues { | ||
var theme: Theme { | ||
get { self[ThemeKey.self] } | ||
set { self[ThemeKey.self] = newValue } | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
Packages/ViewModels/Sources/ViewModels/AppThemeViewModel.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Oscar Gonzalez on 09/03/23. | ||
// | ||
|
||
import Foundation | ||
import DomainModels | ||
import Combine | ||
import Logic | ||
|
||
public class AppThemeViewModel: ObservableObject { | ||
@Published public private(set) var currentTheme: AppTheme | ||
|
||
private var appThemeLogic: AppThemeLogic | ||
|
||
init(appThemeLogic: AppThemeLogic) { | ||
self.appThemeLogic = appThemeLogic | ||
|
||
currentTheme = appThemeLogic.currentTheme | ||
appThemeLogic.$currentTheme.dropFirst().assign(to: &$currentTheme) | ||
} | ||
|
||
public func toggleTheme() { | ||
switch currentTheme { | ||
case .free: | ||
appThemeLogic.changeAppTheme(to: .pro) | ||
case .pro: | ||
appThemeLogic.changeAppTheme(to: .free) | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.