Skip to content

Commit

Permalink
#116 share DeviceType and update Scribe icon in dark mode check
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtavis committed Feb 2, 2022
1 parent b2e09e5 commit e846dca
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
15 changes: 15 additions & 0 deletions Keyboards/KeyboardsBase/ColorVariables.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

import UIKit

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

// 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)
Expand All @@ -29,6 +32,12 @@ var previewOrange = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/25
/// 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: "ScribeBtnPhoneBlack.png")
} else if DeviceType.isPad {
scribeKeyIcon = UIImage(named: "ScribeBtnPadBlack.png")
}

keyColor = UIColor.keyColorLight
keyCharColor = UIColor.keyCharColorLight
specialKeyColor = UIColor.specialKeyColorLight
Expand All @@ -47,6 +56,12 @@ func checkDarkModeSetColors() {
previewGreen = UIColor.previewGreenLight
previewOrange = UIColor.previewOrangeLight
} else if UITraitCollection.current.userInterfaceStyle == .dark {
if DeviceType.isPhone {
scribeKeyIcon = UIImage(named: "ScribeBtnPhoneWhite.png")
} else if DeviceType.isPad {
scribeKeyIcon = UIImage(named: "ScribeBtnPadWhite.png")
}

keyColor = UIColor.keyColorDark
keyCharColor = UIColor.keyCharColorDark
specialKeyColor = UIColor.specialKeyColorDark
Expand Down
14 changes: 1 addition & 13 deletions Keyboards/KeyboardsBase/KeyboardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -313,19 +313,7 @@ class KeyboardViewController: UIInputViewController {

/// Assigns the icon and sets up the Scribe button.
func setScribeBtn() {
if UITraitCollection.current.userInterfaceStyle == .dark {
if DeviceType.isPhone {
scribeBtn.setImage(UIImage(named: "ScribeBtnPhoneWhite.png"), for: .normal)
} else if DeviceType.isPad {
scribeBtn.setImage(UIImage(named: "ScribeBtnPadWhite.png"), for: .normal)
}
} else {
if DeviceType.isPhone {
scribeBtn.setImage(UIImage(named: "ScribeBtnPhoneBlack.png"), for: .normal)
} else if DeviceType.isPad {
scribeBtn.setImage(UIImage(named: "ScribeBtnPadBlack.png"), for: .normal)
}
}
scribeBtn.setImage(scribeKeyIcon, for: .normal)
setBtn(btn: scribeBtn, color: commandKeyColor, name: "Scribe", canCapitalize: false, isSpecial: false)
scribeBtn.layer.borderColor = previewBarBorderColor
scribeBtn.layer.borderWidth = 1.0
Expand Down
4 changes: 4 additions & 0 deletions Scribe.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@
D1D880E027860D7B00407050 /* nouns.json in Resources */ = {isa = PBXBuildFile; fileRef = D1D880DD27860D7B00407050 /* nouns.json */; };
D1D880E127860D7B00407050 /* translations.json in Resources */ = {isa = PBXBuildFile; fileRef = D1D880DE27860D7B00407050 /* translations.json */; };
D1D880E227860D7B00407050 /* verbs.json in Resources */ = {isa = PBXBuildFile; fileRef = D1D880DF27860D7B00407050 /* verbs.json */; };
D1F0367227AAE12200CD7921 /* InterfaceVariables.swift in Sources */ = {isa = PBXBuildFile; fileRef = D190B2492741B31F00705659 /* InterfaceVariables.swift */; };
D1F0367327AAE1B400CD7921 /* CommandVariables.swift in Sources */ = {isa = PBXBuildFile; fileRef = D190B2462741B24F00705659 /* CommandVariables.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -827,6 +829,8 @@
38BD213622D5907F00C6795D /* ViewController.swift in Sources */,
D196B360279A051000228F3F /* PrivacyPolicy.swift in Sources */,
38BD213422D5907F00C6795D /* AppDelegate.swift in Sources */,
D1F0367327AAE1B400CD7921 /* CommandVariables.swift in Sources */,
D1F0367227AAE12200CD7921 /* InterfaceVariables.swift in Sources */,
D1362A39274C106A00C00E48 /* ColorVariables.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
10 changes: 5 additions & 5 deletions Scribe/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,19 @@ class ViewController: UIViewController {
var fontSize = CGFloat(0)
/// Sets the font size for the text in the app screen and corresponding UIImage icons.
func setFontSize() {
if UIDevice.current.userInterfaceIdiom == .phone {
if DeviceType.isPhone {
fontSize = UIScreen.main.bounds.height / 65
} else if UIDevice.current.userInterfaceIdiom == .pad {
} else if DeviceType.isPad {
fontSize = UIScreen.main.bounds.height / 60
}
}

/// Sets the top icon for the app screen given the device to assure that it's oriented correctly to its background.
func setTopIcon() {
if UIDevice.current.userInterfaceIdiom == .phone {
if DeviceType.isPhone {
topIconPhone.isHidden = false
topIconPad.isHidden = true
} else if UIDevice.current.userInterfaceIdiom == .pad {
} else if DeviceType.isPad {
topIconPhone.isHidden = true
topIconPad.isHidden = false
}
Expand Down Expand Up @@ -218,7 +218,7 @@ class ViewController: UIViewController {
// Set configurations for corner icons.
var settingsSymbolConfig = UIImage.SymbolConfiguration(pointSize: fontSize * 0.2, weight: .medium, scale: .medium)
var privacySymbolConfig = UIImage.SymbolConfiguration(pointSize: fontSize * 0.25, weight: .medium, scale: .medium)
if UIDevice.current.userInterfaceIdiom == .pad {
if DeviceType.isPad {
if UIScreen.main.bounds.height < UIScreen.main.bounds.width {
settingsSymbolConfig = UIImage.SymbolConfiguration(pointSize: fontSize * 0.05, weight: .medium, scale: .medium)
privacySymbolConfig = UIImage.SymbolConfiguration(pointSize: fontSize * 0.15, weight: .medium, scale: .medium)
Expand Down

0 comments on commit e846dca

Please sign in to comment.