extending picker classes for more logical separation and modernization
This commit is contained in:
parent
3466be23c8
commit
5f539aa6b7
@ -104,6 +104,8 @@
|
||||
0A7EF86523D8AFFF00B2AAD1 /* ItemDropdownEntryFieldModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7EF86423D8AFFF00B2AAD1 /* ItemDropdownEntryFieldModel.swift */; };
|
||||
0A7EF86723D8B0AE00B2AAD1 /* DateDropdownEntryFieldModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7EF86623D8B0AE00B2AAD1 /* DateDropdownEntryFieldModel.swift */; };
|
||||
0AA33B3A2398524F0067DD0F /* Toggle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AA33B392398524F0067DD0F /* Toggle.swift */; };
|
||||
0AB764D124460F6300E7FE72 /* UIDatePicker+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AB764D024460F6300E7FE72 /* UIDatePicker+Extension.swift */; };
|
||||
0AB764D324460FA400E7FE72 /* UIPickerView+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AB764D224460FA400E7FE72 /* UIPickerView+Extension.swift */; };
|
||||
0ABD136D237CAD1E0081388D /* DateDropdownEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ABD136C237CAD1E0081388D /* DateDropdownEntryField.swift */; };
|
||||
0ABD1371237DB0450081388D /* ItemDropdownEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ABD1370237DB0450081388D /* ItemDropdownEntryField.swift */; };
|
||||
0AE14F64238315D2005417F8 /* TextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE14F63238315D2005417F8 /* TextField.swift */; };
|
||||
@ -532,6 +534,8 @@
|
||||
0A8321AE2355FE9500CB7F00 /* DigitBox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DigitBox.swift; sourceTree = "<group>"; };
|
||||
0AA33B33239813C50067DD0F /* UIColor+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Extension.swift"; sourceTree = "<group>"; };
|
||||
0AA33B392398524F0067DD0F /* Toggle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Toggle.swift; sourceTree = "<group>"; };
|
||||
0AB764D024460F6300E7FE72 /* UIDatePicker+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIDatePicker+Extension.swift"; sourceTree = "<group>"; };
|
||||
0AB764D224460FA400E7FE72 /* UIPickerView+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIPickerView+Extension.swift"; sourceTree = "<group>"; };
|
||||
0ABD136C237CAD1E0081388D /* DateDropdownEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateDropdownEntryField.swift; sourceTree = "<group>"; };
|
||||
0ABD1370237DB0450081388D /* ItemDropdownEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemDropdownEntryField.swift; sourceTree = "<group>"; };
|
||||
0AE14F63238315D2005417F8 /* TextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextField.swift; sourceTree = "<group>"; };
|
||||
@ -1119,6 +1123,8 @@
|
||||
D202AFE5242A6A9C00E5BEDF /* UICollectionViewScrollPosition+Extension.swift */,
|
||||
013F801823FB4A8E00AD8013 /* UIContentMode+Extension.swift */,
|
||||
0A7ECC6F2441001C00C828E8 /* UIToolbar+Extension.swift */,
|
||||
0AB764D024460F6300E7FE72 /* UIDatePicker+Extension.swift */,
|
||||
0AB764D224460FA400E7FE72 /* UIPickerView+Extension.swift */,
|
||||
);
|
||||
path = Extensions;
|
||||
sourceTree = "<group>";
|
||||
@ -2292,6 +2298,7 @@
|
||||
012A88DB238ED45900FE3DA1 /* CarouselModel.swift in Sources */,
|
||||
D29DF28C21E7AC2B003B2FB9 /* ViewConstrainingView.m in Sources */,
|
||||
0AE14F64238315D2005417F8 /* TextField.swift in Sources */,
|
||||
0AB764D124460F6300E7FE72 /* UIDatePicker+Extension.swift in Sources */,
|
||||
D29DF17B21E69E1F003B2FB9 /* PrimaryButton.m in Sources */,
|
||||
D2C78CD224228BBD00B69FDE /* ActionOpenPanelModel.swift in Sources */,
|
||||
C695A68123C9830D00BFB94E /* NumberedListModel.swift in Sources */,
|
||||
@ -2372,6 +2379,7 @@
|
||||
8D4687E2242E2DE400802879 /* ListFourColumnDataUsageListItemModel.swift in Sources */,
|
||||
D29E28DD23D7404C00ACEA85 /* ContainerHelper.swift in Sources */,
|
||||
012A88C2238D7BCA00FE3DA1 /* CarouselItemModel.swift in Sources */,
|
||||
0AB764D324460FA400E7FE72 /* UIPickerView+Extension.swift in Sources */,
|
||||
D29DF29E21E7AE3B003B2FB9 /* MFStyler.m in Sources */,
|
||||
94C661D923CCF4B400D9FE5B /* LeftRightLabelModel.swift in Sources */,
|
||||
011D95AB2405C553000E3791 /* FormItemProtocol.swift in Sources */,
|
||||
|
||||
@ -67,10 +67,10 @@ import UIKit
|
||||
public override func setupFieldContainerContent(_ container: UIView) {
|
||||
super.setupFieldContainerContent(container)
|
||||
|
||||
datePicker = MVMCoreUICommonViewsUtility.addDatePicker(to: textField)
|
||||
datePicker = UIDatePicker.addDatePicker(to: textField)
|
||||
datePicker?.addTarget(self, action: #selector(pickerValueChanged), for: .valueChanged)
|
||||
datePicker?.timeZone = NSTimeZone.system
|
||||
MVMCoreUICommonViewsUtility.addDismissToolbar(textField, delegate: self)
|
||||
UIToolbar.addDismissToolbar(to: textField, delegate: self, action: #selector(dismissFieldInput))
|
||||
}
|
||||
|
||||
@objc public func setDatePickerDuration(from startDate: Date?, to endDate: Date?, showStartDate: Bool = true) {
|
||||
|
||||
@ -331,7 +331,8 @@ import UIKit
|
||||
setAsSecureTextEntry(model.secureEntry)
|
||||
|
||||
for digitBox in digitBoxes {
|
||||
digitBox.digitField.inputAccessoryView = MVMCoreUICommonViewsUtility.getToolbarWithDoneButton(delegate: delegateObject?.observingTextFieldDelegate ?? self)
|
||||
digitBox.digitField.inputAccessoryView = UIToolbar.getToolbarWithDoneButton(delegate: delegateObject?.observingTextFieldDelegate ?? self,
|
||||
action: #selector(observingTextFieldDelegate?.dismissFieldInput))
|
||||
}
|
||||
|
||||
super.set(with: model, delegateObject, additionalData)
|
||||
|
||||
@ -62,7 +62,7 @@ open class ItemDropdownEntryField: BaseDropdownEntryField {
|
||||
@objc open override func setupFieldContainerContent(_ container: UIView) {
|
||||
super.setupFieldContainerContent(container)
|
||||
|
||||
pickerView = MVMCoreUICommonViewsUtility.addPicker(to: textField, delegate: self)
|
||||
pickerView = UIPickerView.addPicker(to: textField, delegate: self, dismissAction: #selector(dismissFieldInput))
|
||||
textField.hideBlinkingCaret = true
|
||||
textField.autocorrectionType = .no
|
||||
uiTextFieldDelegate = self
|
||||
|
||||
@ -90,7 +90,7 @@ import MVMCore
|
||||
|
||||
textField.keyboardType = .numberPad
|
||||
|
||||
let toolbar = MVMCoreUICommonViewsUtility.makeEmptyToolbar()
|
||||
let toolbar = UIToolbar.emptyToolbar()
|
||||
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(dismissFieldInput))
|
||||
|
||||
37
MVMCoreUI/Atomic/Extensions/UIDatePicker+Extension.swift
Normal file
37
MVMCoreUI/Atomic/Extensions/UIDatePicker+Extension.swift
Normal file
@ -0,0 +1,37 @@
|
||||
//
|
||||
// UIDatePicker+Extension.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Kevin Christiano on 4/14/20.
|
||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
public extension UIDatePicker {
|
||||
|
||||
class func addDatePicker(to textField: UITextField) -> UIDatePicker {
|
||||
|
||||
let datePicker = UIDatePicker()
|
||||
datePicker.backgroundColor = .mvmWhite
|
||||
datePicker.datePickerMode = .date
|
||||
|
||||
let locale = NSLocale.current as NSLocale
|
||||
datePicker.locale = locale as Locale
|
||||
datePicker.calendar = locale.object(forKey: .calendar) as? Calendar
|
||||
textField.inputView = datePicker
|
||||
|
||||
return datePicker
|
||||
}
|
||||
|
||||
class func addTimeAndDatePicker(to textField: UITextField) -> UIDatePicker {
|
||||
|
||||
let datePicker = UIDatePicker()
|
||||
datePicker.backgroundColor = .mvmWhite
|
||||
datePicker.datePickerMode = .time
|
||||
textField.inputView = datePicker
|
||||
|
||||
return datePicker
|
||||
}
|
||||
}
|
||||
39
MVMCoreUI/Atomic/Extensions/UIPickerView+Extension.swift
Normal file
39
MVMCoreUI/Atomic/Extensions/UIPickerView+Extension.swift
Normal file
@ -0,0 +1,39 @@
|
||||
//
|
||||
// UIPickerView.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Kevin Christiano on 4/14/20.
|
||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
|
||||
public extension UIPickerView {
|
||||
|
||||
class func createPickerView() -> UIPickerView {
|
||||
|
||||
let picker = UIPickerView(frame: .zero)
|
||||
picker.backgroundColor = .mvmWhite
|
||||
picker.showsSelectionIndicator = true
|
||||
return picker
|
||||
}
|
||||
|
||||
class func addPicker(to textField: UITextField, delegate: (UITextFieldDelegate & UIPickerViewDelegate & UIPickerViewDataSource)?, dismissAction: Selector?) -> UIPickerView {
|
||||
|
||||
// Sets up the picker (same tag as the textfield)
|
||||
let picker = createPickerView()
|
||||
picker.delegate = delegate
|
||||
picker.dataSource = delegate
|
||||
picker.tag = textField.tag
|
||||
textField.inputView = picker
|
||||
|
||||
// Adds a dismiss toolbar, since all fields with pickers should have one.
|
||||
if let dismissAction = dismissAction {
|
||||
UIToolbar.addDismissToolbar(to: textField, delegate: delegate, action: dismissAction)
|
||||
}
|
||||
|
||||
return picker
|
||||
}
|
||||
}
|
||||
@ -8,10 +8,15 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol TextFieldOrView { }
|
||||
|
||||
extension UITextView: TextFieldOrView { }
|
||||
extension UITextField: TextFieldOrView { }
|
||||
|
||||
|
||||
public extension UIToolbar {
|
||||
|
||||
class func makeEmptyToolbar() -> UIToolbar {
|
||||
class func emptyToolbar() -> UIToolbar {
|
||||
|
||||
let toolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 44))
|
||||
toolbar.autoresizingMask = [.flexibleLeftMargin, .flexibleRightMargin, .flexibleWidth]
|
||||
@ -24,7 +29,7 @@ public extension UIToolbar {
|
||||
|
||||
class func getToolbarWithDoneButton(delegate: Any?, action: Selector) -> UIToolbar {
|
||||
|
||||
let toolbar = makeEmptyToolbar()
|
||||
let toolbar = emptyToolbar()
|
||||
let space = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
|
||||
let button = UIBarButtonItem(barButtonSystemItem: .done, target: delegate, action: action)
|
||||
button.tintColor = .mvmBlack
|
||||
@ -32,4 +37,23 @@ public extension UIToolbar {
|
||||
|
||||
return toolbar
|
||||
}
|
||||
|
||||
class func addDismissToolbar(to object: TextFieldOrView?, delegate: Any?, action: Selector) {
|
||||
|
||||
let toolbar = emptyToolbar()
|
||||
let space = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
|
||||
let dismissButton = UIBarButtonItem(barButtonSystemItem: .done, target: delegate, action: action)
|
||||
dismissButton.tintColor = UIColor.black
|
||||
toolbar.items = [space, dismissButton]
|
||||
|
||||
switch object {
|
||||
case is UITextField:
|
||||
(object as? UITextField)?.inputAccessoryView = toolbar
|
||||
|
||||
case is UITextView:
|
||||
(object as? UITextView)?.inputAccessoryView = toolbar
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user