Merge branch 'feature/swiftified_textField' of gitlab.verizon.com:BPHV_MIPS/mvm_core_ui into feature/swiftified_textField
This commit is contained in:
commit
b9850bed81
@ -24,41 +24,45 @@ open class DateDropdownEntryField: DropdownEntryField {
|
||||
|
||||
// TODO: Pull this out into Styler or some class akin to it.
|
||||
public var formatter: DateFormatter = {
|
||||
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateStyle = .medium
|
||||
formatter.timeZone = NSTimeZone.system
|
||||
formatter.locale = .current
|
||||
formatter.formatterBehavior = .default
|
||||
|
||||
return formatter
|
||||
}()
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Delegate
|
||||
//--------------------------------------------------
|
||||
|
||||
/// Holds a reference to the delegating class so this class can internally influence the TextField behavior as well.
|
||||
private weak var proprietorTextDelegate: UITextFieldDelegate?
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializer
|
||||
//--------------------------------------------------
|
||||
|
||||
public override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
|
||||
datePicker = MVMCoreUICommonViewsUtility.addDatePicker(to: textField)
|
||||
datePicker?.timeZone = NSTimeZone.system
|
||||
MVMCoreUICommonViewsUtility.addDismissToolbar(textField, delegate: textField.delegate)
|
||||
}
|
||||
|
||||
public convenience init() {
|
||||
self.init(frame: .zero)
|
||||
|
||||
setup()
|
||||
}
|
||||
|
||||
public convenience init(startDate: Date, endDate: Date, showStartDate: Bool = true) {
|
||||
self.init(frame: .zero)
|
||||
|
||||
setup()
|
||||
setDatePickerDuration(from: startDate, to: endDate, showStartDate: showStartDate)
|
||||
}
|
||||
|
||||
required public init?(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
fatalError("DateDropdownEntryField does not support xib.")
|
||||
private func setup() {
|
||||
|
||||
datePicker = MVMCoreUICommonViewsUtility.addDatePicker(to: textField)
|
||||
datePicker?.addTarget(self, action: #selector(pickerValueChanged), for: .valueChanged)
|
||||
datePicker?.timeZone = NSTimeZone.system
|
||||
MVMCoreUICommonViewsUtility.addDismissToolbar(textField, delegate: self)
|
||||
uiTextFieldDelegate = self
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
@ -94,6 +98,26 @@ open class DateDropdownEntryField: DropdownEntryField {
|
||||
text = formatter.string(from: date)
|
||||
}
|
||||
}
|
||||
|
||||
@objc override func dismissFieldInput(_ sender: Any?) {
|
||||
setTextWith(date: datePicker?.date)
|
||||
super.dismissFieldInput(sender)
|
||||
}
|
||||
|
||||
@objc func pickerValueChanged(_ sender: UIDatePicker){
|
||||
|
||||
setTextWith(date: datePicker?.date)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - UITextField Intercept
|
||||
extension DateDropdownEntryField {
|
||||
|
||||
public func textFieldDidBeginEditing(_ textField: UITextField) {
|
||||
|
||||
isSelected = true
|
||||
proprietorTextDelegate?.textFieldDidBeginEditing?(textField)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Molecular
|
||||
@ -103,7 +127,5 @@ extension DateDropdownEntryField {
|
||||
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
||||
|
||||
guard let dictionary = json, !dictionary.isEmpty else { return }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,14 +27,14 @@ open class ItemDropdownEntryField: DropdownEntryField {
|
||||
//--------------------------------------------------
|
||||
|
||||
/// Holds a reference to the delegating class so this class can internally influence the TextField behavior as well.
|
||||
private weak var outsiderTextDelegate: UITextFieldDelegate?
|
||||
private weak var proprietorTextDelegate: UITextFieldDelegate?
|
||||
|
||||
/// If you're using a MFViewController, you must set this to it
|
||||
public override weak var uiTextFieldDelegate: UITextFieldDelegate? {
|
||||
get { return textField.delegate }
|
||||
set {
|
||||
textField.delegate = self
|
||||
outsiderTextDelegate = newValue
|
||||
proprietorTextDelegate = newValue
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ extension ItemDropdownEntryField {
|
||||
public func textFieldDidBeginEditing(_ textField: UITextField) {
|
||||
|
||||
setInitialValueFromPicker()
|
||||
outsiderTextDelegate?.textFieldDidBeginEditing?(textField)
|
||||
proprietorTextDelegate?.textFieldDidBeginEditing?(textField)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -27,7 +27,7 @@ import MVMCore
|
||||
//--------------------------------------------------
|
||||
|
||||
/// Holds a reference to the delegating class so this class can internally influence the TextField behavior as well.
|
||||
private weak var outsiderTextDelegate: UITextFieldDelegate?
|
||||
private weak var proprietorTextDelegate: UITextFieldDelegate?
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Property Observers
|
||||
@ -44,7 +44,7 @@ import MVMCore
|
||||
get { return textField.delegate }
|
||||
set {
|
||||
textField.delegate = self
|
||||
outsiderTextDelegate = newValue
|
||||
proprietorTextDelegate = newValue
|
||||
}
|
||||
}
|
||||
|
||||
@ -167,7 +167,7 @@ import MVMCore
|
||||
|
||||
textField.resignFirstResponder()
|
||||
|
||||
return outsiderTextDelegate?.textFieldShouldReturn?(textField) ?? true
|
||||
return proprietorTextDelegate?.textFieldShouldReturn?(textField) ?? true
|
||||
}
|
||||
|
||||
public func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
|
||||
@ -176,18 +176,18 @@ import MVMCore
|
||||
return false
|
||||
}
|
||||
|
||||
return outsiderTextDelegate?.textField?(textField, shouldChangeCharactersIn: range, replacementString: string) ?? true
|
||||
return proprietorTextDelegate?.textField?(textField, shouldChangeCharactersIn: range, replacementString: string) ?? true
|
||||
}
|
||||
|
||||
public func textFieldDidBeginEditing(_ textField: UITextField) {
|
||||
|
||||
textField.text = MVMCoreUIUtility.removeMdnFormat(textField.text)
|
||||
outsiderTextDelegate?.textFieldDidBeginEditing?(textField)
|
||||
proprietorTextDelegate?.textFieldDidBeginEditing?(textField)
|
||||
}
|
||||
|
||||
public func textFieldDidEndEditing(_ textField: UITextField) {
|
||||
|
||||
outsiderTextDelegate?.textFieldDidEndEditing?(textField)
|
||||
proprietorTextDelegate?.textFieldDidEndEditing?(textField)
|
||||
|
||||
if validateAndColor() && isNationalMDN {
|
||||
textField.text = MVMCoreUIUtility.formatMdn(textField.text)
|
||||
@ -200,16 +200,16 @@ import MVMCore
|
||||
|
||||
public func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
|
||||
|
||||
return outsiderTextDelegate?.textFieldShouldBeginEditing?(textField) ?? true
|
||||
return proprietorTextDelegate?.textFieldShouldBeginEditing?(textField) ?? true
|
||||
}
|
||||
|
||||
public func textFieldShouldEndEditing(_ textField: UITextField) -> Bool {
|
||||
|
||||
return outsiderTextDelegate?.textFieldShouldEndEditing?(textField) ?? true
|
||||
return proprietorTextDelegate?.textFieldShouldEndEditing?(textField) ?? true
|
||||
}
|
||||
|
||||
public func textFieldShouldClear(_ textField: UITextField) -> Bool {
|
||||
|
||||
return outsiderTextDelegate?.textFieldShouldClear?(textField) ?? true
|
||||
return proprietorTextDelegate?.textFieldShouldClear?(textField) ?? true
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user