Merge branch 'feature/selectable_field' into 'develop'
Adding behavior logic for selecting by server See merge request BPHV_MIPS/mvm_core_ui!405
This commit is contained in:
commit
1e3e4b8717
@ -24,7 +24,7 @@ import UIKit
|
||||
textField.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||
textField.setContentCompressionResistancePriority(.required, for: .horizontal)
|
||||
textField.textAlignment = .center
|
||||
textField.font = MFStyler.fontForTextField()
|
||||
textField.font = Styler.Font.RegularBodyLarge.getFont()
|
||||
textField.keyboardType = .numberPad
|
||||
return textField
|
||||
}()
|
||||
@ -48,11 +48,11 @@ import UIKit
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
guard let self = self else { return }
|
||||
|
||||
self.borderStrokeColor = error ? .mfPumpkin() : .mfSilver()
|
||||
self.borderStrokeColor = error ? .mvmOrange : .mvmCoolGray3
|
||||
|
||||
let barHeight: CGFloat = self.showError ? 4 : 1
|
||||
self.bottomBar?.frame = CGRect(x: 0, y: self.bounds.height - barHeight, width: self.bounds.width, height: barHeight)
|
||||
self.bottomBar?.backgroundColor = self.showError ? UIColor.mfPumpkin().cgColor : UIColor.black.cgColor
|
||||
self.bottomBar?.backgroundColor = self.showError ? UIColor.mvmOrange.cgColor : UIColor.mvmBlack.cgColor
|
||||
|
||||
self.setNeedsDisplay()
|
||||
self.layoutIfNeeded()
|
||||
@ -97,29 +97,24 @@ import UIKit
|
||||
|
||||
open override func setupView() {
|
||||
super.setupView()
|
||||
|
||||
guard constraints.isEmpty else { return }
|
||||
|
||||
translatesAutoresizingMaskIntoConstraints = false
|
||||
backgroundColor = .clear
|
||||
|
||||
|
||||
addSubview(digitField)
|
||||
digitField.delegate = self
|
||||
digitField.didDeleteDelegate = self
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
digitField.topAnchor.constraint(equalTo: topAnchor, constant: PaddingOne),
|
||||
digitField.leadingAnchor.constraint(equalTo: leadingAnchor, constant: PaddingOne),
|
||||
bottomAnchor.constraint(equalTo: digitField.bottomAnchor, constant: PaddingOne),
|
||||
trailingAnchor.constraint(equalTo: digitField.trailingAnchor, constant: PaddingOne),
|
||||
digitField.centerYAnchor.constraint(equalTo: centerYAnchor),
|
||||
digitField.centerXAnchor.constraint(equalTo: centerXAnchor)])
|
||||
|
||||
widthConstraint = widthAnchor.constraint(equalToConstant: DigitBox.size.width)
|
||||
widthConstraint?.isActive = true
|
||||
heightConstraint = heightAnchor.constraint(equalToConstant: DigitBox.size.height)
|
||||
heightConstraint?.isActive = true
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
digitField.topAnchor.constraint(equalTo: topAnchor, constant: Padding.Three),
|
||||
digitField.leadingAnchor.constraint(equalTo: leadingAnchor),
|
||||
bottomAnchor.constraint(equalTo: digitField.bottomAnchor, constant: Padding.Three),
|
||||
trailingAnchor.constraint(equalTo: digitField.trailingAnchor),
|
||||
digitField.centerYAnchor.constraint(equalTo: centerYAnchor)
|
||||
])
|
||||
|
||||
if let bottomBar = bottomBar {
|
||||
layer.addSublayer(bottomBar)
|
||||
}
|
||||
@ -146,7 +141,7 @@ import UIKit
|
||||
super.reset()
|
||||
|
||||
backgroundColor = .clear
|
||||
digitField.font = MFStyler.fontForTextField()
|
||||
digitField.font = Styler.Font.RegularBodyLarge.getFont()
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
@ -186,7 +181,7 @@ import UIKit
|
||||
sizeObject?.performBlockBase(onSize: size)
|
||||
widthConstraint?.constant = width
|
||||
heightConstraint?.constant = height
|
||||
digitField.font = MFFonts.mfFont55Rg(pointSize)
|
||||
digitField.font = MFFonts.mfFontDSRegular(pointSize)
|
||||
previousSize = size
|
||||
}
|
||||
|
||||
|
||||
@ -35,6 +35,7 @@ import UIKit
|
||||
digitBoxes.append(newDigitBox)
|
||||
}
|
||||
|
||||
self.digitBoxes.forEach { $0.removeFromSuperview() }
|
||||
self.digitBoxes = digitBoxes
|
||||
guard let space = MFSizeObject(standardSize: 5, smalliPhoneSize: 3)?.getValueBasedOnScreenSize() else { return }
|
||||
|
||||
@ -76,6 +77,10 @@ import UIKit
|
||||
public var digitBoxes: [DigitBox] = []
|
||||
private var selectedDigitBox: DigitBox?
|
||||
|
||||
public var digitEntryModel: DigitEntryFieldModel? {
|
||||
return model as? DigitEntryFieldModel
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Computed Properties
|
||||
//--------------------------------------------------
|
||||
@ -224,14 +229,24 @@ import UIKit
|
||||
//--------------------------------------------------
|
||||
|
||||
@objc open override func updateView(_ size: CGFloat) {
|
||||
super.updateView(size)
|
||||
|
||||
entryFieldContainer.disableAllBorders = true
|
||||
|
||||
if !self.digitBoxes.isEmpty {
|
||||
self.digitBoxes.forEach { $0.updateView(size) }
|
||||
}
|
||||
layoutIfNeeded()
|
||||
|
||||
super.updateView(size)
|
||||
}
|
||||
|
||||
public override func reset() {
|
||||
super.reset()
|
||||
|
||||
accessibilityElements = nil
|
||||
switchFieldsAutomatically = false
|
||||
selectedDigitBox = nil
|
||||
text = ""
|
||||
digitBoxes.forEach { $0.digitField.text = "" }
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
@ -326,7 +341,7 @@ import UIKit
|
||||
}
|
||||
|
||||
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||
|
||||
|
||||
guard let model = model as? DigitEntryFieldModel else { return }
|
||||
|
||||
numberOfDigits = model.digits
|
||||
@ -341,7 +356,7 @@ import UIKit
|
||||
$0.digitField.inputAccessoryView = UIToolbar.getToolbarWithDoneButton(delegate: observingDelegate,
|
||||
action: #selector(observingDelegate.dismissFieldInput))
|
||||
}
|
||||
|
||||
|
||||
super.set(with: model, delegateObject, additionalData)
|
||||
}
|
||||
|
||||
@ -378,12 +393,14 @@ extension DigitEntryField {
|
||||
|
||||
// One character, switch old value with new, select next textfield
|
||||
textField.text = string
|
||||
digitEntryModel?.text = text
|
||||
selectNextDigitField(textField, clear: false)
|
||||
return false
|
||||
|
||||
} else if replacementLength == 0 && oldLength == 1 {
|
||||
// Non empty cell, clear and stay.
|
||||
textField.text = ""
|
||||
digitEntryModel?.text = text
|
||||
return false
|
||||
}
|
||||
|
||||
@ -410,6 +427,7 @@ extension DigitEntryField {
|
||||
|
||||
if !switchFieldsAutomatically {
|
||||
textField.text = ""
|
||||
digitEntryModel?.text = text
|
||||
}
|
||||
|
||||
proprietorTextDelegate?.textFieldDidBeginEditing?(textField)
|
||||
|
||||
@ -60,6 +60,7 @@ import UIKit
|
||||
self.titleLabel.textColor = enabled ? .mvmBlack : .mvmCoolGray3
|
||||
self.feedbackLabel.textColor = enabled ? .mvmBlack : .mvmCoolGray3
|
||||
self.entryFieldContainer.isEnabled = enabled
|
||||
self.entryFieldModel?.enabled = enabled
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,6 +70,7 @@ import UIKit
|
||||
set (error) {
|
||||
self.feedback = error ? entryFieldModel?.errorMessage : entryFieldModel?.feedback
|
||||
self.entryFieldContainer.showError = error
|
||||
self.entryFieldModel?.showError = error
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,6 +79,7 @@ import UIKit
|
||||
get { return entryFieldContainer.isLocked }
|
||||
set (locked) {
|
||||
self.entryFieldContainer.isLocked = locked
|
||||
self.entryFieldModel?.locked = locked
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,6 +88,7 @@ import UIKit
|
||||
get { return entryFieldContainer.isSelected }
|
||||
set (selected) {
|
||||
self.entryFieldContainer.isSelected = selected
|
||||
self.entryFieldModel?.selected = selected
|
||||
}
|
||||
}
|
||||
|
||||
@ -257,11 +261,13 @@ import UIKit
|
||||
if let isLocked = model.locked {
|
||||
self.isLocked = isLocked
|
||||
|
||||
} else if let isSelected = model.selected {
|
||||
self.isSelected = isSelected
|
||||
} else if (model.selected ?? false) && !model.wasInitiallySelected {
|
||||
|
||||
model.wasInitiallySelected = true
|
||||
self.isSelected = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
||||
return 115
|
||||
}
|
||||
|
||||
@ -10,7 +10,6 @@ import Foundation
|
||||
|
||||
|
||||
@objcMembers public class EntryFieldModel: MoleculeModelProtocol, FormFieldProtocol, FormRuleWatcherFieldProtocol, EnableableModelProtocol {
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
@ -24,12 +23,14 @@ import Foundation
|
||||
public var feedback: String?
|
||||
public var errorMessage: String?
|
||||
public var enabled: Bool = true
|
||||
public var showError: Bool?
|
||||
public var locked: Bool?
|
||||
public var selected: Bool?
|
||||
public var text: String?
|
||||
public var fieldKey: String?
|
||||
public var groupName: String = FormValidator.defaultGroupName
|
||||
public var baseValue: AnyHashable?
|
||||
public var wasInitiallySelected: Bool = false
|
||||
|
||||
public var isValid: Bool? {
|
||||
didSet { updateUI?() }
|
||||
@ -51,6 +52,7 @@ import Foundation
|
||||
case errorMessage
|
||||
case locked
|
||||
case selected
|
||||
case showError
|
||||
case text
|
||||
case fieldKey
|
||||
case groupName
|
||||
@ -93,6 +95,7 @@ import Foundation
|
||||
text = try typeContainer.decodeIfPresent(String.self, forKey: .text)
|
||||
baseValue = text
|
||||
fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey)
|
||||
|
||||
if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) {
|
||||
self.groupName = groupName
|
||||
}
|
||||
@ -106,6 +109,7 @@ import Foundation
|
||||
try container.encodeIfPresent(feedback, forKey: .feedback)
|
||||
try container.encodeIfPresent(text, forKey: .text)
|
||||
try container.encodeIfPresent(locked, forKey: .locked)
|
||||
try container.encodeIfPresent(showError, forKey: .showError)
|
||||
try container.encodeIfPresent(selected, forKey: .selected)
|
||||
try container.encodeIfPresent(errorMessage, forKey: .errorMessage)
|
||||
try container.encode(enabled, forKey: .enabled)
|
||||
|
||||
@ -339,6 +339,10 @@ import UIKit
|
||||
uiTextFieldDelegate = delegateObject?.uiTextFieldDelegate
|
||||
observingTextFieldDelegate = delegateObject?.observingTextFieldDelegate
|
||||
setupTextFieldToolbar()
|
||||
|
||||
if isSelected {
|
||||
startEditing()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user