wip.
This commit is contained in:
parent
9b581a6132
commit
1af47ab98d
@ -24,41 +24,44 @@ open class DateDropdownEntryField: DropdownEntryField {
|
|||||||
|
|
||||||
// TODO: Pull this out into Styler or some class akin to it.
|
// TODO: Pull this out into Styler or some class akin to it.
|
||||||
public var formatter: DateFormatter = {
|
public var formatter: DateFormatter = {
|
||||||
|
|
||||||
let formatter = DateFormatter()
|
let formatter = DateFormatter()
|
||||||
formatter.dateStyle = .medium
|
formatter.dateStyle = .medium
|
||||||
formatter.timeZone = NSTimeZone.system
|
formatter.timeZone = NSTimeZone.system
|
||||||
formatter.locale = .current
|
formatter.locale = .current
|
||||||
formatter.formatterBehavior = .default
|
formatter.formatterBehavior = .default
|
||||||
|
|
||||||
return formatter
|
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
|
// 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() {
|
public convenience init() {
|
||||||
self.init(frame: .zero)
|
self.init(frame: .zero)
|
||||||
|
|
||||||
|
setup()
|
||||||
}
|
}
|
||||||
|
|
||||||
public convenience init(startDate: Date, endDate: Date, showStartDate: Bool = true) {
|
public convenience init(startDate: Date, endDate: Date, showStartDate: Bool = true) {
|
||||||
self.init(frame: .zero)
|
self.init(frame: .zero)
|
||||||
|
|
||||||
|
setup()
|
||||||
setDatePickerDuration(from: startDate, to: endDate, showStartDate: showStartDate)
|
setDatePickerDuration(from: startDate, to: endDate, showStartDate: showStartDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
required public init?(coder: NSCoder) {
|
private func setup() {
|
||||||
super.init(coder: coder)
|
|
||||||
fatalError("DateDropdownEntryField does not support xib.")
|
datePicker = MVMCoreUICommonViewsUtility.addDatePicker(to: textField)
|
||||||
|
datePicker?.addTarget(self, action: #selector(valueChanged(_:)), for: .valueChanged)
|
||||||
|
datePicker?.timeZone = NSTimeZone.system
|
||||||
|
MVMCoreUICommonViewsUtility.addDismissToolbar(textField, delegate: self)
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -94,6 +97,26 @@ open class DateDropdownEntryField: DropdownEntryField {
|
|||||||
text = formatter.string(from: date)
|
text = formatter.string(from: date)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc override func dismissFieldInput(_ sender: Any?) {
|
||||||
|
setTextWith(date: datePicker?.date)
|
||||||
|
super.dismissFieldInput(sender)
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func valueChanged(_ sender: UIDatePicker){
|
||||||
|
|
||||||
|
setTextWith(date: datePicker?.date)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - UITextField Intercept
|
||||||
|
extension DateDropdownEntryField {
|
||||||
|
|
||||||
|
public func textFieldDidBeginEditing(_ textField: UITextField) {
|
||||||
|
|
||||||
|
// setInitialValueFromPicker()
|
||||||
|
proprietorTextDelegate?.textFieldDidBeginEditing?(textField)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Molecular
|
// MARK: - Molecular
|
||||||
|
|||||||
@ -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.
|
/// 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
|
/// If you're using a MFViewController, you must set this to it
|
||||||
public override weak var uiTextFieldDelegate: UITextFieldDelegate? {
|
public override weak var uiTextFieldDelegate: UITextFieldDelegate? {
|
||||||
get { return textField.delegate }
|
get { return textField.delegate }
|
||||||
set {
|
set {
|
||||||
textField.delegate = self
|
textField.delegate = self
|
||||||
outsiderTextDelegate = newValue
|
proprietorTextDelegate = newValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ open class ItemDropdownEntryField: DropdownEntryField {
|
|||||||
// MARK: - Methods
|
// MARK: - Methods
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
public func setPickerDelegate(delegate: UIPickerViewDelegate & UIPickerViewDataSource) {
|
public func setPickerDelegates(delegate: UIPickerViewDelegate & UIPickerViewDataSource) {
|
||||||
|
|
||||||
pickerView?.delegate = delegate
|
pickerView?.delegate = delegate
|
||||||
pickerView?.dataSource = delegate
|
pickerView?.dataSource = delegate
|
||||||
@ -111,7 +111,7 @@ extension ItemDropdownEntryField {
|
|||||||
public func textFieldDidBeginEditing(_ textField: UITextField) {
|
public func textFieldDidBeginEditing(_ textField: UITextField) {
|
||||||
|
|
||||||
setInitialValueFromPicker()
|
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.
|
/// 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
|
// MARK: - Property Observers
|
||||||
@ -44,7 +44,7 @@ import MVMCore
|
|||||||
get { return textField.delegate }
|
get { return textField.delegate }
|
||||||
set {
|
set {
|
||||||
textField.delegate = self
|
textField.delegate = self
|
||||||
outsiderTextDelegate = newValue
|
proprietorTextDelegate = newValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ import MVMCore
|
|||||||
|
|
||||||
textField.resignFirstResponder()
|
textField.resignFirstResponder()
|
||||||
|
|
||||||
return outsiderTextDelegate?.textFieldShouldReturn?(textField) ?? true
|
return proprietorTextDelegate?.textFieldShouldReturn?(textField) ?? true
|
||||||
}
|
}
|
||||||
|
|
||||||
public func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
|
public func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
|
||||||
@ -176,18 +176,18 @@ import MVMCore
|
|||||||
return false
|
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) {
|
public func textFieldDidBeginEditing(_ textField: UITextField) {
|
||||||
|
|
||||||
textField.text = MVMCoreUIUtility.removeMdnFormat(textField.text)
|
textField.text = MVMCoreUIUtility.removeMdnFormat(textField.text)
|
||||||
outsiderTextDelegate?.textFieldDidBeginEditing?(textField)
|
proprietorTextDelegate?.textFieldDidBeginEditing?(textField)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func textFieldDidEndEditing(_ textField: UITextField) {
|
public func textFieldDidEndEditing(_ textField: UITextField) {
|
||||||
|
|
||||||
outsiderTextDelegate?.textFieldDidEndEditing?(textField)
|
proprietorTextDelegate?.textFieldDidEndEditing?(textField)
|
||||||
|
|
||||||
if validateAndColor() && isNationalMDN {
|
if validateAndColor() && isNationalMDN {
|
||||||
textField.text = MVMCoreUIUtility.formatMdn(textField.text)
|
textField.text = MVMCoreUIUtility.formatMdn(textField.text)
|
||||||
@ -200,16 +200,16 @@ import MVMCore
|
|||||||
|
|
||||||
public func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
|
public func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
|
||||||
|
|
||||||
return outsiderTextDelegate?.textFieldShouldBeginEditing?(textField) ?? true
|
return proprietorTextDelegate?.textFieldShouldBeginEditing?(textField) ?? true
|
||||||
}
|
}
|
||||||
|
|
||||||
public func textFieldShouldEndEditing(_ textField: UITextField) -> Bool {
|
public func textFieldShouldEndEditing(_ textField: UITextField) -> Bool {
|
||||||
|
|
||||||
return outsiderTextDelegate?.textFieldShouldEndEditing?(textField) ?? true
|
return proprietorTextDelegate?.textFieldShouldEndEditing?(textField) ?? true
|
||||||
}
|
}
|
||||||
|
|
||||||
public func textFieldShouldClear(_ textField: UITextField) -> Bool {
|
public func textFieldShouldClear(_ textField: UITextField) -> Bool {
|
||||||
|
|
||||||
return outsiderTextDelegate?.textFieldShouldClear?(textField) ?? true
|
return proprietorTextDelegate?.textFieldShouldClear?(textField) ?? true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user