From ae5a1c0c025d165d91accc924ebb9f0c8224ceba Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 4 Nov 2019 14:44:22 -0500 Subject: [PATCH] la. --- .../Atoms/TextFields/DigitEntryField.swift | 31 ++++++---- .../Atoms/TextFields/DropdownEntryField.swift | 30 ++++----- .../Atoms/TextFields/FormEntryField.swift | 7 ++- .../Atoms/TextFields/MdnEntryField.swift | 30 ++++++--- .../Atoms/TextFields/TextEntryField.swift | 3 + MVMCoreUI/Atoms/Views/CaretView.swift | 62 +++++++++---------- MVMCoreUI/Molecules/Items/TableViewCell.swift | 14 ++--- 7 files changed, 101 insertions(+), 76 deletions(-) diff --git a/MVMCoreUI/Atoms/TextFields/DigitEntryField.swift b/MVMCoreUI/Atoms/TextFields/DigitEntryField.swift index 86fbae9a..cb96a2cb 100644 --- a/MVMCoreUI/Atoms/TextFields/DigitEntryField.swift +++ b/MVMCoreUI/Atoms/TextFields/DigitEntryField.swift @@ -30,7 +30,7 @@ import UIKit public override var isEnabled: Bool { didSet { if isEnabled { - titleLabel.styleB2(true) + titleLabel.textColor = .black } else { titleLabel.textColor = .mfBattleshipGrey() } @@ -49,7 +49,7 @@ import UIKit var string = "" digitFields.forEach { string += $0.attributedPlaceholder?.string ?? "" } - + return !string.isEmpty ? string : nil } set { @@ -90,7 +90,7 @@ import UIKit var string = "" digitFields.forEach { string += $0.text ?? "" } - + return string } set { @@ -157,7 +157,7 @@ import UIKit buildTextFieldsView(size: MVMCoreUISplitViewController.getDetailViewWidth()) } - public init(numberOfDigits: Int, bothDelegates delegate: (UITextFieldDelegate & MFTextFieldDelegate)?, size: CGFloat? = nil) { + public init(numberOfDigits: Int, bothDelegates delegate: (UITextFieldDelegate & TextFieldDelegate)?, size: CGFloat? = nil) { super.init(bothDelegates: delegate as? (TextFieldDelegate & UITextFieldDelegate)) setup() @@ -177,7 +177,7 @@ import UIKit open func setup() { hideBorder = true - titleLabel.styleB2(true) + // titleLabel.styleB2(true) alignCenterHorizontal() } @@ -199,9 +199,9 @@ import UIKit self.titleLabel.updateView(size) if !self.digitFields.isEmpty { - + StackableViewController.remove(self.digitFields) - + self.digitFields.forEach { $0.updateView(size) } } @@ -225,14 +225,16 @@ import UIKit func createDigitField() -> DigitBox { let textField = DigitBox() + textField.isAccessibilityElement = true textField.delegate = self textField.textBoxDelegate = self - return textField } func buildTextFieldsView(size: CGFloat) { + var accessibleElements: [Any] = [titleLabel] + // Remove all current UI. if !digitFields.isEmpty { StackableViewController.remove(digitFields) @@ -241,7 +243,10 @@ import UIKit if numberOfDigits > 0 { let digitFields = [DigitBox](repeating: createDigitField(), count: numberOfDigits) - digitFields.forEach { $0.updateView(size) } + digitFields.forEach { + $0.updateView(size) + accessibleElements.append($0) + } self.digitFields = digitFields setupTextFieldsView(forSize: size) @@ -249,6 +254,8 @@ import UIKit } else { digitFields = [] } + + accessibilityElements = accessibleElements + [feedbackLabel] } override func valueChanged() { @@ -309,7 +316,7 @@ import UIKit validationBlock = { enteredValue in guard let enteredValue = enteredValue else { return false } - + return enteredValue.count > 0 && enteredValue.count == self.digitFields.count } } @@ -379,7 +386,7 @@ import UIKit super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) } - open override class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { + open override class func estimatedHeight(forRow json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { return 44 } @@ -390,7 +397,7 @@ import UIKit open override class func accessibilityElements() -> [Any]? { // let fields = [] -// return self.digitFields + // return self.digitFields return nil } diff --git a/MVMCoreUI/Atoms/TextFields/DropdownEntryField.swift b/MVMCoreUI/Atoms/TextFields/DropdownEntryField.swift index a553913c..fe5f44b7 100644 --- a/MVMCoreUI/Atoms/TextFields/DropdownEntryField.swift +++ b/MVMCoreUI/Atoms/TextFields/DropdownEntryField.swift @@ -14,8 +14,10 @@ import UIKit // MARK: - Outlets //-------------------------------------------------- - let dropDownCaretLabel: CaretView = { + let dropDownCaretView: CaretView = { let caret = CaretView() +// caret.size = .medium + caret.direction = .down caret.isHidden = true caret.isUserInteractionEnabled = true return caret @@ -77,9 +79,8 @@ import UIKit private func setup() { - dropDownCaretLabel.heightAnchor.constraint(equalToConstant: 40).isActive = true - dropDownCaretWidth = widthAnchor.constraint(equalToConstant: 40) - dropDownCaretWidth?.isActive = true + let tapOnCaret = UITapGestureRecognizer(target: self, action: #selector(startEditing)) + dropDownCaretView.addGestureRecognizer(tapOnCaret) } //-------------------------------------------------- @@ -87,20 +88,19 @@ import UIKit //-------------------------------------------------- open override func setupFieldContainerContent(_ container: UIView) { + super.setupFieldContainerContent(container) - let tapOnCaret = UITapGestureRecognizer(target: self, action: #selector(startEditing)) - dropDownCaretLabel.addGestureRecognizer(tapOnCaret) + container.addSubview(dropDownCaretView) - container.addSubview(dropDownCaretLabel) + dropDownCaretView.heightAnchor.constraint(equalToConstant: 9).isActive = true + dropDownCaretView.widthAnchor.constraint(equalToConstant: 16).isActive = true textFieldTrailingConstraint?.isActive = false - dropDownCaretLabel.topAnchor.constraint(equalTo: container.topAnchor).isActive = true - textFieldTrailingConstraint = dropDownCaretLabel.leadingAnchor.constraint(equalTo: textField.trailingAnchor, constant: 6) + dropDownCaretView.topAnchor.constraint(greaterThanOrEqualTo: container.topAnchor, constant: 13).isActive = true + textFieldTrailingConstraint = dropDownCaretView.leadingAnchor.constraint(equalTo: textField.trailingAnchor, constant: 6) textFieldTrailingConstraint?.isActive = true - container.trailingAnchor.constraint(equalTo: dropDownCaretLabel.trailingAnchor, constant: 16).isActive = true - container.bottomAnchor.constraint(equalTo: dropDownCaretLabel.bottomAnchor).isActive = true - dropDownCaretWidth = dropDownCaretLabel.widthAnchor.constraint(equalToConstant: 0) - dropDownCaretWidth?.isActive = true + container.trailingAnchor.constraint(equalTo: dropDownCaretView.trailingAnchor, constant: 16).isActive = true + container.bottomAnchor.constraint(greaterThanOrEqualTo: dropDownCaretView.bottomAnchor, constant: 13).isActive = true } //-------------------------------------------------- @@ -109,7 +109,7 @@ import UIKit public func showDropDown(_ show: Bool) { - dropDownCaretLabel.isHidden = !show + dropDownCaretView.isHidden = !show dropDownCaretWidth?.isActive = !show setNeedsLayout() layoutIfNeeded() @@ -211,7 +211,7 @@ extension DropdownEntryField { else { return } if let _ = dictionary[KeyType] as? String { - dropDownCaretLabel.isHidden = false + dropDownCaretView.isHidden = false } } } diff --git a/MVMCoreUI/Atoms/TextFields/FormEntryField.swift b/MVMCoreUI/Atoms/TextFields/FormEntryField.swift index b0638253..f3e72664 100644 --- a/MVMCoreUI/Atoms/TextFields/FormEntryField.swift +++ b/MVMCoreUI/Atoms/TextFields/FormEntryField.swift @@ -23,6 +23,7 @@ import UIKit let label = Label() label.font = MFStyler.fontB3() label.textColor = UIColor.mfBattleshipGrey() + label.isAccessibilityElement = true label.setContentCompressionResistancePriority(.required, for: .vertical) label.setContentCompressionResistancePriority(.required, for: .horizontal) return label @@ -32,6 +33,7 @@ import UIKit let label = Label() label.font = MFStyler.fontForTextFieldUnderLabel() label.textColor = .black + label.isAccessibilityElement = true label.setContentCompressionResistancePriority(.required, for: .vertical) label.setContentCompressionResistancePriority(.required, for: .horizontal) return label @@ -39,6 +41,7 @@ import UIKit public private(set) var fieldContainer: UIView = { let view = UIView(frame: .zero) + view.isAccessibilityElement = false view.translatesAutoresizingMaskIntoConstraints = false return view }() @@ -175,6 +178,7 @@ import UIKit translatesAutoresizingMaskIntoConstraints = false setContentCompressionResistancePriority(.required, for: .vertical) + accessibilityElements = [titleLabel, feedbackLabel] backgroundColor = .clear addSubview(titleLabel) @@ -310,6 +314,7 @@ import UIKit case disable } + /// Updates the visual appearance of the container, with some logical laterations as well. public func updateUI(appearance: Appearance) { self.appearance = appearance @@ -339,7 +344,7 @@ import UIKit case .disable: isUserInteractionEnabled = false borderStrokeColor = .mfSilver() - titleLabel.textColor = self.isEnabled ? UIColor.mfBattleshipGrey() : UIColor.mfSilver() + titleLabel.textColor = self.isEnabled ? .mfBattleshipGrey() : .mfSilver() bottomBar.backgroundColor = self.isEnabled ? UIColor.black.cgColor : UIColor.mfSilver().cgColor } diff --git a/MVMCoreUI/Atoms/TextFields/MdnEntryField.swift b/MVMCoreUI/Atoms/TextFields/MdnEntryField.swift index f1b769d5..6ca54314 100644 --- a/MVMCoreUI/Atoms/TextFields/MdnEntryField.swift +++ b/MVMCoreUI/Atoms/TextFields/MdnEntryField.swift @@ -20,11 +20,25 @@ import MVMCore public var isNationalMdn = true public var shouldValidateMDN = false + private weak var outsiderTextDelegate: UITextFieldDelegate? + public var mdn: String? { get { return MVMCoreUIUtility.removeMdnFormat(text) } set { text = MVMCoreUIUtility.formatMdn(newValue) } } + /// If you're using a MFViewController, you must set this to it + public override weak var uiTextFieldDelegate: UITextFieldDelegate? { + get { return textField.delegate } + set { + textField.delegate = newValue + outsiderTextDelegate = newValue + if newValue != nil { + textField.delegate = self + } + } + } + //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- @@ -92,7 +106,7 @@ import MVMCore clearErrorState() } else { errorMessage = errorMessage ?? MVMCoreUIUtility.hardcodedString(withKey: "textfield_phone_format_error_message") - UIAccessibility.post(notification: UIAccessibility.Notification.layoutChanged, argument: textField) + UIAccessibility.post(notification: .layoutChanged, argument: textField) } return isValid @@ -145,7 +159,7 @@ import MVMCore textField.resignFirstResponder() - return uiTextFieldDelegate?.textFieldShouldReturn?(textField) ?? true + return outsiderTextDelegate?.textFieldShouldReturn?(textField) ?? true } public func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { @@ -154,18 +168,18 @@ import MVMCore return false } - return uiTextFieldDelegate?.textField?(textField, shouldChangeCharactersIn: range, replacementString: string) ?? true + return outsiderTextDelegate?.textField?(textField, shouldChangeCharactersIn: range, replacementString: string) ?? true } public func textFieldDidBeginEditing(_ textField: UITextField) { textField.text = MVMCoreUIUtility.removeMdnFormat(textField.text) - uiTextFieldDelegate?.textFieldDidBeginEditing?(textField) + outsiderTextDelegate?.textFieldDidBeginEditing?(textField) } public func textFieldDidEndEditing(_ textField: UITextField) { - uiTextFieldDelegate?.textFieldDidEndEditing?(textField) + outsiderTextDelegate?.textFieldDidEndEditing?(textField) if validateAndColor() && isNationalMdn { textField.text = MVMCoreUIUtility.formatMdn(textField.text) @@ -178,16 +192,16 @@ import MVMCore public func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool { - return uiTextFieldDelegate?.textFieldShouldBeginEditing?(textField) ?? true + return outsiderTextDelegate?.textFieldShouldBeginEditing?(textField) ?? true } public func textFieldShouldEndEditing(_ textField: UITextField) -> Bool { - return uiTextFieldDelegate?.textFieldShouldEndEditing?(textField) ?? true + return outsiderTextDelegate?.textFieldShouldEndEditing?(textField) ?? true } public func textFieldShouldClear(_ textField: UITextField) -> Bool { - return uiTextFieldDelegate?.textFieldShouldClear?(textField) ?? true + return outsiderTextDelegate?.textFieldShouldClear?(textField) ?? true } } diff --git a/MVMCoreUI/Atoms/TextFields/TextEntryField.swift b/MVMCoreUI/Atoms/TextFields/TextEntryField.swift index 9b0bfbb2..c40042b3 100644 --- a/MVMCoreUI/Atoms/TextFields/TextEntryField.swift +++ b/MVMCoreUI/Atoms/TextFields/TextEntryField.swift @@ -26,6 +26,7 @@ import UIKit public private(set) var textField: UITextField = { let textField = UITextField(frame: .zero) + textField.isAccessibilityElement = true textField.translatesAutoresizingMaskIntoConstraints = false textField.setContentCompressionResistancePriority(.required, for: .vertical) textField.font = MFStyler.fontForTextField() @@ -151,6 +152,8 @@ import UIKit textFieldTrailingConstraint = container.trailingAnchor.constraint(equalTo: textField.trailingAnchor, constant: 16) textFieldTrailingConstraint?.isActive = true + + accessibilityElements = [titleLabel, textField, feedbackLabel] } open override func updateView(_ size: CGFloat) { diff --git a/MVMCoreUI/Atoms/Views/CaretView.swift b/MVMCoreUI/Atoms/Views/CaretView.swift index 519965a1..4b13d5fa 100644 --- a/MVMCoreUI/Atoms/Views/CaretView.swift +++ b/MVMCoreUI/Atoms/Views/CaretView.swift @@ -15,7 +15,7 @@ public var strokeColor: UIColor = .black public var lineWidth: CGFloat = 1 public var direction: Direction = .right - public var size: CaretSize? +// public var size: CaretSize? private var caretPath: UIBezierPath = UIBezierPath() @@ -33,29 +33,29 @@ // MARK: - Constraints //------------------------------------------------------ - public enum CaretSize: String { - case small - case medium - case large - - // Dimensions of container; provided by InVision. - func dimensions() -> CGSize { - - switch self { - case .small: - return CGSize(width: 6, height: 10) - - case .medium: - return CGSize(width: 9, height: 16) - - case .large: - return CGSize(width: 14, height: 24) - } - } - } +// public enum CaretSize: String { +// case small +// case medium +// case large +// +// // Dimensions of container; provided by InVision. +// func dimensions() -> CGSize { +// +// switch self { +// case .small: +// return CGSize(width: 6, height: 10) +// +// case .medium: +// return CGSize(width: 9, height: 16) +// +// case .large: +// return CGSize(width: 14, height: 24) +// } +// } +// } - public var heightConstraint: NSLayoutConstraint? - public var widthConstraint: NSLayoutConstraint? +// public var heightConstraint: NSLayoutConstraint? +// public var widthConstraint: NSLayoutConstraint? //------------------------------------------------------ // MARK: - Initialization @@ -88,8 +88,8 @@ defaultState() // Establishing references. - heightConstraint = heightAnchor.constraint(equalToConstant: 0) - widthConstraint = widthAnchor.constraint(equalToConstant: 0) +// heightConstraint = heightAnchor.constraint(equalToConstant: 0) +// widthConstraint = widthAnchor.constraint(equalToConstant: 0) } //------------------------------------------------------ @@ -162,12 +162,12 @@ @objc public func setConstraints() { - guard let dimensions = size?.dimensions() else { return } - - heightConstraint?.constant = dimensions.height - heightConstraint?.isActive = true - widthConstraint?.constant = dimensions.width - widthConstraint?.isActive = true +// guard let dimensions = size?.dimensions() else { return } +// +// heightConstraint?.constant = dimensions.height +// heightConstraint?.isActive = true +// widthConstraint?.constant = dimensions.width +// widthConstraint?.isActive = true } //------------------------------------------------------ diff --git a/MVMCoreUI/Molecules/Items/TableViewCell.swift b/MVMCoreUI/Molecules/Items/TableViewCell.swift index 3dd85f71..588b0b78 100644 --- a/MVMCoreUI/Molecules/Items/TableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/TableViewCell.swift @@ -204,17 +204,13 @@ import UIKit // MARK: - Arrow /// 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(lineWidth: 1) - caretView?.size = .small - caretView?.setConstraints() - - if let size = caretView?.size?.dimensions() { - caretViewWidthSizeObject = MFSizeObject(standardSize: size.width, standardiPadPortraitSize: 9) - caretViewHeightSizeObject = MFSizeObject(standardSize: size.height, standardiPadPortraitSize: 16) - } + caretView?.frame = CGRect(x: 0, y: 0, width: width, height: height) + caretViewWidthSizeObject = MFSizeObject(standardSize: width, standardiPadPortraitSize: 9) + caretViewHeightSizeObject = MFSizeObject(standardSize: height, standardiPadPortraitSize: 16) accessoryView = caretView }