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