diff --git a/MVMCoreUI/Atoms/TextFields/DigitBox.swift b/MVMCoreUI/Atoms/TextFields/DigitBox.swift index 79d4e554..37c30b22 100644 --- a/MVMCoreUI/Atoms/TextFields/DigitBox.swift +++ b/MVMCoreUI/Atoms/TextFields/DigitBox.swift @@ -8,12 +8,12 @@ import UIKit -@objc protocol DigitBoxDelegate { +@objc protocol DigitBoxProtocol { @objc optional func digitFieldDidDelete(_ textField: UITextField?) } -@objcMembers open class DigitBox: FormFieldContainer, UITextFieldDelegate { +@objcMembers open class DigitBox: FormFieldContainer, UITextFieldDelegate, TextFieldDidDeleteProtocol { //-------------------------------------------------- // MARK: - Outlets //-------------------------------------------------- @@ -61,7 +61,7 @@ import UIKit // MARK: - Delegate //-------------------------------------------------- - weak var digitBoxDelegate: DigitBoxDelegate? + weak var digitBoxDelegate: DigitBoxProtocol? //-------------------------------------------------- // MARK: - Constraints @@ -74,16 +74,16 @@ import UIKit // MARK: - Initializers //-------------------------------------------------- - public override init(frame: CGRect) { + @objc public override init(frame: CGRect) { super.init(frame: frame) setup() } - public convenience init() { + @objc public convenience init() { self.init(frame: .zero) } - required public init?(coder: NSCoder) { + @objc required public init?(coder: NSCoder) { super.init(coder: coder) fatalError("DigitBox does not support xibs.") } @@ -92,7 +92,7 @@ import UIKit // MARK: - Lifecycle //-------------------------------------------------- - private func setup() { + @objc private func setup() { guard constraints.isEmpty else { return } @@ -101,6 +101,7 @@ import UIKit addSubview(digitField) digitField.delegate = self + digitField.didDeleteDelegate = self NSLayoutConstraint.activate([ digitField.heightAnchor.constraint(equalToConstant: 24), @@ -120,21 +121,20 @@ import UIKit layer.addSublayer(bottomBar) } updateView(MVMCoreUISplitViewController.getDetailViewWidth()) - digitField.addTarget(self, action:#selector(textfieldChanged) , for: .valueChanged) } - func textfieldChanged() { - + @objc public func textFieldDidDelete() { + digitBoxDelegate?.digitFieldDidDelete?(digitField) } - open override func layoutSubviews() { + @objc open override func layoutSubviews() { super.layoutSubviews() let barHeight: CGFloat = showError ? 4 : 1 bottomBar?.frame = CGRect(x: 0, y: bounds.height - barHeight, width: bounds.width, height: barHeight) } - open override func reset() { + @objc open override func reset() { super.reset() digitField.text = nil @@ -144,7 +144,7 @@ import UIKit // MARK: - Methods //-------------------------------------------------- - public override func updateView(_ size: CGFloat) { + @objc public override func updateView(_ size: CGFloat) { super.updateView(size) DispatchQueue.main.async { [weak self] in diff --git a/MVMCoreUI/Atoms/TextFields/DigitEntryField.swift b/MVMCoreUI/Atoms/TextFields/DigitEntryField.swift index ce53c0d1..c3e1f3b5 100644 --- a/MVMCoreUI/Atoms/TextFields/DigitEntryField.swift +++ b/MVMCoreUI/Atoms/TextFields/DigitEntryField.swift @@ -11,7 +11,7 @@ import UIKit /** * Subclass of TextEntryField as it is to use similar logic as a singular textField but appear separate.. */ -@objcMembers open class DigitEntryField: TextEntryField, DigitBoxDelegate { +@objcMembers open class DigitEntryField: TextEntryField, DigitBoxProtocol { //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- @@ -122,7 +122,7 @@ import UIKit // MARK: - Delegate //-------------------------------------------------- - /// Holds a reference to the delegating class so this class can internally influence the TextField behavior as well. + /// Holds a reference to the 'delegating' class so this class can internally influence the TextField behavior as well. private weak var proprietorTextDelegate: UITextFieldDelegate? //-------------------------------------------------- @@ -140,6 +140,7 @@ import UIKit @objc public convenience init(numberOfDigits: Int) { self.init(frame: .zero) self.numberOfDigits = numberOfDigits + assembleDigitFieldsView(size: MVMCoreUISplitViewController.getDetailViewWidth()) } @objc required public init?(coder: NSCoder) { @@ -156,7 +157,6 @@ import UIKit alignCenterHorizontal() isAccessibilityElement = false entryContainer.disableAllBorders = true - assembleDigitFieldsView(size: MVMCoreUISplitViewController.getDetailViewWidth()) } @objc private func createDigitField() -> DigitBox { @@ -173,6 +173,8 @@ import UIKit var accessibleElements: [Any] = [titleLabel] + digitBoxes.forEach { $0.removeFromSuperview() } + if numberOfDigits > 0 { var digitBoxes = [DigitBox]() for _ in 0.. Bool { + @objc public func validate() -> Bool { if !shouldValidateMDN { let isValid = hasValidMDN() @@ -116,7 +116,7 @@ import MVMCore return true } - @objc func getContacts(_ sender: Any?) { + @objc public func getContacts(_ sender: Any?) { let picker = CNContactPickerViewController() picker.delegate = self @@ -183,7 +183,7 @@ import MVMCore proprietorTextDelegate?.textFieldDidEndEditing?(textField) - if validateAndColor() && isNationalMDN { + if validate() && isNationalMDN { textField.text = MVMCoreUIUtility.formatMdn(textField.text) } } diff --git a/MVMCoreUI/BaseClasses/TextField.swift b/MVMCoreUI/BaseClasses/TextField.swift index c8321f4d..5b3a4963 100644 --- a/MVMCoreUI/BaseClasses/TextField.swift +++ b/MVMCoreUI/BaseClasses/TextField.swift @@ -8,12 +8,12 @@ import UIKit -protocol TextFieldDelegate { +public protocol TextFieldDidDeleteProtocol: class { func textFieldDidDelete() } -open class TextField: UITextField { +@objcMembers open class TextField: UITextField { //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- @@ -30,7 +30,7 @@ open class TextField: UITextField { //-------------------------------------------------- /// Holds a reference to the delegating class so this class can internally influence the TextField behavior as well. - private weak var proprietorTextDelegate: UITextFieldDelegate? + public weak var didDeleteDelegate: TextFieldDidDeleteProtocol? //-------------------------------------------------- // MARK: - Initialization @@ -69,7 +69,7 @@ open class TextField: UITextField { open override func deleteBackward() { super.deleteBackward() -// proprietorTextDelegate?.textFieldDidDelete() + didDeleteDelegate?.textFieldDidDelete() } } diff --git a/MVMCoreUI/Containers/views/FormFieldContainer.swift b/MVMCoreUI/Containers/views/FormFieldContainer.swift index 1673d2fa..b890d62b 100644 --- a/MVMCoreUI/Containers/views/FormFieldContainer.swift +++ b/MVMCoreUI/Containers/views/FormFieldContainer.swift @@ -101,7 +101,7 @@ import UIKit _isLocked = false _isEnabled = true _showError = false - +    fieldState = selected ? .selected : .original } } @@ -155,6 +155,8 @@ import UIKit override open func setupView() { super.setupView() + isAccessibilityElement = false + isOpaque = false if let bottomBar = bottomBar { layer.addSublayer(bottomBar) diff --git a/MVMCoreUI/Molecules/Items/TableViewCell.swift b/MVMCoreUI/Molecules/Items/TableViewCell.swift index 13faeb42..0e303228 100644 --- a/MVMCoreUI/Molecules/Items/TableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/TableViewCell.swift @@ -208,12 +208,14 @@ import UIKit /// Adds the standard mvm style caret to the accessory view @objc public func addCaretViewAccessory() { guard accessoryView == nil else { return } - let width: CGFloat = 6 - let height: CGFloat = 10 - caretView = CaretView(lineThickness: CaretView.thin) - caretView?.frame = CGRect(x: 0, y: 0, width: width, height: height) - caretViewWidthSizeObject = MFSizeObject(standardSize: width, standardiPadPortraitSize: 9) - caretViewHeightSizeObject = MFSizeObject(standardSize: height, standardiPadPortraitSize: 16) + caretView = CaretView(lineWidth: 1) + caretView?.size = .small(.vertical) + caretView?.setConstraints() + + if let size = caretView?.size?.dimensions() { + caretViewWidthSizeObject = MFSizeObject(standardSize: size.width, standardiPadPortraitSize: 9) + caretViewHeightSizeObject = MFSizeObject(standardSize: size.height, standardiPadPortraitSize: 16) + } accessoryView = caretView }