Skip to content

Commit

Permalink
scribe-org#216: added all colors to Assets file, added enum, refactor…
Browse files Browse the repository at this point in the history
…ed ColorVariables.swift
  • Loading branch information
misteu committed Oct 11, 2022
1 parent 86c7f5b commit 3f18d40
Show file tree
Hide file tree
Showing 33 changed files with 880 additions and 223 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Emojis for the following are chosen based on [gitmoji](https://gitmoji.dev/).

- Boolean states for commands were converted into a single enum to make keyboard states much simpler to work with.
- Code was refactored to work with the new enum style of command state management.
- Refactored `ColorVariables.swift` to colors asset file.

# Scribe-iOS 1.4.0

Expand Down
134 changes: 15 additions & 119 deletions Keyboards/KeyboardsBase/ColorVariables.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,128 +7,24 @@
import UIKit

// The Scribe key icon that changes based on light and dark mode as well as device.
var scribeKeyIcon = UIImage(named: "ScribeKeyPhoneBlack.png")
var scribeKeyIcon = UIImage(named: "scribeKeyIcon")

// Initialize all colors.
var keyColor = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)
var keyCharColor = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)
var specialKeyColor = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)
var keyPressedColor = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)
var keyColor = UIColor(.key)
var keyCharColor = UIColor(.keyChar)
var specialKeyColor = UIColor(.keySpecial)
var keyPressedColor = UIColor(.keyPressed)

var commandKeyColor = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)
var commandBarColor = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)
var commandBarBorderColor = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0).cgColor
var commandKeyColor = UIColor(.commandKey)
var commandBarColor = UIColor(.commandBar)
var commandBarBorderColor = UIColor(.commandBarBorder).cgColor

var keyboardBgColor = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)
var keyShadowColor = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0).cgColor
var keyboardBgColor = UIColor(.keyboardBackground)
var keyShadowColor = UIColor(.keyShadow).cgColor

// annotate colors.
var annotateRed = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)
var annotateBlue = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)
var annotatePurple = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)
var annotateGreen = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)
var annotateOrange = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)

/// Determines if the device is in dark mode and sets the color scheme.
func checkDarkModeSetColors() {
if UITraitCollection.current.userInterfaceStyle == .light {
if DeviceType.isPhone {
scribeKeyIcon = UIImage(named: "ScribeKeyPhoneBlack.png")
} else if DeviceType.isPad {
scribeKeyIcon = UIImage(named: "ScribeKeyPadBlack.png")
}

keyColor = UIColor.keyColorLight
keyCharColor = UIColor.keyCharColorLight
specialKeyColor = UIColor.specialKeyColorLight
keyPressedColor = UIColor.keyPressedColorLight

commandKeyColor = UIColor.commandKeyColorLight
commandBarColor = UIColor.commandBarColorLight
commandBarBorderColor = UIColor.commandBarBorderColorLight

keyboardBgColor = UIColor.keyboardBgColorLight
keyShadowColor = UIColor.keyShadowColorLight

annotateRed = UIColor.annotateRedLight
annotateBlue = UIColor.annotateBlueLight
annotatePurple = UIColor.annotatePurpleLight
annotateGreen = UIColor.annotateGreenLight
annotateOrange = UIColor.annotateOrangeLight
} else if UITraitCollection.current.userInterfaceStyle == .dark {
if DeviceType.isPhone {
scribeKeyIcon = UIImage(named: "ScribeKeyPhoneWhite.png")
} else if DeviceType.isPad {
scribeKeyIcon = UIImage(named: "ScribeKeyPadWhite.png")
}

keyColor = UIColor.keyColorDark
keyCharColor = UIColor.keyCharColorDark
specialKeyColor = UIColor.specialKeyColorDark
keyPressedColor = UIColor.keyPressedColorDark

commandKeyColor = UIColor.commandKeyColorDark
commandBarColor = UIColor.commandBarColorDark
commandBarBorderColor = UIColor.commandBarBorderColorDark

keyboardBgColor = UIColor.keyboardBgColorDark
keyShadowColor = UIColor.keyShadowColorDark

annotateRed = UIColor.annotateRedDark
annotateBlue = UIColor.annotateBlueDark
annotatePurple = UIColor.annotatePurpleDark
annotateGreen = UIColor.annotateGreenDark
annotateOrange = UIColor.annotateOrangeDark
}
}

/// Extends UIColor with branding colors as well as those for annotating nouns.
extension UIColor {
static let scribeGrey = UIColor(red: 100.0/255.0, green: 100.0/255.0, blue: 100.0/255.0, alpha: 0.9)

// Light theme.
static let scribeBlueLight = UIColor(red: 117.0/255.0, green: 206.0/255.0, blue: 250.0/255.0, alpha: 0.95)

static let keyColorLight = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)
static let keyCharColorLight = UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 0.9)
static let specialKeyColorLight = UIColor(red: 174.0/255.0, green: 179.0/255.0, blue: 190.0/255.0, alpha: 1.0)
static let keyPressedColorLight = UIColor(red: 228.0/255.0, green: 228.0/255.0, blue: 228.0/255.0, alpha: 1.0)

static let commandKeyColorLight = UIColor.scribeBlueLight
static let commandBarColorLight = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)
static let commandBarBorderColorLight = UIColor(
red: 203.0/255.0, green: 203.0/255.0, blue: 206.0/255.0, alpha: 1.0
).cgColor

static let keyboardBgColorLight = UIColor(red: 206.0/255.0, green: 210.0/255.0, blue: 217.0/255.0, alpha: 1.0)
static let keyShadowColorLight = UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 0.35).cgColor

