diff --git a/MVMCoreUI/Atoms/TextFields/DigitBox.swift b/MVMCoreUI/Atoms/TextFields/DigitBox.swift index 37c30b22..d590b9e3 100644 --- a/MVMCoreUI/Atoms/TextFields/DigitBox.swift +++ b/MVMCoreUI/Atoms/TextFields/DigitBox.swift @@ -35,7 +35,7 @@ import UIKit private var previousSize: CGFloat = 0.0 //-------------------------------------------------- - // MARK: - Property Observer + // MARK: - Computed Properties //-------------------------------------------------- public override var showError: Bool { diff --git a/MVMCoreUI/Atoms/TextFields/DigitEntryField.swift b/MVMCoreUI/Atoms/TextFields/DigitEntryField.swift index c3e1f3b5..1d355c88 100644 --- a/MVMCoreUI/Atoms/TextFields/DigitEntryField.swift +++ b/MVMCoreUI/Atoms/TextFields/DigitEntryField.swift @@ -13,36 +13,35 @@ import UIKit */ @objcMembers open class DigitEntryField: TextEntryField, DigitBoxProtocol { //-------------------------------------------------- - // MARK: - Properties + // MARK: - Stored Properties //-------------------------------------------------- private(set) var numberOfDigits = 4 - public var switchFieldsAutomatically = false + + /// Monitors if fields are being selected internally. + private var switchFieldsAutomatically = false public var digitBoxes: [DigitBox] = [] var selectedDigitField: DigitBox? //-------------------------------------------------- - // MARK: - Property Observers + // MARK: - Computed Properties //-------------------------------------------------- public override var isEnabled: Bool { get { return super.isEnabled } set (enabled) { titleLabel.textColor = enabled ? .mfBattleshipGrey() : .mfSilver() - - digitBoxes.forEach { - $0.isEnabled = enabled - $0.isUserInteractionEnabled = enabled - $0.digitField.isEnabled = enabled - $0.digitField.textColor = enabled ? .black : .mfBattleshipGrey() - } + digitBoxes.forEach { $0.isEnabled = enabled } + super.isEnabled = enabled } } public override var showError: Bool { - didSet { - digitBoxes.forEach { $0.showError = self.showError } + get { return super.showError } + set (error) { + digitBoxes.forEach { $0.showError = error } + super.showError = error } } @@ -50,6 +49,7 @@ import UIKit get { return super.isLocked } set (locked) { digitBoxes.forEach { $0.isLocked = locked } + super.isLocked = locked } } @@ -109,6 +109,13 @@ import UIKit } } + //-------------------------------------------------- + // MARK: - Delegate + //-------------------------------------------------- + + /// Holds a reference to the 'delegating' class so this class can internally influence the TextField behavior as well. + private weak var proprietorTextDelegate: UITextFieldDelegate? + /// If you're using a MFViewController, you must set this to it public override weak var uiTextFieldDelegate: UITextFieldDelegate? { get { return textField.delegate } @@ -118,19 +125,15 @@ import UIKit } } - //-------------------------------------------------- - // MARK: - Delegate - //-------------------------------------------------- - - /// Holds a reference to the 'delegating' class so this class can internally influence the TextField behavior as well. - private weak var proprietorTextDelegate: UITextFieldDelegate? - //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- @objc public override init(frame: CGRect) { super.init(frame: frame) + + isAccessibilityElement = false + entryContainer.disableAllBorders = true } @objc public convenience init() { @@ -152,12 +155,7 @@ import UIKit // MARK: - Setup //-------------------------------------------------- - @objc public override func setupFieldContainerContent(_ container: UIView) { - - alignCenterHorizontal() - isAccessibilityElement = false - entryContainer.disableAllBorders = true - } + @objc public override func setupFieldContainerContent(_ container: UIView) {} @objc private func createDigitField() -> DigitBox { @@ -173,10 +171,11 @@ import UIKit var accessibleElements: [Any] = [titleLabel] - digitBoxes.forEach { $0.removeFromSuperview() } + resetDigitBoxes() if numberOfDigits > 0 { var digitBoxes = [DigitBox]() + for _ in 0..