DigitEntry in decent place.
This commit is contained in:
parent
b9850bed81
commit
c38e3c0712
@ -17,14 +17,10 @@ import UIKit
|
||||
//--------------------------------------------------
|
||||
|
||||
private(set) var numberOfDigits = 4
|
||||
private var switchedAutomatically = false
|
||||
public var switchFieldsAutomatically = false
|
||||
|
||||
public var digitFields: [DigitBox] = []
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Property Observers
|
||||
//--------------------------------------------------
|
||||
@ -133,12 +129,10 @@ import UIKit
|
||||
|
||||
alignCenterHorizontal()
|
||||
isAccessibilityElement = false
|
||||
entryContainer.hideBorder = true
|
||||
entryContainer.hideBorders = true
|
||||
entryContainer.bottomBar.backgroundColor = UIColor.clear.cgColor
|
||||
entryContainer.bottomBar.frame = CGRect(x: 0, y: entryContainer.bounds.height, width: 0, height: 0)
|
||||
assembleDigitFieldsView(size: MVMCoreUISplitViewController.getDetailViewWidth())
|
||||
|
||||
textField.removeFromSuperview()
|
||||
}
|
||||
|
||||
private func createDigitField() -> DigitBox {
|
||||
@ -155,7 +149,11 @@ import UIKit
|
||||
var accessibleElements: [Any] = [titleLabel]
|
||||
|
||||
if numberOfDigits > 0 {
|
||||
let digitFields = [DigitBox](repeating: createDigitField(), count: numberOfDigits)
|
||||
var digitFields = [DigitBox]()
|
||||
for _ in 0..<numberOfDigits {
|
||||
digitFields.append(createDigitField())
|
||||
}
|
||||
|
||||
self.digitFields = digitFields
|
||||
guard let space = MFSizeObject(standardSize: 5, smalliPhoneSize: 3)?.getValueBasedOnScreenSize() else { return }
|
||||
|
||||
@ -164,7 +162,7 @@ import UIKit
|
||||
for (index, box) in digitFields.enumerated() {
|
||||
accessibleElements.append(box)
|
||||
entryContainer.addSubview(box)
|
||||
|
||||
|
||||
box.topAnchor.constraint(equalTo: entryContainer.topAnchor).isActive = true
|
||||
entryContainer.bottomAnchor.constraint(equalTo: box.bottomAnchor).isActive = true
|
||||
|
||||
@ -195,6 +193,8 @@ import UIKit
|
||||
open override func updateView(_ size: CGFloat) {
|
||||
super.updateView(size)
|
||||
|
||||
entryContainer.hideBorders = true
|
||||
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
guard let self = self else { return }
|
||||
|
||||
@ -210,7 +210,7 @@ import UIKit
|
||||
// MARK: - Methods
|
||||
//--------------------------------------------------
|
||||
|
||||
func setAsSecureTextEntry(_ secureEntry: Bool) {
|
||||
public func setAsSecureTextEntry(_ secureEntry: Bool) {
|
||||
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
guard let self = self else { return }
|
||||
@ -233,58 +233,54 @@ import UIKit
|
||||
}
|
||||
}
|
||||
|
||||
public func selectPreviousTextField(_ currentTextField: UITextField?, clear: Bool) {
|
||||
public func selectPreviousDigitField(_ currentTextField: UITextField?, clear: Bool) {
|
||||
|
||||
var selectNextField = false
|
||||
|
||||
for field in digitFields {
|
||||
|
||||
if field == currentTextField {
|
||||
if field.digitField == currentTextField {
|
||||
selectNextField = true
|
||||
field.isSelected = false
|
||||
|
||||
} else if selectNextField {
|
||||
if !clear {
|
||||
switchedAutomatically = true
|
||||
switchFieldsAutomatically = true
|
||||
}
|
||||
field.becomeFirstResponder()
|
||||
switchedAutomatically = false
|
||||
field.digitField.becomeFirstResponder()
|
||||
field.isSelected = true
|
||||
switchFieldsAutomatically = false
|
||||
|
||||
UIAccessibility.post(notification: .layoutChanged, argument: field)
|
||||
UIAccessibility.post(notification: .layoutChanged, argument: field.digitField)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func selectNextTextField(_ currentTextField: UITextField?, clear: Bool) {
|
||||
public func selectNextDigitField(_ currentTextField: UITextField?, clear: Bool) {
|
||||
|
||||
var selectNextField = false
|
||||
|
||||
for field in digitFields {
|
||||
if field == currentTextField {
|
||||
if field.digitField == currentTextField {
|
||||
selectNextField = true
|
||||
field.isSelected = false
|
||||
|
||||
} else if selectNextField {
|
||||
if !clear {
|
||||
switchedAutomatically = true
|
||||
switchFieldsAutomatically = true
|
||||
}
|
||||
field.isSelected = true
|
||||
field.becomeFirstResponder()
|
||||
switchedAutomatically = false
|
||||
switchFieldsAutomatically = false
|
||||
|
||||
UIAccessibility.post(notification: .layoutChanged, argument: field)
|
||||
UIAccessibility.post(notification: .layoutChanged, argument: field.digitField)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class func getEnabledTextfields(_ textFieldToDetermine: [TextEntryField]?) -> [AnyHashable]? {
|
||||
open class func getEnabledDigitFields(_ textFieldToDetermine: [TextEntryField]) -> [AnyHashable]? {
|
||||
|
||||
var enabledTextFields = [AnyHashable]()
|
||||
|
||||
for textfield in textFieldToDetermine ?? [] {
|
||||
if textfield.isEnabled {
|
||||
enabledTextFields.append(textfield)
|
||||
}
|
||||
}
|
||||
|
||||
return enabledTextFields
|
||||
return textFieldToDetermine.filter { $0.isEnabled }
|
||||
}
|
||||
}
|
||||
|
||||
@ -316,12 +312,12 @@ extension DigitEntryField {
|
||||
|
||||
// One character, switch old value with new, select next textfield
|
||||
textField.text = string
|
||||
selectNextTextField(textField, clear: false)
|
||||
selectNextDigitField(textField, clear: false)
|
||||
valueChanged()
|
||||
return false
|
||||
|
||||
} else if replacementLength == 0 && oldLength == 1 {
|
||||
// non empty cell, clear and stay.
|
||||
// Non empty cell, clear and stay.
|
||||
textField.text = ""
|
||||
valueChanged()
|
||||
return false
|
||||
@ -336,12 +332,12 @@ extension DigitEntryField {
|
||||
func textFieldDidDelete(_ textField: UITextField?) {
|
||||
|
||||
// Empty cell, go back to previous cell and clear.
|
||||
selectPreviousTextField(textField, clear: true)
|
||||
selectPreviousDigitField(textField, clear: true)
|
||||
}
|
||||
|
||||
@objc public func textFieldDidBeginEditing(_ textField: UITextField) {
|
||||
|
||||
if !switchedAutomatically {
|
||||
if !switchFieldsAutomatically {
|
||||
textField.text = ""
|
||||
valueChanged()
|
||||
}
|
||||
@ -356,7 +352,7 @@ extension DigitEntryField {
|
||||
|
||||
@objc public func textFieldShouldClear(_ textField: UITextField) -> Bool {
|
||||
|
||||
selectPreviousTextField(textField, clear: false)
|
||||
selectPreviousDigitField(textField, clear: false)
|
||||
|
||||
return uiTextFieldDelegate?.textFieldShouldClear?(textField) ?? true
|
||||
}
|
||||
@ -374,7 +370,7 @@ extension DigitEntryField {
|
||||
|
||||
// MARK: - Molecular
|
||||
extension DigitEntryField {
|
||||
|
||||
|
||||
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
||||
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
||||
|
||||
@ -385,16 +381,16 @@ extension DigitEntryField {
|
||||
numberOfDigits = digits
|
||||
}
|
||||
|
||||
assembleDigitFieldsView(size: MVMCoreUIUtility.getWidth())
|
||||
|
||||
if !dictionary.isEmpty{
|
||||
for digitBox in digitFields {
|
||||
MVMCoreUICommonViewsUtility.addDismissToolbar(digitBox.digitField, delegate: delegateObject as? UITextFieldDelegate)
|
||||
}
|
||||
}
|
||||
|
||||
assembleDigitFieldsView(size: MVMCoreUIUtility.getWidth())
|
||||
}
|
||||
|
||||
open override class func estimatedHeight(forRow json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
||||
return 44
|
||||
return 115
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ import UIKit
|
||||
}()
|
||||
|
||||
/// Determines if a border should be drawn.
|
||||
public var hideBorder = false
|
||||
public var hideBorders = false
|
||||
|
||||
public var borderStrokeColor: UIColor = .mfSilver()
|
||||
private var borderPath: UIBezierPath = UIBezierPath()
|
||||
@ -35,13 +35,17 @@ import UIKit
|
||||
|
||||
public var showError = false {
|
||||
didSet {
|
||||
showError ? errorUI() : originalUI()
|
||||
if !hideBorders {
|
||||
showError ? errorUI() : originalUI()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public var isEnabled = true {
|
||||
didSet {
|
||||
isEnabled ? originalUI() : disabledUI()
|
||||
if !hideBorders {
|
||||
isEnabled ? originalUI() : disabledUI()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,7 +57,9 @@ import UIKit
|
||||
|
||||
public var isSelected = false {
|
||||
didSet {
|
||||
isSelected ? selectedUI() : originalUI()
|
||||
if !hideBorders {
|
||||
isSelected ? selectedUI() : originalUI()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,7 +92,7 @@ import UIKit
|
||||
|
||||
borderPath.removeAllPoints()
|
||||
|
||||
if !hideBorder {
|
||||
if !hideBorders {
|
||||
// Brings the other half of the line inside the view to prevent cropping.
|
||||
let origin = bounds.origin
|
||||
let size = frame.size
|
||||
@ -117,7 +123,7 @@ import UIKit
|
||||
open func originalUI() {
|
||||
|
||||
isUserInteractionEnabled = true
|
||||
hideBorder = false
|
||||
hideBorders = false
|
||||
borderStrokeColor = .mfSilver()
|
||||
bottomBar.backgroundColor = UIColor.black.cgColor
|
||||
refreshUI(bottomBarSize: 1)
|
||||
@ -126,7 +132,7 @@ import UIKit
|
||||
open func errorUI() {
|
||||
|
||||
isUserInteractionEnabled = true
|
||||
hideBorder = false
|
||||
hideBorders = false
|
||||
borderStrokeColor = .mfPumpkin()
|
||||
bottomBar.backgroundColor = UIColor.mfPumpkin().cgColor
|
||||
refreshUI(bottomBarSize: 4)
|
||||
@ -135,7 +141,7 @@ import UIKit
|
||||
open func selectedUI() {
|
||||
|
||||
isUserInteractionEnabled = true
|
||||
hideBorder = false
|
||||
hideBorders = false
|
||||
borderStrokeColor = .black
|
||||
bottomBar.backgroundColor = UIColor.black.cgColor
|
||||
refreshUI(bottomBarSize: 1)
|
||||
@ -144,7 +150,7 @@ import UIKit
|
||||
open func lockedUI() {
|
||||
|
||||
isUserInteractionEnabled = false
|
||||
hideBorder = true
|
||||
hideBorders = true
|
||||
borderStrokeColor = .clear
|
||||
bottomBar.backgroundColor = UIColor.clear.cgColor
|
||||
refreshUI(bottomBarSize: 1)
|
||||
@ -154,19 +160,20 @@ import UIKit
|
||||
|
||||
isUserInteractionEnabled = false
|
||||
borderStrokeColor = .mfSilver()
|
||||
hideBorder = false
|
||||
bottomBar.backgroundColor = UIColor.mfSilver().cgColor
|
||||
refreshUI(bottomBarSize: 1)
|
||||
}
|
||||
|
||||
open func refreshUI(bottomBarSize: CGFloat? = nil) {
|
||||
|
||||
let size: CGFloat = bottomBarSize ?? (showError ? 4 : 1)
|
||||
bottomBar.frame = CGRect(x: 0, y: bounds.height - size, width: bounds.width, height: size)
|
||||
|
||||
delegateObject?.moleculeDelegate?.moleculeLayoutUpdated?(self)
|
||||
setNeedsDisplay()
|
||||
layoutIfNeeded()
|
||||
if !hideBorders {
|
||||
let size: CGFloat = bottomBarSize ?? (showError ? 4 : 1)
|
||||
bottomBar.frame = CGRect(x: 0, y: bounds.height - size, width: bounds.width, height: size)
|
||||
|
||||
delegateObject?.moleculeDelegate?.moleculeLayoutUpdated?(self)
|
||||
setNeedsDisplay()
|
||||
layoutIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
@ -179,8 +186,8 @@ import UIKit
|
||||
|
||||
guard let dictionary = json, !dictionary.isEmpty else { return }
|
||||
|
||||
if let hideBorder = dictionary["hideBorder"] as? Bool {
|
||||
self.hideBorder = hideBorder
|
||||
if let hideBorders = dictionary["hideBorders"] as? Bool {
|
||||
self.hideBorders = hideBorders
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user