static let annotateRedLight = UIColor(red: 160.0/255.0, green: 24.0/255.0, blue: 35.0/255.0, alpha: 0.9)
static let annotateBlueLight = UIColor(red: 51.0/255.0, green: 92.0/255.0, blue: 153.0/255.0, alpha: 0.9)
static let annotatePurpleLight = UIColor(red: 113.0/255.0, green: 5.0/255.0, blue: 138.0/255.0, alpha: 0.9)
static let annotateGreenLight = UIColor(red: 62.0/255.0, green: 122.0/255.0, blue: 71.0/255.0, alpha: 0.9)
static let annotateOrangeLight = UIColor(red: 248.0/255.0, green: 90.0/255.0, blue: 58.0/255.0, alpha: 0.9)

// Dark theme.
static let scribeBlueDark = UIColor(red: 76.0/255.0, green: 173.0/255.0, blue: 230.0/255.0, alpha: 0.9)

static let keyColorDark = UIColor(red: 67.0/255.0, green: 67.0/255.0, blue: 67.0/255.0, alpha: 1.0)
static let keyCharColorDark = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 0.9)
static let specialKeyColorDark = UIColor(red: 32.0/255.0, green: 32.0/255.0, blue: 32.0/255.0, alpha: 1.0)
static let keyPressedColorDark = UIColor(red: 46.0/255.0, green: 46.0/255.0, blue: 46.0/255.0, alpha: 1.0)

static let commandKeyColorDark = UIColor.scribeBlueDark
static let commandBarColorDark = UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 1.0)
static let commandBarBorderColorDark = UIColor(
red: 75.0/255.0, green: 75.0/255.0, blue: 75.0/255.0, alpha: 1.0
).cgColor

static let keyboardBgColorDark = UIColor(red: 30.0/255.0, green: 30.0/255.0, blue: 30.0/255.0, alpha: 1.0)
static let keyShadowColorDark = UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 0.95).cgColor

static let annotateRedDark = UIColor(red: 252.0/255.0, green: 95.0/255.0, blue: 108.0/255.0, alpha: 0.9)
static let annotateBlueDark = UIColor(red: 51.0/255.0, green: 158.0/255.0, blue: 235.0/255.0, alpha: 0.9)
static let annotatePurpleDark = UIColor(red: 173.0/255.0, green: 110.0/255.0, blue: 237.0/255.0, alpha: 0.9)
static let annotateGreenDark = UIColor(red: 133.0/255.0, green: 194.0/255.0, blue: 112.0/255.0, alpha: 0.9)
static let annotateOrangeDark = UIColor(red: 254.0/255.0, green: 160.0/255.0, blue: 93.0/255.0, alpha: 0.9)
}
var annotateRed = UIColor(.annotateRed)
var annotateBlue = UIColor(.annotateBlue)
var annotatePurple = UIColor(.annotatePurple)
var annotateGreen = UIColor(.annotateGreen)
var annotateOrange = UIColor(.annotateOrange)
35 changes: 35 additions & 0 deletions Keyboards/KeyboardsBase/Colors/ScribeColor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// ScribeColor.swift
// Scribe
//
// Created by Michael Steudter - @misteu on 04.10.22.
//

import UIKit

/// All the colors defined in `Assets.xcassets/Colors`
enum ScribeColor: String {
case annotateBlue
case annotateGreen
case annotateOrange
case annotatePurple
case annotateRed
case annotateTitle
case commandBar
case commandBarBorder
case commandBarInfoButton
case commandKey
case key
case keyChar
case keyPressed
case keyShadow
case keySpecial
case keyboardBackground
case scribeBlue
case scribeGray

/// `UIColor` object for the given
var color: UIColor {
.init(self)
}
}
36 changes: 36 additions & 0 deletions Keyboards/KeyboardsBase/Colors/UIColor+ScribeColors.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// UIColor+ScribeColors.swift
// Scribe
//
// Created by Michael Steudter - @misteu on 04.10.22.
//

import UIKit

extension UIColor {

// MARK: - Init from ScribeColor

/// Creates `UIColor` from passed `ScribeColor`
/// - Parameter color: The `UIColor`.
///
/// Defaults to `UIColor.red` if passed color was not found in assets.
convenience init(_ color: ScribeColor) {
if UIColor(named: color.rawValue) != nil {
self.init(named: color.rawValue)!
} else {
print("unable to find color named: \(color.rawValue)")
self.init(red: 1, green: 0, blue: 0, alpha: 1)
}
}

/// Convenience computed property for light mode variant of the color.
var light: UIColor {
resolvedColor(with: .init(userInterfaceStyle: .light))
}

/// Convenience computed property for dark mode variant of the color.
var dark: UIColor {
resolvedColor(with: .init(userInterfaceStyle: .light))
}
}
3 changes: 0 additions & 3 deletions Keyboards/KeyboardsBase/KeyboardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ class KeyboardViewController: UIInputViewController {
/// - Adding the keyboard selector target
override func viewDidLoad() {
super.viewDidLoad()

checkDarkModeSetColors()
// If alternateKeysView is already added than remove it so it's not colored wrong.
if self.view.viewWithTag(1001) != nil {
let viewWithTag = self.view.viewWithTag(1001)
Expand Down Expand Up @@ -171,7 +169,6 @@ class KeyboardViewController: UIInputViewController {
/// Overrides the previous color variables if the user switches between light and dark mode.
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
checkDarkModeSetColors()
// If alternateKeysView is already added than remove it so it's not colored wrong.
if self.view.viewWithTag(1001) != nil {
let viewWithTag = self.view.viewWithTag(1001)
Expand Down
Loading

0 comments on commit 3f18d40

Please sign in to comment.