error image for secure entry state
This commit is contained in:
parent
5f539aa6b7
commit
ddc44a17ed
@ -8,6 +8,8 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
public typealias TextFieldAndPickerDelegate = (UITextFieldDelegate & UIPickerViewDelegate & UIPickerViewDataSource)
|
||||
|
||||
|
||||
open class ItemDropdownEntryField: BaseDropdownEntryField {
|
||||
//--------------------------------------------------
|
||||
|
||||
@ -90,9 +90,9 @@ import MVMCore
|
||||
|
||||
textField.keyboardType = .numberPad
|
||||
|
||||
let toolbar = UIToolbar.emptyToolbar()
|
||||
let toolbar = UIToolbar.createEmptyToolbar()
|
||||
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(dismissFieldInput))
|
||||
toolbar.items = [contacts, space, dismissButton]
|
||||
textField.inputAccessoryView = toolbar
|
||||
|
||||
@ -36,12 +36,6 @@ import UIKit
|
||||
return textField
|
||||
}()
|
||||
|
||||
private var standardAccessoryView: UIView?
|
||||
|
||||
public var accessoryView: UIView? {
|
||||
didSet { accessoryView == nil ? unconstrainAccessoryView() : constrainAccessoryView() }
|
||||
}
|
||||
|
||||
public lazy var errorImage: UIImageView = {
|
||||
let image = MVMCoreUIUtility.imageNamed("alert_standard")
|
||||
let imageView = UIImageView(image: image)
|
||||
@ -63,8 +57,6 @@ import UIKit
|
||||
/// Validate on each entry in the textField. Default: true
|
||||
public var validateEachCharacter: Bool = true
|
||||
|
||||
var usesAccessoryView: Bool = true
|
||||
|
||||
/// Validate when user resigns editing. Default: true
|
||||
public var validateWhenDoneEditing: Bool = true
|
||||
|
||||
@ -101,14 +93,7 @@ import UIKit
|
||||
}
|
||||
|
||||
if textField.isSecureTextEntry {
|
||||
if !error {
|
||||
accessoryView?.removeFromSuperview()
|
||||
accessoryView = nil
|
||||
accessoryView = standardAccessoryView
|
||||
} else {
|
||||
standardAccessoryView = accessoryView
|
||||
accessoryView = errorImage
|
||||
}
|
||||
showErrorView(error)
|
||||
}
|
||||
|
||||
super.showError = error
|
||||
@ -163,28 +148,6 @@ import UIKit
|
||||
//--------------------------------------------------
|
||||
|
||||
public var textFieldTrailingConstraint: NSLayoutConstraint?
|
||||
public var accessoryViewTrailingConstraint: NSLayoutConstraint?
|
||||
|
||||
public func constrainAccessoryView() {
|
||||
|
||||
guard let accessoryView = accessoryView else { return }
|
||||
|
||||
entryFieldContainer.addSubview(accessoryView)
|
||||
|
||||
textFieldTrailingConstraint?.isActive = false
|
||||
textFieldTrailingConstraint = accessoryView.leadingAnchor.constraint(equalTo: textField.trailingAnchor, constant: Padding.Two)
|
||||
textFieldTrailingConstraint?.isActive = true
|
||||
|
||||
accessoryViewTrailingConstraint = entryFieldContainer.trailingAnchor.constraint(equalTo: accessoryView.trailingAnchor, constant: Padding.Four)
|
||||
accessoryViewTrailingConstraint?.isActive = true
|
||||
accessoryView.centerYAnchor.constraint(equalTo: entryFieldContainer.centerYAnchor).isActive = true
|
||||
}
|
||||
|
||||
public func unconstrainAccessoryView() {
|
||||
|
||||
textFieldTrailingConstraint = entryFieldContainer.trailingAnchor.constraint(equalTo: textField.trailingAnchor, constant: Padding.Four)
|
||||
textFieldTrailingConstraint?.isActive = true
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
@ -248,10 +211,6 @@ import UIKit
|
||||
textField.font = Styler.Font.RegularBodyLarge.getFont()
|
||||
}
|
||||
|
||||
@objc deinit {
|
||||
setBothTextDelegates(to: nil)
|
||||
}
|
||||
|
||||
@objc public func setBothTextDelegates(to delegate: (UITextFieldDelegate & ObservingTextFieldDelegate)?) {
|
||||
observingTextFieldDelegate = delegate
|
||||
uiTextFieldDelegate = delegate
|
||||
@ -260,7 +219,7 @@ import UIKit
|
||||
//--------------------------------------------------
|
||||
// MARK: - Observing for Change (TextFieldDelegate)
|
||||
//--------------------------------------------------
|
||||
|
||||
|
||||
@discardableResult
|
||||
@objc override open func resignFirstResponder() -> Bool {
|
||||
if validateWhenDoneEditing {
|
||||
@ -316,6 +275,25 @@ import UIKit
|
||||
resignFirstResponder()
|
||||
}
|
||||
|
||||
private func showErrorView(_ show: Bool) {
|
||||
|
||||
if show {
|
||||
entryFieldContainer.addSubview(errorImage)
|
||||
|
||||
textFieldTrailingConstraint?.isActive = false
|
||||
textFieldTrailingConstraint = errorImage.leadingAnchor.constraint(equalTo: textField.trailingAnchor, constant: Padding.Two)
|
||||
textFieldTrailingConstraint?.isActive = true
|
||||
|
||||
entryFieldContainer.trailingAnchor.constraint(equalTo: errorImage.trailingAnchor, constant: Padding.Four).isActive = true
|
||||
errorImage.centerYAnchor.constraint(equalTo: entryFieldContainer.centerYAnchor).isActive = true
|
||||
|
||||
} else {
|
||||
errorImage.removeFromSuperview()
|
||||
textFieldTrailingConstraint = entryFieldContainer.trailingAnchor.constraint(equalTo: textField.trailingAnchor, constant: Padding.Four)
|
||||
textFieldTrailingConstraint?.isActive = true
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - MoleculeViewProtocol
|
||||
//--------------------------------------------------
|
||||
|
||||
@ -9,7 +9,6 @@
|
||||
import Foundation
|
||||
|
||||
|
||||
|
||||
public extension UIPickerView {
|
||||
|
||||
class func createPickerView() -> UIPickerView {
|
||||
@ -20,7 +19,7 @@ public extension UIPickerView {
|
||||
return picker
|
||||
}
|
||||
|
||||
class func addPicker(to textField: UITextField, delegate: (UITextFieldDelegate & UIPickerViewDelegate & UIPickerViewDataSource)?, dismissAction: Selector?) -> UIPickerView {
|
||||
class func addPicker(to textField: UITextField, delegate: TextFieldAndPickerDelegate?, dismissAction: Selector?) -> UIPickerView {
|
||||
|
||||
// Sets up the picker (same tag as the textfield)
|
||||
let picker = createPickerView()
|
||||
|
||||
@ -16,7 +16,7 @@ extension UITextField: TextFieldOrView { }
|
||||
|
||||
public extension UIToolbar {
|
||||
|
||||
class func emptyToolbar() -> UIToolbar {
|
||||
class func createEmptyToolbar() -> UIToolbar {
|
||||
|
||||
let toolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 44))
|
||||
toolbar.autoresizingMask = [.flexibleLeftMargin, .flexibleRightMargin, .flexibleWidth]
|
||||
@ -29,7 +29,7 @@ public extension UIToolbar {
|
||||
|
||||
class func getToolbarWithDoneButton(delegate: Any?, action: Selector) -> UIToolbar {
|
||||
|
||||
let toolbar = emptyToolbar()
|
||||
let toolbar = createEmptyToolbar()
|
||||
let space = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
|
||||
let button = UIBarButtonItem(barButtonSystemItem: .done, target: delegate, action: action)
|
||||
button.tintColor = .mvmBlack
|
||||
@ -38,12 +38,12 @@ public extension UIToolbar {
|
||||
return toolbar
|
||||
}
|
||||
|
||||
class func addDismissToolbar(to object: TextFieldOrView?, delegate: Any?, action: Selector) {
|
||||
class func addDismissToolbar(to object: TextFieldOrView, delegate: Any?, action: Selector) {
|
||||
|
||||
let toolbar = emptyToolbar()
|
||||
let toolbar = createEmptyToolbar()
|
||||
let space = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
|
||||
let dismissButton = UIBarButtonItem(barButtonSystemItem: .done, target: delegate, action: action)
|
||||
dismissButton.tintColor = UIColor.black
|
||||
dismissButton.tintColor = .mvmBlack
|
||||
toolbar.items = [space, dismissButton]
|
||||
|
||||
switch object {
|
||||
@ -52,6 +52,7 @@ public extension UIToolbar {
|
||||
|
||||
case is UITextView:
|
||||
(object as? UITextView)?.inputAccessoryView = toolbar
|
||||
|
||||
default:
|
||||
return
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user