more changes.
This commit is contained in:
parent
f19d45b865
commit
8b5fe4a1f4
@ -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
|
||||
|
||||
@ -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..<numberOfDigits {
|
||||
@ -233,8 +235,7 @@ import UIKit
|
||||
|
||||
@objc open override func reset() {
|
||||
super.reset()
|
||||
|
||||
entryContainer.disableAllBorders = false
|
||||
|
||||
digitBoxes.forEach { $0.reset() }
|
||||
}
|
||||
|
||||
@ -269,7 +270,7 @@ import UIKit
|
||||
|
||||
var selectPreviousField = false
|
||||
|
||||
for field in digitBoxes.reversed() {
|
||||
for field in Array(digitBoxes.reversed()) {
|
||||
|
||||
if field.isSelected {
|
||||
selectPreviousField = true
|
||||
@ -307,8 +308,8 @@ import UIKit
|
||||
if !clear {
|
||||
switchFieldsAutomatically = true
|
||||
}
|
||||
field.isSelected = true
|
||||
field.digitField.becomeFirstResponder()
|
||||
field.isSelected = true
|
||||
switchFieldsAutomatically = false
|
||||
|
||||
UIAccessibility.post(notification: .layoutChanged, argument: field.digitField)
|
||||
@ -408,19 +409,27 @@ extension DigitEntryField {
|
||||
if digitBox.digitField == textField {
|
||||
selectedDigitField = digitBox
|
||||
digitBox.isSelected = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !switchFieldsAutomatically {
|
||||
textField.text = ""
|
||||
valueChanged()
|
||||
}
|
||||
// if !switchFieldsAutomatically {
|
||||
// textField.text = ""
|
||||
// valueChanged()
|
||||
// }
|
||||
|
||||
proprietorTextDelegate?.textFieldDidBeginEditing?(textField)
|
||||
}
|
||||
|
||||
@objc public func textFieldDidEndEditing(_ textField: UITextField) {
|
||||
|
||||
digitBoxes.forEach { box in
|
||||
if box.digitField == textField {
|
||||
box.isSelected = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
proprietorTextDelegate?.textFieldDidEndEditing?(textField)
|
||||
}
|
||||
|
||||
|
||||
@ -22,14 +22,12 @@ import UIKit
|
||||
let label = Label()
|
||||
label.font = MFStyler.fontB3()
|
||||
label.textColor = .mfBattleshipGrey()
|
||||
label.isAccessibilityElement = true
|
||||
label.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||
return label
|
||||
}()
|
||||
|
||||
public private(set) var entryContainer: FormFieldContainer = {
|
||||
let view = FormFieldContainer()
|
||||
view.isAccessibilityElement = false
|
||||
return view
|
||||
}()
|
||||
|
||||
@ -37,7 +35,6 @@ import UIKit
|
||||
let label = Label()
|
||||
label.font = MFStyler.fontForTextFieldUnderLabel()
|
||||
label.textColor = .black
|
||||
label.isAccessibilityElement = true
|
||||
label.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||
return label
|
||||
}()
|
||||
|
||||
@ -52,6 +52,7 @@ open class ItemDropdownEntryField: BaseDropdownEntryField {
|
||||
|
||||
pickerView = MVMCoreUICommonViewsUtility.addPicker(to: textField, delegate: self)
|
||||
textField.hideBlinkingCaret = true
|
||||
textField.autocorrectionType = .no
|
||||
uiTextFieldDelegate = self
|
||||
}
|
||||
|
||||
|
||||
@ -97,7 +97,7 @@ import MVMCore
|
||||
return MVMCoreUIUtility.validateInternationalMDNString(MDN)
|
||||
}
|
||||
|
||||
@objc public func validateAndColor() -> 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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user