Latest revision.
This commit is contained in:
parent
a455511809
commit
c9b41c9bc1
@ -27,9 +27,9 @@ import UIKit
|
|||||||
public override var isEnabled: Bool {
|
public override var isEnabled: Bool {
|
||||||
didSet {
|
didSet {
|
||||||
if isEnabled {
|
if isEnabled {
|
||||||
descriptionLabel?.styleB2(true)
|
titleLabel.styleB2(true)
|
||||||
} else {
|
} else {
|
||||||
descriptionLabel?.textColor = UIColor.mfBattleshipGrey()
|
titleLabel.textColor = UIColor.mfBattleshipGrey()
|
||||||
}
|
}
|
||||||
|
|
||||||
for textField in digitFields ?? [] {
|
for textField in digitFields ?? [] {
|
||||||
@ -63,29 +63,29 @@ import UIKit
|
|||||||
NSAttributedString.Key.foregroundColor: UIColor.mfBattleshipGrey()])
|
NSAttributedString.Key.foregroundColor: UIColor.mfBattleshipGrey()])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// if feedback.text.length > 0 {
|
// if feedback.text.length > 0 {
|
||||||
// labelToTextFieldPin?.constant = 10
|
// labelToTextFieldPin?.constant = 10
|
||||||
// } else {
|
// } else {
|
||||||
// labelToTextFieldPin?.constant = 0
|
// labelToTextFieldPin?.constant = 0
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// adding missing accessibilityLabel value
|
// adding missing accessibilityLabel value
|
||||||
// if we have some value in accessibilityLabel,
|
// if we have some value in accessibilityLabel,
|
||||||
// then only can append regular and picker item
|
// then only can append regular and picker item
|
||||||
// textField.accessibilityLabel() = newValue ?? "" + (MVMCoreUIUtility.hardcodedString(withKey: "mfdigittextfield_regular"))
|
// textField.accessibilityLabel() = newValue ?? "" + (MVMCoreUIUtility.hardcodedString(withKey: "mfdigittextfield_regular"))
|
||||||
//
|
//
|
||||||
// super.showErrorMessage(errorMessage)
|
// super.showErrorMessage(errorMessage)
|
||||||
//
|
//
|
||||||
// if self.showErrorMessage {
|
// if self.showErrorMessage {
|
||||||
// self.labelToTextFieldPin?.constant = 10
|
// self.labelToTextFieldPin?.constant = 10
|
||||||
// }
|
// }
|
||||||
// for field in self.digitFields ?? [] {
|
// for field in self.digitFields ?? [] {
|
||||||
// field.setAsError()
|
// field.setAsError()
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override var text: String? {
|
public override var text: String? {
|
||||||
get {
|
get {
|
||||||
var string = ""
|
var string = ""
|
||||||
@ -107,13 +107,13 @@ import UIKit
|
|||||||
field.text = stringForIndex
|
field.text = stringForIndex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
valueChanged()
|
valueChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override var descriptionText: String? {
|
public override var title: String? {
|
||||||
get { return descriptionLabel?.text }
|
get { return titleLabel.text }
|
||||||
set {
|
set {
|
||||||
if let formText = newValue, !formText.isEmpty {
|
if let formText = newValue, !formText.isEmpty {
|
||||||
messageToTextFieldPin?.constant = 10
|
messageToTextFieldPin?.constant = 10
|
||||||
@ -121,7 +121,7 @@ import UIKit
|
|||||||
messageToTextFieldPin?.constant = 0
|
messageToTextFieldPin?.constant = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
super.descriptionText = newValue
|
super.title = newValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,8 +190,8 @@ import UIKit
|
|||||||
|
|
||||||
open func setup() {
|
open func setup() {
|
||||||
|
|
||||||
descriptionLabel?.styleB2(true)
|
titleLabel.styleB2(true)
|
||||||
descriptionText = ""
|
title = ""
|
||||||
alignCenterHorizontal()
|
alignCenterHorizontal()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,7 +201,7 @@ 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.descriptionLabel?.updateView(size)
|
self.titleLabel.updateView(size)
|
||||||
|
|
||||||
if let digitFields = self.digitFields, !digitFields.isEmpty {
|
if let digitFields = self.digitFields, !digitFields.isEmpty {
|
||||||
|
|
||||||
@ -262,7 +262,7 @@ import UIKit
|
|||||||
|
|
||||||
if let feedback = self.feedback, !feedback.isEmpty {
|
if let feedback = self.feedback, !feedback.isEmpty {
|
||||||
self.labelToTextFieldPin?.constant = 10
|
self.labelToTextFieldPin?.constant = 10
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
self.labelToTextFieldPin?.constant = 0
|
self.labelToTextFieldPin?.constant = 0
|
||||||
}
|
}
|
||||||
@ -398,7 +398,7 @@ import UIKit
|
|||||||
}
|
}
|
||||||
field.becomeFirstResponder()
|
field.becomeFirstResponder()
|
||||||
self.switchedAutomatically = false
|
self.switchedAutomatically = false
|
||||||
|
|
||||||
UIAccessibility.post(notification: .layoutChanged, argument: field)
|
UIAccessibility.post(notification: .layoutChanged, argument: field)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -409,11 +409,11 @@ import UIKit
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
open override class func accessibilityElements() -> [Any]? {
|
open override class func accessibilityElements() -> [Any]? {
|
||||||
// self.digit
|
// self.digit
|
||||||
// if let digitFields = self.digitFields {
|
// if let digitFields = self.digitFields {
|
||||||
// return [digitFields] + [textField]
|
// return [digitFields] + [textField]
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
return [textField]
|
return [textField]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -475,7 +475,7 @@ import UIKit
|
|||||||
textField.text = ""
|
textField.text = ""
|
||||||
valueChanged()
|
valueChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
uiTextFieldDelegate?.textFieldDidBeginEditing?(textField)
|
uiTextFieldDelegate?.textFieldDidBeginEditing?(textField)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,7 +487,7 @@ import UIKit
|
|||||||
@objc public func textFieldShouldClear(_ textField: UITextField) -> Bool {
|
@objc public func textFieldShouldClear(_ textField: UITextField) -> Bool {
|
||||||
|
|
||||||
selectPreviousTextField(textField, clear: false)
|
selectPreviousTextField(textField, clear: false)
|
||||||
|
|
||||||
return uiTextFieldDelegate?.textFieldShouldClear?(textField) ?? true
|
return uiTextFieldDelegate?.textFieldShouldClear?(textField) ?? true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -68,9 +68,7 @@ import UIKit
|
|||||||
|
|
||||||
setupView()
|
setupView()
|
||||||
|
|
||||||
if let textField = textField {
|
MVMCoreUICommonViewsUtility.addDismissToolbar(textField, delegate: bothDelegates)
|
||||||
MVMCoreUICommonViewsUtility.addDismissToolbar(textField, delegate: bothDelegates)
|
|
||||||
}
|
|
||||||
|
|
||||||
setBothTextDelegates(bothDelegates)
|
setBothTextDelegates(bothDelegates)
|
||||||
}
|
}
|
||||||
@ -81,7 +79,6 @@ import UIKit
|
|||||||
|
|
||||||
open override func setupFieldContainerContent(_ container: UIView) {
|
open override func setupFieldContainerContent(_ container: UIView) {
|
||||||
|
|
||||||
guard let textField = textField else { return }
|
|
||||||
|
|
||||||
let dropDownCaretLabel = Label()
|
let dropDownCaretLabel = Label()
|
||||||
self.dropDownCaretLabel = dropDownCaretLabel
|
self.dropDownCaretLabel = dropDownCaretLabel
|
||||||
@ -144,8 +141,6 @@ extension DropdownEntryField {
|
|||||||
|
|
||||||
private func createDatePicker() {
|
private func createDatePicker() {
|
||||||
|
|
||||||
guard let textField = textField else { return }
|
|
||||||
|
|
||||||
MVMCoreUICommonViewsUtility.addDismissToolbar(textField, delegate: textField.delegate)
|
MVMCoreUICommonViewsUtility.addDismissToolbar(textField, delegate: textField.delegate)
|
||||||
datePicker = MVMCoreUICommonViewsUtility.addDatePicker(to: textField)
|
datePicker = MVMCoreUICommonViewsUtility.addDatePicker(to: textField)
|
||||||
|
|
||||||
@ -197,7 +192,7 @@ extension DropdownEntryField {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
textField?.resignFirstResponder()
|
textField.resignFirstResponder()
|
||||||
return pickedDate
|
return pickedDate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -223,8 +218,6 @@ extension DropdownEntryField {
|
|||||||
|
|
||||||
open override func setAccessibilityString(_ accessibilityString: String?) {
|
open override func setAccessibilityString(_ accessibilityString: String?) {
|
||||||
|
|
||||||
guard let textField = textField else { return }
|
|
||||||
|
|
||||||
var accessibilityString = accessibilityString ?? ""
|
var accessibilityString = accessibilityString ?? ""
|
||||||
|
|
||||||
if dropDownIsDisplayed, let txtPickerItem = MVMCoreUIUtility.hardcodedString(withKey: "textfield_picker_item") {
|
if dropDownIsDisplayed, let txtPickerItem = MVMCoreUIUtility.hardcodedString(withKey: "textfield_picker_item") {
|
||||||
|
|||||||
@ -17,11 +17,31 @@ import UIKit
|
|||||||
// MARK: - Outlets
|
// MARK: - Outlets
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
private(set) var descriptionLabel: Label?
|
private(set) var titleLabel: Label = {
|
||||||
private(set) var feedbackLabel: Label?
|
let label = Label()
|
||||||
private(set) var fieldContainer: UIView?
|
label.font = MFStyler.fontB3()
|
||||||
|
label.textColor = UIColor.mfBattleshipGrey()
|
||||||
|
label.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
|
label.setContentCompressionResistancePriority(.required, for: .horizontal)
|
||||||
|
return label
|
||||||
|
}()
|
||||||
|
|
||||||
private var borderStrokeColor: UIColor = UIColor.mfSilver()
|
private(set) var feedbackLabel: Label = {
|
||||||
|
let label = Label()
|
||||||
|
label.font = MFStyler.fontForTextFieldUnderLabel()
|
||||||
|
label.textColor = .black
|
||||||
|
label.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
|
label.setContentCompressionResistancePriority(.required, for: .horizontal)
|
||||||
|
return label
|
||||||
|
}()
|
||||||
|
|
||||||
|
private(set) var fieldContainer: UIView = {
|
||||||
|
let view = UIView(frame: .zero)
|
||||||
|
view.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
return view
|
||||||
|
}()
|
||||||
|
|
||||||
|
private var borderStrokeColor: UIColor = .mfSilver()
|
||||||
private var borderPath: UIBezierPath = UIBezierPath()
|
private var borderPath: UIBezierPath = UIBezierPath()
|
||||||
|
|
||||||
public var bottomBar: CAShapeLayer = {
|
public var bottomBar: CAShapeLayer = {
|
||||||
@ -44,7 +64,12 @@ import UIKit
|
|||||||
|
|
||||||
/// Determines if a border should be drawn.
|
/// Determines if a border should be drawn.
|
||||||
public var hideBorder = false
|
public var hideBorder = false
|
||||||
public var showErrorMessage = false
|
|
||||||
|
public var showErrorMessage = false {
|
||||||
|
didSet {
|
||||||
|
feedbackHeightConstraint?.isActive = !showErrorMessage
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public var errorMessage: String?
|
public var errorMessage: String?
|
||||||
|
|
||||||
@ -54,15 +79,15 @@ 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.isEnabled ? self.originalAppearance() : self.errorAppearance()
|
self.isEnabled ? self.originalAppearance() : self.disabledAppearance()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public var descriptionText: String? {
|
public var title: String? {
|
||||||
get { return descriptionLabel?.text }
|
get { return titleLabel.text }
|
||||||
set {
|
set {
|
||||||
descriptionLabel?.text = newValue
|
titleLabel.text = newValue
|
||||||
setAccessibilityString(newValue)
|
setAccessibilityString(newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -70,16 +95,16 @@ import UIKit
|
|||||||
/// Override this to conveniently get/set the textfield(s).
|
/// Override this to conveniently get/set the textfield(s).
|
||||||
public var text: String? {
|
public var text: String? {
|
||||||
get { return nil }
|
get { return nil }
|
||||||
set { fatalError("You need to override FormEntryField's 'text' variable in the subclass.") }
|
set { fatalError("You need to override FormEntryField's 'text' variable in your subclass.") }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets feedback text in the textField.
|
/// Sets feedback text in the textField.
|
||||||
public var feedback: String? {
|
public var feedback: String? {
|
||||||
get { return feedbackLabel?.text }
|
get { return feedbackLabel.text }
|
||||||
set {
|
set {
|
||||||
self.feedbackLabel?.text = newValue
|
feedbackLabel.text = newValue
|
||||||
self.refreshUI()
|
|
||||||
setAccessibilityString(newValue)
|
setAccessibilityString(newValue)
|
||||||
|
refreshUI()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,9 +129,10 @@ import UIKit
|
|||||||
|
|
||||||
public var feedbackLabelTrailing: NSLayoutConstraint?
|
public var feedbackLabelTrailing: NSLayoutConstraint?
|
||||||
public var feedbackLabelLeading: NSLayoutConstraint?
|
public var feedbackLabelLeading: NSLayoutConstraint?
|
||||||
|
var feedbackHeightConstraint: NSLayoutConstraint?
|
||||||
|
|
||||||
public var descriptionLabelLeading: NSLayoutConstraint?
|
public var titleLabelLeading: NSLayoutConstraint?
|
||||||
public var descriptionLabelTrailing: NSLayoutConstraint?
|
public var titleLabelTrailing: NSLayoutConstraint?
|
||||||
|
|
||||||
public var bottomBarHeightConstraint: NSLayoutConstraint?
|
public var bottomBarHeightConstraint: NSLayoutConstraint?
|
||||||
|
|
||||||
@ -117,15 +143,19 @@ import UIKit
|
|||||||
/// This must be overriden by a subclass.
|
/// This must be overriden by a subclass.
|
||||||
public override init(frame: CGRect) {
|
public override init(frame: CGRect) {
|
||||||
super.init(frame: frame)
|
super.init(frame: frame)
|
||||||
|
|
||||||
setupView()
|
setupView()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This must be overriden by a subclass.
|
|
||||||
public convenience init() {
|
public convenience init() {
|
||||||
self.init(frame: .zero)
|
self.init(frame: .zero)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public init(title: String) {
|
||||||
|
super.init(frame: .zero)
|
||||||
|
setupView()
|
||||||
|
self.titleLabel.text = title
|
||||||
|
}
|
||||||
|
|
||||||
required public init?(coder: NSCoder) {
|
required public init?(coder: NSCoder) {
|
||||||
super.init(coder: coder)
|
super.init(coder: coder)
|
||||||
fatalError("FormEntryField does not support xib.")
|
fatalError("FormEntryField does not support xib.")
|
||||||
@ -139,49 +169,31 @@ import UIKit
|
|||||||
final public override func setupView() {
|
final public override func setupView() {
|
||||||
|
|
||||||
guard subviews.isEmpty else { return }
|
guard subviews.isEmpty else { return }
|
||||||
// heightAnchor.constraint(greaterThanOrEqualToConstant: 0).isActive = true
|
|
||||||
translatesAutoresizingMaskIntoConstraints = false
|
translatesAutoresizingMaskIntoConstraints = false
|
||||||
setContentCompressionResistancePriority(.required, for: .vertical)
|
setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
backgroundColor = .clear
|
backgroundColor = .clear
|
||||||
|
|
||||||
let descriptionLabel = Label()
|
addSubview(titleLabel)
|
||||||
self.descriptionLabel = descriptionLabel
|
|
||||||
descriptionLabel.font = MFStyler.fontB3()
|
|
||||||
descriptionLabel.textColor = UIColor.mfBattleshipGrey()
|
|
||||||
descriptionLabel.setContentCompressionResistancePriority(.required, for: .vertical)
|
|
||||||
descriptionLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
|
|
||||||
|
|
||||||
addSubview(descriptionLabel)
|
titleLabel.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor).isActive = true
|
||||||
|
titleLabelLeading = titleLabel.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor)
|
||||||
descriptionLabel.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor).isActive = true
|
titleLabelLeading?.isActive = true
|
||||||
descriptionLabelLeading = descriptionLabel.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor)
|
titleLabelTrailing = layoutMarginsGuide.trailingAnchor.constraint(equalTo: titleLabel.trailingAnchor)
|
||||||
descriptionLabelLeading?.isActive = true
|
titleLabelLeading?.isActive = true
|
||||||
descriptionLabelTrailing = layoutMarginsGuide.trailingAnchor.constraint(equalTo: descriptionLabel.trailingAnchor)
|
|
||||||
descriptionLabelLeading?.isActive = true
|
|
||||||
|
|
||||||
let fieldContainer = UIView(frame: .zero)
|
|
||||||
self.fieldContainer = fieldContainer
|
|
||||||
fieldContainer.translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
|
|
||||||
addSubview(fieldContainer)
|
addSubview(fieldContainer)
|
||||||
setupFieldContainer(fieldContainer)
|
setupFieldContainerContent(fieldContainer)
|
||||||
|
|
||||||
fieldContainer.topAnchor.constraint(equalTo: descriptionLabel.bottomAnchor, constant: 4).isActive = true
|
fieldContainer.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 4).isActive = true
|
||||||
fieldContainerLeading = fieldContainer.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor)
|
fieldContainerLeading = fieldContainer.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor)
|
||||||
fieldContainerLeading?.isActive = true
|
fieldContainerLeading?.isActive = true
|
||||||
fieldContainerTrailing = layoutMarginsGuide.trailingAnchor.constraint(equalTo: fieldContainer.trailingAnchor)
|
fieldContainerTrailing = layoutMarginsGuide.trailingAnchor.constraint(equalTo: fieldContainer.trailingAnchor)
|
||||||
fieldContainerTrailing?.isActive = true
|
fieldContainerTrailing?.isActive = true
|
||||||
|
|
||||||
let feedbackLabel = Label()
|
|
||||||
self.feedbackLabel = feedbackLabel
|
|
||||||
feedbackLabel.font = MFStyler.fontForTextFieldUnderLabel()
|
|
||||||
feedbackLabel.textColor = .black
|
|
||||||
feedbackLabel.setContentCompressionResistancePriority(.required, for: .vertical)
|
|
||||||
feedbackLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
|
|
||||||
|
|
||||||
addSubview(feedbackLabel)
|
addSubview(feedbackLabel)
|
||||||
|
|
||||||
feedbackLabel.heightAnchor.constraint(greaterThanOrEqualToConstant: 0).isActive = true
|
feedbackHeightConstraint = feedbackLabel.heightAnchor.constraint(equalToConstant: 0)
|
||||||
feedbackLabel.topAnchor.constraint(equalTo: fieldContainer.bottomAnchor, constant: PaddingOne).isActive = true
|
feedbackLabel.topAnchor.constraint(equalTo: fieldContainer.bottomAnchor, constant: PaddingOne).isActive = true
|
||||||
feedbackLabelLeading = feedbackLabel.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor)
|
feedbackLabelLeading = feedbackLabel.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor)
|
||||||
feedbackLabelLeading?.isActive = true
|
feedbackLabelLeading?.isActive = true
|
||||||
@ -197,32 +209,47 @@ import UIKit
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Method to override.
|
Method to override.
|
||||||
Intended to add the interactive content (textField) to the fieldContainer.
|
Intended to add the interactive content (i.e. textField) to the fieldContainer.
|
||||||
*/
|
*/
|
||||||
open func setupFieldContainerContent(_ container: UIView) {
|
open func setupFieldContainerContent(_ container: UIView) {
|
||||||
// To Be Overridden By Subclass.
|
// To be overridden by subclass.
|
||||||
}
|
|
||||||
|
|
||||||
/// Configuration for the field container view.
|
|
||||||
private func setupFieldContainer(_ parentView: UIView) {
|
|
||||||
setupFieldContainerContent(parentView)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func updateView(_ size: CGFloat) {
|
open override func updateView(_ size: CGFloat) {
|
||||||
super.updateView(size)
|
super.updateView(size)
|
||||||
|
|
||||||
descriptionLabel?.updateView(size)
|
titleLabel.updateView(size)
|
||||||
feedbackLabel?.font = MFStyler.fontForTextFieldUnderLabel()
|
feedbackLabel.font = MFStyler.fontForTextFieldUnderLabel()
|
||||||
|
|
||||||
refreshUI()
|
refreshUI()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open override func reset() {
|
||||||
|
super.reset()
|
||||||
|
|
||||||
|
backgroundColor = .clear
|
||||||
|
titleLabel.reset()
|
||||||
|
feedbackLabel.reset()
|
||||||
|
fieldContainer.subviews.forEach { $0.removeFromSuperview() }
|
||||||
|
originalAppearance()
|
||||||
|
}
|
||||||
|
|
||||||
open override func layoutSubviews() {
|
open override func layoutSubviews() {
|
||||||
super.layoutSubviews()
|
super.layoutSubviews()
|
||||||
|
|
||||||
refreshUI(bottomBarSize: 1)
|
refreshUI(bottomBarSize: 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open func refreshUI(bottomBarSize: CGFloat? = nil) {
|
||||||
|
|
||||||
|
if let size = bottomBarSize {
|
||||||
|
bottomBar.frame = CGRect(x: 0, y: fieldContainer.bounds.height - size, width: fieldContainer.bounds.width, height: size)
|
||||||
|
}
|
||||||
|
|
||||||
|
self.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated?(self)
|
||||||
|
setNeedsDisplay()
|
||||||
|
layoutIfNeeded()
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Drawing
|
// MARK: - Drawing
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -232,16 +259,18 @@ import UIKit
|
|||||||
|
|
||||||
borderPath.removeAllPoints()
|
borderPath.removeAllPoints()
|
||||||
|
|
||||||
if !hideBorder, let frame = fieldContainer?.frame {
|
if !hideBorder {
|
||||||
|
|
||||||
// Brings the other half of the line inside the view to prevent thinness from cropping.
|
// Brings the other half of the line inside the view to prevent thinness from cropping.
|
||||||
|
let origin = fieldContainer.frame.origin
|
||||||
|
let size = fieldContainer.frame.size
|
||||||
let insetLean: CGFloat = 0.5
|
let insetLean: CGFloat = 0.5
|
||||||
borderPath.lineWidth = 1
|
borderPath.lineWidth = 1
|
||||||
|
|
||||||
borderPath.move(to: CGPoint(x: frame.origin.x + insetLean, y: frame.origin.y + frame.size.height))
|
borderPath.move(to: CGPoint(x: origin.x + insetLean, y: origin.y + size.height))
|
||||||
borderPath.addLine(to: CGPoint(x: frame.origin.x + insetLean, y: frame.origin.y + insetLean))
|
borderPath.addLine(to: CGPoint(x: origin.x + insetLean, y: origin.y + insetLean))
|
||||||
borderPath.addLine(to: CGPoint(x: frame.origin.x + frame.size.width - insetLean, y: frame.origin.y + insetLean))
|
borderPath.addLine(to: CGPoint(x: origin.x + size.width - insetLean, y: origin.y + insetLean))
|
||||||
borderPath.addLine(to: CGPoint(x: frame.origin.x + frame.size.width - insetLean, y: frame.origin.y + frame.size.height))
|
borderPath.addLine(to: CGPoint(x: origin.x + size.width - insetLean, y: origin.y + size.height))
|
||||||
|
|
||||||
borderStrokeColor.setStroke()
|
borderStrokeColor.setStroke()
|
||||||
borderPath.stroke()
|
borderPath.stroke()
|
||||||
@ -252,9 +281,7 @@ import UIKit
|
|||||||
|
|
||||||
func resizeBottomBar(size: CGFloat) {
|
func resizeBottomBar(size: CGFloat) {
|
||||||
|
|
||||||
if let fieldBounds = fieldContainer?.bounds {
|
bottomBar.frame = CGRect(x: 0, y: fieldContainer.bounds.height - size, width: fieldContainer.bounds.width, height: size)
|
||||||
bottomBar.frame = CGRect(x: 0, y: fieldBounds.height - size, width: fieldBounds.width, height: size)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -265,18 +292,18 @@ import UIKit
|
|||||||
|
|
||||||
fieldContainerLeading?.constant = constant
|
fieldContainerLeading?.constant = constant
|
||||||
feedbackLabelLeading?.constant = constant
|
feedbackLabelLeading?.constant = constant
|
||||||
descriptionLabelLeading?.constant = constant
|
titleLabelLeading?.constant = constant
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func setRightPinConstant(_ constant: CGFloat) {
|
open override func setRightPinConstant(_ constant: CGFloat) {
|
||||||
|
|
||||||
fieldContainerTrailing?.constant = constant
|
fieldContainerTrailing?.constant = constant
|
||||||
feedbackLabelTrailing?.constant = constant
|
feedbackLabelTrailing?.constant = constant
|
||||||
descriptionLabelTrailing?.constant = constant
|
titleLabelTrailing?.constant = constant
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Form Appearance
|
// MARK: - Form UI Base Appearance
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
public enum Appearance: String {
|
public enum Appearance: String {
|
||||||
@ -295,11 +322,11 @@ import UIKit
|
|||||||
showErrorMessage = false
|
showErrorMessage = false
|
||||||
borderStrokeColor = .mfSilver()
|
borderStrokeColor = .mfSilver()
|
||||||
bottomBar.backgroundColor = UIColor.black.cgColor
|
bottomBar.backgroundColor = UIColor.black.cgColor
|
||||||
descriptionLabel?.textColor = .mfBattleshipGrey()
|
titleLabel.textColor = .mfBattleshipGrey()
|
||||||
|
|
||||||
refreshUI(bottomBarSize: 1)
|
refreshUI(bottomBarSize: 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// - parameter showError: Default = false. Determines if error message should be displayed when setting the visual error appearance.
|
||||||
open func errorAppearance(showError: Bool = false) {
|
open func errorAppearance(showError: Bool = false) {
|
||||||
|
|
||||||
isUserInteractionEnabled = true
|
isUserInteractionEnabled = true
|
||||||
@ -322,7 +349,6 @@ import UIKit
|
|||||||
bottomBarHeightConstraint?.constant = 1
|
bottomBarHeightConstraint?.constant = 1
|
||||||
hideBorder = true
|
hideBorder = true
|
||||||
bottomBar.backgroundColor = UIColor.clear.cgColor
|
bottomBar.backgroundColor = UIColor.clear.cgColor
|
||||||
|
|
||||||
refreshUI(bottomBarSize: 1)
|
refreshUI(bottomBarSize: 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,7 +359,6 @@ import UIKit
|
|||||||
hideBorder = false
|
hideBorder = false
|
||||||
borderStrokeColor = .black
|
borderStrokeColor = .black
|
||||||
bottomBar.backgroundColor = UIColor.black.cgColor
|
bottomBar.backgroundColor = UIColor.black.cgColor
|
||||||
|
|
||||||
refreshUI(bottomBarSize: 1)
|
refreshUI(bottomBarSize: 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -343,22 +368,10 @@ import UIKit
|
|||||||
bottomBarHeightConstraint?.constant = 1
|
bottomBarHeightConstraint?.constant = 1
|
||||||
hideBorder = false
|
hideBorder = false
|
||||||
feedback = nil
|
feedback = nil
|
||||||
descriptionLabel?.textColor = self.isEnabled ? UIColor.mfBattleshipGrey() : UIColor.mfSilver()
|
titleLabel.textColor = self.isEnabled ? UIColor.mfBattleshipGrey() : UIColor.mfSilver()
|
||||||
bottomBar.backgroundColor = self.isEnabled ? (self.showErrorMessage ? UIColor.mfPumpkin().cgColor : UIColor.black.cgColor) : UIColor.mfSilver().cgColor
|
bottomBar.backgroundColor = self.isEnabled ? UIColor.black.cgColor : UIColor.mfSilver().cgColor
|
||||||
|
|
||||||
refreshUI(bottomBarSize: 1)
|
refreshUI(bottomBarSize: 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
open func refreshUI(bottomBarSize: CGFloat? = nil) {
|
|
||||||
|
|
||||||
if let size = bottomBarSize, let fieldBounds = fieldContainer?.bounds {
|
|
||||||
bottomBar.frame = CGRect(x: 0, y: fieldBounds.height - size, width: fieldBounds.width, height: size)
|
|
||||||
}
|
|
||||||
|
|
||||||
self.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated?(self)
|
|
||||||
setNeedsDisplay()
|
|
||||||
layoutIfNeeded()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Molecular
|
// MARK: - Molecular
|
||||||
@ -373,7 +386,7 @@ extension FormEntryField {
|
|||||||
else { return }
|
else { return }
|
||||||
|
|
||||||
if let formText = dictionary[KeyLabel] as? String {
|
if let formText = dictionary[KeyLabel] as? String {
|
||||||
descriptionText = formText
|
title = formText
|
||||||
}
|
}
|
||||||
|
|
||||||
if let text = dictionary[KeyDisable] as? String, text.isEqual(StringY) || dictionary.boolForKey(KeyDisable) {
|
if let text = dictionary[KeyDisable] as? String, text.isEqual(StringY) || dictionary.boolForKey(KeyDisable) {
|
||||||
@ -389,7 +402,23 @@ extension FormEntryField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let appearance = dictionary["appearance"] as? String {
|
if let appearance = dictionary["appearance"] as? String {
|
||||||
// let enu = Appearance(rawValue: appearance)
|
switch Appearance(rawValue: appearance) {
|
||||||
|
case .error:
|
||||||
|
errorAppearance()
|
||||||
|
|
||||||
|
case .lock:
|
||||||
|
lockAppearance()
|
||||||
|
|
||||||
|
case .select:
|
||||||
|
selectedAppearance()
|
||||||
|
|
||||||
|
case .disabled:
|
||||||
|
// This is set by the isEnabled property observer.
|
||||||
|
isEnabled = false
|
||||||
|
|
||||||
|
default:
|
||||||
|
originalAppearance()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Key used to send text value to server
|
// Key used to send text value to server
|
||||||
|
|||||||
@ -48,15 +48,15 @@ import MVMCore
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
private func setup() {
|
private func setup() {
|
||||||
|
|
||||||
textField?.keyboardType = .numberPad
|
textField.keyboardType = .numberPad
|
||||||
|
|
||||||
let toolbar = MVMCoreUICommonViewsUtility.makeEmptyToolbar()
|
let toolbar = MVMCoreUICommonViewsUtility.makeEmptyToolbar()
|
||||||
let space = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
|
let space = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
|
||||||
let contacts = UIBarButtonItem(title: MVMCoreUIUtility.hardcodedString(withKey: "textfield_contacts_barbutton"), style: .plain, target: self, action: #selector(getContacts(_:)))
|
let contacts = UIBarButtonItem(title: MVMCoreUIUtility.hardcodedString(withKey: "textfield_contacts_barbutton"), style: .plain, target: self, action: #selector(getContacts(_:)))
|
||||||
let dismissButton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(dismissTextFieldResponder(_:)))
|
let dismissButton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(dismissTextFieldResponder(_:)))
|
||||||
toolbar.items = [contacts, space, dismissButton]
|
toolbar.items = [contacts, space, dismissButton]
|
||||||
textField?.inputAccessoryView = toolbar
|
textField.inputAccessoryView = toolbar
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -126,10 +126,8 @@ import MVMCore
|
|||||||
|
|
||||||
text = unformattedMDN
|
text = unformattedMDN
|
||||||
|
|
||||||
if let textField = textField {
|
textFieldShouldReturn(textField)
|
||||||
textFieldShouldReturn(textField)
|
textFieldDidEndEditing(textField)
|
||||||
textFieldDidEndEditing(textField)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -24,7 +24,16 @@ import UIKit
|
|||||||
// MARK: - Outlets
|
// MARK: - Outlets
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
private(set) var textField: UITextField?
|
private(set) var textField: UITextField = {
|
||||||
|
let textField = UITextField(frame: .zero)
|
||||||
|
textField.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
textField.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
|
textField.font = MFStyler.fontForTextField()
|
||||||
|
textField.smartQuotesType = .no
|
||||||
|
textField.smartDashesType = .no
|
||||||
|
textField.smartInsertDeleteType = .no
|
||||||
|
return textField
|
||||||
|
}()
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
@ -40,17 +49,17 @@ 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.textField?.isEnabled = self.isEnabled
|
self.textField.isEnabled = self.isEnabled
|
||||||
self.textField?.textColor = self.isEnabled ? self.enabledTextColor : self.enabledTextColor
|
self.textField.textColor = self.isEnabled ? self.enabledTextColor : self.enabledTextColor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The text of this textField.
|
// The text of this textField.
|
||||||
public override var text: String? {
|
public override var text: String? {
|
||||||
get { return textField?.text }
|
get { return textField.text }
|
||||||
set {
|
set {
|
||||||
textField?.text = newValue
|
textField.text = newValue
|
||||||
valueChanged()
|
valueChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -63,7 +72,7 @@ import UIKit
|
|||||||
|
|
||||||
public override var errorMessage: String? {
|
public override var errorMessage: String? {
|
||||||
didSet {
|
didSet {
|
||||||
textField?.accessibilityValue = String(format: MVMCoreUIUtility.hardcodedString(withKey: "textfield_error_message") ?? "", textField?.text ?? "", errorMessage ?? "")
|
textField.accessibilityValue = String(format: MVMCoreUIUtility.hardcodedString(withKey: "textfield_error_message") ?? "", textField.text ?? "", errorMessage ?? "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,8 +99,8 @@ import UIKit
|
|||||||
|
|
||||||
/// If you're using a MFViewController, you must set this to it
|
/// If you're using a MFViewController, you must set this to it
|
||||||
public weak var uiTextFieldDelegate: UITextFieldDelegate? {
|
public weak var uiTextFieldDelegate: UITextFieldDelegate? {
|
||||||
get { return textField?.delegate }
|
get { return textField.delegate }
|
||||||
set { textField?.delegate = newValue }
|
set { textField.delegate = newValue }
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -121,7 +130,7 @@ import UIKit
|
|||||||
/// - parameter bothDelegates: Sets both MF/UI Text Field Delegates.
|
/// - parameter bothDelegates: Sets both MF/UI Text Field Delegates.
|
||||||
public init(bothDelegates: (UITextFieldDelegate & TextFieldDelegate)?) {
|
public init(bothDelegates: (UITextFieldDelegate & TextFieldDelegate)?) {
|
||||||
super.init(frame: .zero)
|
super.init(frame: .zero)
|
||||||
|
|
||||||
setupView()
|
setupView()
|
||||||
setBothTextDelegates(bothDelegates)
|
setBothTextDelegates(bothDelegates)
|
||||||
}
|
}
|
||||||
@ -132,20 +141,12 @@ import UIKit
|
|||||||
|
|
||||||
open override func setupFieldContainerContent(_ container: UIView) {
|
open override func setupFieldContainerContent(_ container: UIView) {
|
||||||
|
|
||||||
let textField = UITextField(frame: .zero)
|
|
||||||
self.textField = textField
|
|
||||||
textField.translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
textField.setContentCompressionResistancePriority(.required, for: .vertical)
|
|
||||||
textField.heightAnchor.constraint(equalToConstant: 24).isActive = true
|
|
||||||
textField.font = MFStyler.fontForTextField()
|
|
||||||
textField.smartQuotesType = .no
|
|
||||||
textField.smartDashesType = .no
|
|
||||||
textField.smartInsertDeleteType = .no
|
|
||||||
MFStyler.styleTextField(textField)
|
MFStyler.styleTextField(textField)
|
||||||
|
|
||||||
container.addSubview(textField)
|
container.addSubview(textField)
|
||||||
|
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
|
textField.heightAnchor.constraint(equalToConstant: 24),
|
||||||
textField.topAnchor.constraint(equalTo: container.topAnchor, constant: 10),
|
textField.topAnchor.constraint(equalTo: container.topAnchor, constant: 10),
|
||||||
textField.leadingAnchor.constraint(equalTo: container.leadingAnchor, constant: 16),
|
textField.leadingAnchor.constraint(equalTo: container.leadingAnchor, constant: 16),
|
||||||
container.bottomAnchor.constraint(equalTo: textField.bottomAnchor, constant: 10)])
|
container.bottomAnchor.constraint(equalTo: textField.bottomAnchor, constant: 10)])
|
||||||
@ -157,9 +158,9 @@ import UIKit
|
|||||||
open override func updateView(_ size: CGFloat) {
|
open override func updateView(_ size: CGFloat) {
|
||||||
super.updateView(size)
|
super.updateView(size)
|
||||||
|
|
||||||
if let textField = textField {
|
|
||||||
MFStyler.styleTextField(textField)
|
MFStyler.styleTextField(textField)
|
||||||
}
|
|
||||||
|
|
||||||
layoutIfNeeded()
|
layoutIfNeeded()
|
||||||
}
|
}
|
||||||
@ -175,7 +176,7 @@ import UIKit
|
|||||||
open func clearError() {
|
open func clearError() {
|
||||||
|
|
||||||
feedback = nil
|
feedback = nil
|
||||||
textField?.accessibilityValue = nil
|
textField.accessibilityValue = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
public func setBothTextDelegates(_ delegate: (UITextFieldDelegate & TextFieldDelegate)?) {
|
public func setBothTextDelegates(_ delegate: (UITextFieldDelegate & TextFieldDelegate)?) {
|
||||||
@ -193,7 +194,7 @@ import UIKit
|
|||||||
|
|
||||||
@objc func dismissTextFieldResponder(_ sender: Any?) {
|
@objc func dismissTextFieldResponder(_ sender: Any?) {
|
||||||
|
|
||||||
textField?.resignFirstResponder()
|
textField.resignFirstResponder()
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -237,7 +238,7 @@ import UIKit
|
|||||||
|
|
||||||
@objc func startEditing() {
|
@objc func startEditing() {
|
||||||
|
|
||||||
textField?.becomeFirstResponder()
|
textField.becomeFirstResponder()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,13 +265,13 @@ extension TextEntryField {
|
|||||||
|
|
||||||
switch dictionary.stringForkey(KeyType) {
|
switch dictionary.stringForkey(KeyType) {
|
||||||
case "password":
|
case "password":
|
||||||
textField?.isSecureTextEntry = true
|
textField.isSecureTextEntry = true
|
||||||
|
|
||||||
case "number":
|
case "number":
|
||||||
textField?.keyboardType = .numberPad
|
textField.keyboardType = .numberPad
|
||||||
|
|
||||||
case "email":
|
case "email":
|
||||||
textField?.keyboardType = .emailAddress
|
textField.keyboardType = .emailAddress
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
@ -293,9 +294,7 @@ extension TextEntryField {
|
|||||||
|
|
||||||
uiTextFieldDelegate = delegateObject.uiTextFieldDelegate
|
uiTextFieldDelegate = delegateObject.uiTextFieldDelegate
|
||||||
|
|
||||||
if let textField = textField {
|
MVMCoreUICommonViewsUtility.addDismissToolbar(textField, delegate: uiTextFieldDelegate)
|
||||||
MVMCoreUICommonViewsUtility.addDismissToolbar(textField, delegate: uiTextFieldDelegate)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,8 +312,6 @@ extension TextEntryField {
|
|||||||
|
|
||||||
open override func setAccessibilityString(_ accessibilityString: String?) {
|
open override func setAccessibilityString(_ accessibilityString: String?) {
|
||||||
|
|
||||||
guard let textField = textField else { return }
|
|
||||||
|
|
||||||
var accessibilityString = accessibilityString ?? ""
|
var accessibilityString = accessibilityString ?? ""
|
||||||
|
|
||||||
if let txtRegular = MVMCoreUIUtility.hardcodedString(withKey: "textfield_regular") {
|
if let txtRegular = MVMCoreUIUtility.hardcodedString(withKey: "textfield_regular") {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user