generally functioning. some loose ends with TextField.

This commit is contained in:
Kevin G Christiano 2019-10-16 13:51:55 -04:00
parent d0cb4a987e
commit 19310bff89
5 changed files with 68 additions and 65 deletions

View File

@ -12,7 +12,7 @@ import UIKit
@objc optional func textFieldDidDelete(_ textField: UITextField?)
}
class DigitTextBox: UITextField, MVMCoreViewProtocol {
@objcMembers open class DigitTextBox: UITextField, MVMCoreViewProtocol {
//--------------------------------------------------
// MARK: - Outlets
//--------------------------------------------------
@ -38,7 +38,7 @@ class DigitTextBox: UITextField, MVMCoreViewProtocol {
// MARK: - Initializers
//--------------------------------------------------
required init?(coder: NSCoder) {
required public init?(coder: NSCoder) {
super.init(coder: coder)
fatalError("init(coder:) has not been implemented")
}
@ -58,33 +58,32 @@ class DigitTextBox: UITextField, MVMCoreViewProtocol {
func setup() {
if constraints.count == 0 {
translatesAutoresizingMaskIntoConstraints = false
backgroundColor = .white
textAlignment = .center
keyboardType = .numberPad
layer.borderWidth = 1
hideError()
widthConstraint = widthAnchor.constraint(equalToConstant: 40)
widthConstraint?.isActive = true
heightConstraint = heightAnchor.constraint(equalToConstant: 60)
heightConstraint?.isActive = true
bottomBar = SeparatorView.separatorAdd(to: self, position: SeparatorPositionBot)
bottomBar?.setAsMedium()
updateView(MVMCoreUISplitViewController.getDetailViewWidth())
}
guard constraints.isEmpty else { return }
translatesAutoresizingMaskIntoConstraints = false
backgroundColor = .white
textAlignment = .center
keyboardType = .numberPad
layer.borderWidth = 1
hideError()
widthConstraint = widthAnchor.constraint(equalToConstant: 40)
widthConstraint?.isActive = true
heightConstraint = heightAnchor.constraint(equalToConstant: 60)
heightConstraint?.isActive = true
bottomBar = SeparatorView.separatorAdd(to: self, position: SeparatorPositionBot)
bottomBar?.setAsMedium()
updateView(MVMCoreUISplitViewController.getDetailViewWidth())
}
//--------------------------------------------------
// MARK: - Methods
//--------------------------------------------------
override func deleteBackward() {
override open func deleteBackward() {
super.deleteBackward()
if let delegate = mfTextBoxDelegate {
@ -92,7 +91,7 @@ class DigitTextBox: UITextField, MVMCoreViewProtocol {
}
}
func updateView(_ size: CGFloat) {
public func updateView(_ size: CGFloat) {
DispatchQueue.main.async {
if !MVMCoreGetterUtility.fequal(a: Float(size), b: Float(self.previousSize)) {

View File

@ -8,7 +8,7 @@
import UIKit
class DigitTextField: TextField, UITextFieldDelegate, MFDigitTextBoxDelegate {
@objcMembers open class DigitTextField: TextField, UITextFieldDelegate, MFDigitTextBoxDelegate {
//--------------------------------------------------
// MARK: - Outlets
//--------------------------------------------------

View File

@ -12,7 +12,7 @@ import UIKit
import MVMCore
@objcMembers class MdnTextField: TextField, UITextFieldDelegate, ABPeoplePickerNavigationControllerDelegate, CNContactPickerDelegate {
@objcMembers open class MdnTextField: TextField, UITextFieldDelegate, ABPeoplePickerNavigationControllerDelegate, CNContactPickerDelegate {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
@ -25,9 +25,9 @@ import MVMCore
// MARK: - Initializers
//--------------------------------------------------
public override init(frame: CGRect) {
open override init(frame: CGRect) {
super.init(frame: .zero)
setup()
setup()
}
public convenience init() {
@ -42,14 +42,14 @@ import MVMCore
//--------------------------------------------------
// MARK: - Setup
//--------------------------------------------------
private func setup() {
textField?.delegate = self
customDelegate = uiTextFieldDelegate
isNationalMdn = true
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(_:)))
@ -72,13 +72,13 @@ import MVMCore
}
}
}
//--------------------------------------------------
// MARK: - Methods
//--------------------------------------------------
func hasValidMdn() -> Bool {
guard let mdn = getMdn() else { return true }
if mdn.isEmpty {
@ -92,7 +92,7 @@ import MVMCore
}
func validateAndColor() -> Bool {
if !shouldValidateMDN {
let isValid = hasValidMdn()
@ -108,24 +108,24 @@ import MVMCore
return true
}
func getErrorMessage() -> String? {
return nil
}
func getMdn() -> String? {
return MVMCoreUIUtility.removeMdnFormat(text! as String)
}
func setMdn(_ mdn: String?) {
guard let MDN = mdn else { return }
text = MVMCoreUIUtility.formatMdn(MDN)
}
@objc func dismissFieldInput(_ sender: Any?) {
if let delegate = uiTextFieldDelegate {
@ -134,7 +134,7 @@ import MVMCore
textField?.resignFirstResponder()
}
}
func getContacts(_ sender: Any?) {
let picker = CNContactPickerViewController()
@ -144,19 +144,19 @@ import MVMCore
picker.predicateForSelectionOfProperty = NSPredicate(format: "key == 'phoneNumbers'")
MVMCoreNavigationHandler.shared()?.present(picker, animated: true)
}
//--------------------------------------------------
// MARK: - ContactPicker Delegate
//--------------------------------------------------
func contactPicker(_ picker: CNContactPickerViewController, didSelect contactProperty: CNContactProperty) {
if contactProperty.value != nil && (contactProperty.value is CNPhoneNumber) {
let phoneNumber = contactProperty.value as? CNPhoneNumber
let MDN = phoneNumber?.stringValue
var unformattedMDN = MVMCoreUIUtility.removeMdnFormat(MDN)
// Sometimes user add extra 1 in front of mdn in their address book
if isNationalMdn,
let unformedMDN = unformattedMDN,
@ -165,7 +165,7 @@ import MVMCore
unformattedMDN = (unformedMDN as NSString).substring(from: 1)
}
text = unformattedMDN
if let textField = textField {
@ -174,7 +174,7 @@ import MVMCore
}
}
}
//--------------------------------------------------
// MARK: - ImplementedTextField Delegate
//--------------------------------------------------
@ -183,27 +183,27 @@ import MVMCore
@objc func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
if let customDelegate = customDelegate {
return customDelegate.textFieldShouldReturn?(textField) ?? false
}
return true
}
@objc func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
if !MVMCoreUIUtility.validate(string, withRegularExpression: RegularExpressionDigitOnly) {
return false
}
if let customDelegate = customDelegate {
return customDelegate.textField?(textField, shouldChangeCharactersIn: range, replacementString: string) ?? true
}
return true
}
func textFieldDidBeginEditing(_ textField: UITextField) {
textField.text = MVMCoreUIUtility.removeMdnFormat(textField.text)
@ -213,16 +213,16 @@ import MVMCore
func textFieldDidEndEditing(_ textField: UITextField) {
customDelegate?.textFieldDidEndEditing?(textField)
if validateAndColor() && isNationalMdn {
textField.text = MVMCoreUIUtility.formatMdn(textField.text)
}
}
//--------------------------------------------------
// MARK: - Passed Along TextField delegate
//--------------------------------------------------
@objc func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
if let customDelegate = customDelegate {
@ -231,7 +231,7 @@ import MVMCore
return true
}
@objc func textFieldShouldEndEditing(_ textField: UITextField) -> Bool {
if let customDelegate = customDelegate {
@ -240,7 +240,7 @@ import MVMCore
return true
}
@objc func textFieldShouldClear(_ textField: UITextField) -> Bool {
if let customDelegate = customDelegate {
@ -249,5 +249,4 @@ import MVMCore
return true
}
}

View File

@ -226,6 +226,7 @@ import UIKit
// MARK: - Lifecycle
//--------------------------------------------------
/// Initial configuration of class and view.
override open func setupView() {
guard subviews.isEmpty else { return }
@ -241,6 +242,8 @@ import UIKit
formLabel.textColor = UIColor.mfBattleshipGrey()
formLabel.setContentHuggingPriority(UILayoutPriority(251), for: .horizontal)
formLabel.setContentHuggingPriority(UILayoutPriority(251), for: .vertical)
formLabel.setContentCompressionResistancePriority(.required, for: .vertical)
formLabel.heightAnchor.constraint(greaterThanOrEqualToConstant: 0).isActive = true
addSubview(formLabel)
@ -282,6 +285,7 @@ import UIKit
layoutMarginsGuide.bottomAnchor.constraint(equalTo: placeholderErrorLabel.bottomAnchor).isActive = true
}
/// Configuration logic for the text container view.
private func constrainContent(_ parentView: UIView) {
let backgroundView = UIView(frame: .zero)
@ -299,7 +303,8 @@ import UIKit
let textField = UITextField(frame: .zero)
self.textField = textField
textField.translatesAutoresizingMaskIntoConstraints = false
textField.setContentHuggingPriority(.required, for: .vertical)
textField.setContentCompressionResistancePriority(.required, for: .vertical)
textField.heightAnchor.constraint(equalToConstant: 24).isActive = true
textField.font = MFStyler.fontForTextField()
textField.smartQuotesType = .no
textField.smartDashesType = .no
@ -311,7 +316,7 @@ import UIKit
NSLayoutConstraint.activate([
textField.topAnchor.constraint(equalTo: parentView.topAnchor, constant: 10),
textField.leadingAnchor.constraint(equalTo: parentView.leadingAnchor, constant: 16),
parentView.trailingAnchor.constraint(equalTo: textField.trailingAnchor, constant: 10)])
parentView.bottomAnchor.constraint(equalTo: textField.bottomAnchor, constant: 10)])
let dropDownCarrotLabel = Label()
self.dropDownCarrotLabel = dropDownCarrotLabel
@ -325,8 +330,8 @@ import UIKit
addSubview(dropDownCarrotLabel)
textField.topAnchor.constraint(equalTo: parentView.topAnchor, constant: 10).isActive = true
textField.leadingAnchor.constraint(equalTo: textField.leadingAnchor, constant: 6).isActive = true
dropDownCarrotLabel.topAnchor.constraint(equalTo: parentView.topAnchor).isActive = true
dropDownCarrotLabel.leadingAnchor.constraint(equalTo: textField.trailingAnchor, constant: 6).isActive = true
parentView.trailingAnchor.constraint(equalTo: dropDownCarrotLabel.trailingAnchor, constant: 16).isActive = true
parentView.bottomAnchor.constraint(equalTo: dropDownCarrotLabel.bottomAnchor).isActive = true
dropDownCarrotWidth = dropDownCarrotLabel.widthAnchor.constraint(equalToConstant: 0)
@ -346,6 +351,7 @@ import UIKit
parentView.bottomAnchor.constraint(equalTo: separatorView.bottomAnchor).isActive = true
let dashLine = DashLine()
dashLine.translatesAutoresizingMaskIntoConstraints = false
dashLine.backgroundColor = .white
dashLine.isHidden = true
@ -355,8 +361,7 @@ import UIKit
dashLine.centerYAnchor.constraint(equalTo: separatorView.centerYAnchor),
dashLine.centerXAnchor.constraint(equalTo: separatorView.centerXAnchor),
dashLine.topAnchor.constraint(equalTo: separatorView.topAnchor),
dashLine.leadingAnchor.constraint(equalTo: separatorView.leadingAnchor),
separatorView.bottomAnchor.constraint(equalTo: dashLine.bottomAnchor)])
dashLine.leadingAnchor.constraint(equalTo: separatorView.leadingAnchor)])
}
open override func updateView(_ size: CGFloat) {
@ -706,7 +711,7 @@ extension TextField {
setWithMap(json)
if let formValidationProtocol = delegateObject.formValidationProtocol {
mfTextFieldDelegate = FormValidator.getFormValidatorFor(delegate: formValidationProtocol) as? TextFieldDelegate
mfTextFieldDelegate = FormValidator.getFormValidatorFor(delegate: formValidationProtocol)
}
uiTextFieldDelegate = delegateObject.uiTextFieldDelegate

View File

@ -31,7 +31,6 @@ open class DashLine: MFView {
required public init?(coder: NSCoder) {
super.init(coder: coder)
fatalError("init(coder:) has not been implemented")
}
//------------------------------------------------------
@ -39,6 +38,7 @@ open class DashLine: MFView {
//------------------------------------------------------
@objc override open func updateView(_ size: CGFloat) {
DispatchQueue.main.async { [weak self] in
self?.setNeedsDisplay()
}