Introduce color provider to encapsulate check for iOS 13 availability

This commit is contained in:
Danny Moesch 2019-10-01 22:36:22 +02:00
parent e0c32003e3
commit 51c9510f3d
12 changed files with 80 additions and 41 deletions

View file

@ -40,17 +40,13 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate {
self.view.addSubview(passcodeTextField)
self.passcodeTextField = passcodeTextField
if #available(iOSApplicationExtension 13.0, *) {
view.backgroundColor = .systemBackground
passcodeTextField.backgroundColor = .secondarySystemBackground
passcodeTextField.textColor = .secondaryLabel
} else {
view.backgroundColor = .white
}
view.backgroundColor = Colors.systemBackground
passcodeTextField.backgroundColor = Colors.secondarySystemBackground
passcodeTextField.textColor = Colors.secondaryLabel
let biometryAuthButton = UIButton(type: .custom)
biometryAuthButton.setTitle("", for: .normal)
biometryAuthButton.setTitleColor(Globals.blue, for: .normal)
biometryAuthButton.setTitleColor(Colors.systemBlue, for: .normal)
biometryAuthButton.addTarget(self, action: #selector(bioButtonPressedAction(_:)), for: .touchUpInside)
biometryAuthButton.isHidden = true
biometryAuthButton.translatesAutoresizingMaskIntoConstraints = false
@ -76,7 +72,7 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate {
let forgotPasscodeButton = UIButton(type: .custom)
forgotPasscodeButton.setTitle("ForgotYourPasscode?".localize(), for: .normal)
forgotPasscodeButton.titleLabel?.font = UIFont.systemFont(ofSize: UIFont.systemFontSize)
forgotPasscodeButton.setTitleColor(Globals.blue, for: .normal)
forgotPasscodeButton.setTitleColor(Colors.systemBlue, for: .normal)
forgotPasscodeButton.addTarget(self, action: #selector(forgotPasscodeButtonPressedAction(_:)), for: .touchUpInside)
// hide the forgotPasscodeButton if the native app is running
forgotPasscodeButton.isHidden = self.isCancellable
@ -86,7 +82,7 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate {
let cancelButton = UIButton(type: .custom)
cancelButton.setTitle("Cancel".localize(), for: .normal)
cancelButton.setTitleColor(Globals.blue, for: .normal)
cancelButton.setTitleColor(Colors.systemBlue, for: .normal)
cancelButton.addTarget(self, action: #selector(passcodeLockDidCancel), for: .touchUpInside)
cancelButton.isHidden = !self.isCancellable
cancelButton.translatesAutoresizingMaskIntoConstraints = false

View file

@ -0,0 +1,51 @@
//
// Colors.swift
// passKit
//
// Created by Danny Moesch on 01.10.19.
// Copyright © 2019 Bob Sun. All rights reserved.
//
public struct Colors {
public static let label: UIColor = {
if #available(iOS 13.0, *) {
return .label
}
return .black
}()
public static let secondaryLabel: UIColor = {
if #available(iOS 13.0, *) {
return .secondaryLabel
}
return .init(red: 60.0, green: 60.0, blue: 67.0, alpha: 0.6)
}()
public static let systemBackground: UIColor = {
if #available(iOS 13.0, *) {
return .systemBackground
}
return .white
}()
public static let secondarySystemBackground: UIColor = {
if #available(iOS 13.0, *) {
return .secondarySystemBackground
}
return .init(red: 242.0, green: 242.0, blue: 247.0, alpha: 1.0)
}()
public static let systemRed: UIColor = {
if #available(iOS 13.0, *) {
return .systemRed
}
return .red
}()
public static let systemBlue: UIColor = {
if #available(iOS 13.0, *) {
return .systemBlue
}
return .blue
}()
}

View file

@ -41,14 +41,6 @@ public class Globals {
public static let passwordFont = UIFont(name: "Courier-Bold", size: UIFont.labelFontSize - 1)
// UI related
public static let red = UIColor.systemRed
public static let blue = UIColor.systemBlue
public static let black: UIColor = {
if #available(iOSApplicationExtension 13.0, *) {
return UIColor.label
}
return UIColor.black
}()
public static let tableCellButtonSize = CGFloat(20.0)
private init() { }

View file

@ -22,11 +22,11 @@ public class Utils {
for (index, element) in plainPassword.unicodeScalars.enumerated() {
var charColor = UIColor.darkText
if NSCharacterSet.decimalDigits.contains(element) {
charColor = Globals.red
charColor = Colors.systemRed
} else if !NSCharacterSet.letters.contains(element) {
charColor = Globals.blue
charColor = Colors.systemBlue
} else {
charColor = Globals.black
charColor = Colors.label
}
attributedPassword.addAttribute(NSAttributedString.Key.foregroundColor, value: charColor, range: NSRange(location: index, length: 1))
}