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