Skip to content

Commit

Permalink
Working on implementing DSKit for MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Borinschi committed Nov 19, 2024
1 parent a02a8d5 commit 7850cb4
Show file tree
Hide file tree
Showing 86 changed files with 1,153 additions and 663 deletions.
6 changes: 2 additions & 4 deletions DSKit/Sources/DSKit/Appearances/BlueAppearance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2021 Borinschi Ivan. All rights reserved.
//

import UIKit

public class BlueAppearance: DSAppearance {

public var title: String
Expand All @@ -24,7 +22,7 @@ public class BlueAppearance: DSAppearance {

/// Init system appearance with brand color, or primary color of your app
/// - Parameter primaryBrandColor: UIColor
public init(brandColor: UIColor? = nil, title: String = "Blue") {
public init(brandColor: DSUIColor? = nil, title: String = "Blue") {

self.title = title

Expand Down Expand Up @@ -79,7 +77,7 @@ public class BlueAppearance: DSAppearance {

// MARK: - Tabbar

tabBar = DSTabbarAppearance(
tabBar = DSTabBarAppearance(
barTint: primaryView.background,
itemTint: primaryView.button.accentColor,
unselectedItemTint: secondaryText.subheadline,
Expand Down
16 changes: 7 additions & 9 deletions DSKit/Sources/DSKit/Appearances/DSKitAppearance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2021 Borinschi Ivan. All rights reserved.
//

import UIKit

public struct LightBlueAppearance: DSAppearance {

public var title: String
Expand All @@ -25,7 +23,7 @@ public struct LightBlueAppearance: DSAppearance {

/// Init DSKit appearance with specific brand color
/// - Parameter brandColor: UIColor
public init(brandColor: UIColor? = nil) {
public init(brandColor: DSUIColor? = nil) {

self.title = "Light Blue"

Expand Down Expand Up @@ -60,10 +58,10 @@ public struct LightBlueAppearance: DSAppearance {
)

// Background
let background: UIColor = .dynamic(light: 0xfefffe, dark: 0x15202b)
let background: DSUIColor = .dynamic(light: 0xfefffe, dark: 0x15202b)

// Separator
let separator: UIColor = .dynamic(light: 0xd0dbe3, dark: 0x38444d)
let separator: DSUIColor = .dynamic(light: 0xd0dbe3, dark: 0x38444d)

// Corner radius
let cornerRadius: CGFloat = 10
Expand Down Expand Up @@ -109,10 +107,10 @@ public struct LightBlueAppearance: DSAppearance {
)

// Background
let sBackground: UIColor = .dynamic(light: 0xf3f4f2, dark: 0x101a24)
let sBackground: DSUIColor = .dynamic(light: 0xf3f4f2, dark: 0x101a24)

// Separator
let sSeparator: UIColor = .dynamic(light: 0xd0dbe3, dark: 0x15202b)
let sSeparator: DSUIColor = .dynamic(light: 0xd0dbe3, dark: 0x15202b)

// Corner radius
let sCornerRadius: CGFloat = 10
Expand All @@ -129,7 +127,7 @@ public struct LightBlueAppearance: DSAppearance {

// MARK: - Tabbar

tabBar = DSTabbarAppearance(
tabBar = DSTabBarAppearance(
barTint: primaryView.background,
itemTint: primaryView.button.accentColor,
unselectedItemTint: text.subheadline,
Expand Down Expand Up @@ -158,7 +156,7 @@ public struct LightBlueAppearance: DSAppearance {

price = DSPriceAppearance(
regularAmount: text.subheadline,
badgeBackground: UIColor(0xFF656B)
badgeBackground: DSUIColor(0xFF656B)
)
}

Expand Down
8 changes: 3 additions & 5 deletions DSKit/Sources/DSKit/Appearances/DarkAppearance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2021 Borinschi Ivan. All rights reserved.
//

import UIKit

public class DarkAppearance: DSAppearance {

public var title: String
Expand All @@ -24,7 +22,7 @@ public class DarkAppearance: DSAppearance {

/// Init system appearance with brand color, or primary color of your app
/// - Parameter primaryBrandColor: UIColor
public init(brandColor: UIColor? = nil, title: String = "Dark") {
public init(brandColor: DSUIColor? = nil, title: String = "Dark") {

self.title = title

Expand Down Expand Up @@ -84,11 +82,11 @@ public class DarkAppearance: DSAppearance {

// MARK: - Tabbar

tabBar = DSTabbarAppearance(
tabBar = DSTabBarAppearance(
barTint: primaryView.background,
itemTint: primaryView.button.accentColor,
unselectedItemTint: secondaryText.subheadline,
badge: UIColor.red,
badge: DSUIColor.red,
translucent: true
)

Expand Down
16 changes: 6 additions & 10 deletions DSKit/Sources/DSKit/Appearances/PeachAppearance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
// Copyright © 2021 Borinschi Ivan. All rights reserved.
//

import UIKit

import UIKit

public class PeachAppearance: DSAppearance {

public var title: String
Expand All @@ -24,7 +20,7 @@ public class PeachAppearance: DSAppearance {
public var actionElementHeight: CGFloat = 48
public var screenMargins: CGFloat = 16

public init(brandColor: UIColor? = nil, title: String = "Peach") {
public init(brandColor: DSUIColor? = nil, title: String = "Peach") {

self.title = title

Expand Down Expand Up @@ -83,11 +79,11 @@ public class PeachAppearance: DSAppearance {

// MARK: - Tabbar

tabBar = DSTabbarAppearance(
barTint: .dynamic(light: 0xFFFFFF, dark: 0x1A1A1A),
itemTint: .dynamic(light: 0xE84F3D, dark: 0xE84F3D),
unselectedItemTint: .dynamic(light: 0x717171, dark: 0x999999),
badge: .dynamic(light: 0xE84F3D, dark: 0xE84F3D),
tabBar = DSTabBarAppearance(
barTint: DSUIColor.dynamic(light: 0xFFFFFF, dark: 0x1A1A1A),
itemTint: DSUIColor.dynamic(light: 0xE84F3D, dark: 0xE84F3D),
unselectedItemTint: DSUIColor.dynamic(light: 0x717171, dark: 0x999999),
badge: DSUIColor.dynamic(light: 0xE84F3D, dark: 0xE84F3D),
translucent: true
)

Expand Down
6 changes: 2 additions & 4 deletions DSKit/Sources/DSKit/Appearances/RetroAppearance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2021 Borinschi Ivan. All rights reserved.
//

import UIKit

public final class RetroAppearance: DSAppearance {

public var title: String
Expand All @@ -27,7 +25,7 @@ public final class RetroAppearance: DSAppearance {

/// Init system appearance with brand color, or primary color of your app
/// - Parameter primaryBrandColor: UIColor
public init(brandColor: UIColor? = nil, title: String = "Retro") {
public init(brandColor: DSUIColor? = nil, title: String = "Retro") {

self.title = title

Expand Down Expand Up @@ -101,7 +99,7 @@ public final class RetroAppearance: DSAppearance {

// MARK: - Tabbar

tabBar = DSTabbarAppearance(
tabBar = DSTabBarAppearance(
barTint: primaryView.background,
itemTint: primaryView.button.accentColor,
unselectedItemTint: text.subheadline,
Expand Down
15 changes: 12 additions & 3 deletions DSKit/Sources/DSKit/Designable/DSAppearance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
//

import SwiftUI
import UIKit

// MARK: - Environment Key for DSAppearance

struct AppearanceEnvironment: EnvironmentKey {
static let defaultValue: DSAppearance = LightBlueAppearance()
Expand All @@ -20,6 +21,8 @@ public extension EnvironmentValues {
}
}

// MARK: - DSAppearance Protocol

public protocol DSAppearance {
var title: String { get set }
var primaryView: DSViewAppearanceProtocol { get set }
Expand All @@ -42,7 +45,10 @@ extension DSAppearance {
}

public extension DSAppearance {
/// Override the system appearance settings (iOS only)
func overrideTheSystemAppearance() {
#if canImport(UIKit)
// Configure Navigation Bar Appearance
let navigationBarAppearance = UINavigationBarAppearance()
navigationBarAppearance.configureWithOpaqueBackground()
navigationBarAppearance.backgroundColor = self.navigationBar.bar
Expand Down Expand Up @@ -77,13 +83,16 @@ public extension DSAppearance {

UITabBar.appearance().standardAppearance = tabBarAppearance
UITabBar.appearance().scrollEdgeAppearance = tabBarAppearance
#endif
}
}

// MARK: - SwiftUI View Extension

public extension View {
/// Apply the `DSAppearance` to the SwiftUI view
func dsAppearance(_ appearance: DSAppearance) -> some View {
appearance.overrideTheSystemAppearance()
return self
.environment(\.appearance, appearance)
return self.environment(\.appearance, appearance)
}
}
19 changes: 10 additions & 9 deletions DSKit/Sources/DSKit/Designable/DSButtonAppearance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
// Copyright © 2021 Borinschi Ivan. All rights reserved.
//

import UIKit
import SwiftUI

public protocol DSButtonAppearanceProtocol {
var accentColor: UIColor { get set }
var supportColor: UIColor { get set }
var accentColor: DSUIColor { get set }
var supportColor: DSUIColor { get set }
}

public extension DSButtonAppearanceProtocol {
/// Returns a SwiftUI `Color` based on the given `DSButtonColorKey`
func color(key: DSButtonColorKey) -> Color {
switch key {
case .accentColor:
accentColor.color
return Color(accentColor)
case .supportColor:
supportColor.color
return Color(supportColor)
}
}
}
Expand All @@ -32,12 +32,13 @@ public enum DSButtonColorKey {

public struct DSButtonAppearance: DSButtonAppearanceProtocol {

public var accentColor: UIColor
public var supportColor: UIColor
public var accentColor: DSUIColor
public var supportColor: DSUIColor

/// Initialize `DSButtonAppearance` with colors
public init(
accentColor: UIColor,
supportColor: UIColor
accentColor: DSUIColor,
supportColor: DSUIColor
) {
self.accentColor = accentColor
self.supportColor = supportColor
Expand Down
1 change: 0 additions & 1 deletion DSKit/Sources/DSKit/Designable/DSColorKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Created by Ivan Borinschi on 26.12.2022.
//

import UIKit
import SwiftUI

public enum DSColorKey: Equatable, Hashable {
Expand Down
26 changes: 12 additions & 14 deletions DSKit/Sources/DSKit/Designable/DSDesignableTextFieldColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,29 @@
// Copyright © 2021 Borinschi Ivan. All rights reserved.
//

import UIKit

protocol DSTextFieldColorsProtocol {
var border: UIColor { get set }
var background: UIColor { get set }
var text: UIColor { get set }
var placeHolder: UIColor { get set }
var border: DSUIColor { get set }
var background: DSUIColor { get set }
var text: DSUIColor { get set }
var placeHolder: DSUIColor { get set }
}

public struct DSTextFieldColors: DSTextFieldColorsProtocol {

public init(
border: UIColor,
background: UIColor,
text: UIColor,
placeHolder: UIColor
border: DSUIColor,
background: DSUIColor,
text: DSUIColor,
placeHolder: DSUIColor
) {
self.border = border
self.background = background
self.text = text
self.placeHolder = placeHolder
}

public var border: UIColor
public var background: UIColor
public var text: UIColor
public var placeHolder: UIColor
public var border: DSUIColor
public var background: DSUIColor
public var text: DSUIColor
public var placeHolder: DSUIColor
}
55 changes: 19 additions & 36 deletions DSKit/Sources/DSKit/Designable/DSDynamicColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,31 @@
// Created by Borinschi Ivan on 16.12.2020.
//

import UIKit

public class DSDynamicColor {

/// Generate light and dark color for dynamic interfaces
/// - Parameters:
/// - light: UIColor for light interface
/// - dark: UIColor for dark interface
/// - Returns: UIColor
public static func color(light: UIColor, dark: UIColor) -> UIColor {
return UIColor { (traitCollection: UITraitCollection) -> UIColor in
if traitCollection.userInterfaceStyle == .dark {
return dark
} else {
return light
}
}
}

/// Generate light and dark color for dynamic interfaces
/// - Parameters:
/// - light: UIColor fo light interface
/// - dark: UIColor for dark interface
/// - Returns: UIColor
public static func color(light: Int, dark: Int) -> UIColor {
return color(light: UIColor(light), dark: UIColor(dark))
}
}

extension UIColor {
static func dynamic(light: UIColor, dark: UIColor) -> UIColor {
return UIColor { traitCollection -> UIColor in
switch traitCollection.userInterfaceStyle {
case .dark:
return dark
default:
return light
}
/// - light: DSUIColor for light interface
/// - dark: DSUIColor for dark interface
/// - Returns: DSUIColor
public static func color(light: DSUIColor, dark: DSUIColor) -> DSUIColor {
#if canImport(UIKit)
return DSUIColor { traitCollection in
traitCollection.userInterfaceStyle == .dark ? dark : light
}
#elseif canImport(AppKit)
return DSUIColor(name: nil, dynamicProvider: { appearance in
appearance.bestMatch(from: [.darkAqua, .aqua]) == .darkAqua ? dark : light
})
#endif
}

static func dynamic(light: Int, dark: Int) -> UIColor {
dynamic(light: UIColor(light), dark: UIColor(dark))
/// Generate light and dark color for dynamic interfaces using hex values
/// - Parameters:
/// - light: Hex color for light interface
/// - dark: Hex color for dark interface
/// - Returns: DSUIColor
public static func color(light: Int, dark: Int) -> DSUIColor {
return color(light: DSUIColor(light), dark: DSUIColor(dark))
}
}
Loading

0 comments on commit 7850cb4

Please sign in to comment.