refactored picker base
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
052d354bbd
commit
b24f90dab7
@ -29,6 +29,7 @@ public protocol PickerViewable: UIPickerViewDataSource, UIPickerViewDelegate, Ha
|
||||
associatedtype EnumType: RawRepresentable
|
||||
var items: [EnumType] { get set }
|
||||
var onPickerDidSelect: ((EnumType) -> Void)? { get set }
|
||||
var scrollToBottom: (()->Void)? { get set }
|
||||
}
|
||||
|
||||
public class PickerSelectorView<EnumType: RawRepresentable>: UIStackView, PickerViewable {
|
||||
@ -50,7 +51,7 @@ public class PickerSelectorView<EnumType: RawRepresentable>: UIStackView, Picker
|
||||
didSet { selectedIndex = 0 }
|
||||
}
|
||||
public var onPickerDidSelect: ((EnumType) -> Void)?
|
||||
|
||||
public var scrollToBottom: (()->Void)?
|
||||
public init(title: String, picker: UIPickerView? = nil, items: [EnumType]) {
|
||||
self.picker = picker
|
||||
self.items = items
|
||||
@ -70,6 +71,7 @@ public class PickerSelectorView<EnumType: RawRepresentable>: UIStackView, Picker
|
||||
self?.picker?.reloadAllComponents()
|
||||
self?.picker?.selectRow(self?.selectedIndex ?? 0, inComponent: 0, animated: false)
|
||||
self?.picker?.isHidden = false
|
||||
self?.scrollToBottom?()
|
||||
}.store(in: &subscribers)
|
||||
}
|
||||
|
||||
@ -94,6 +96,7 @@ public class PickerSelectorView<EnumType: RawRepresentable>: UIStackView, Picker
|
||||
guard row - 1 >= 0 else { return }
|
||||
selectedIndex = row
|
||||
onPickerDidSelect?(items[row-1])
|
||||
text = "\(items[row-1].rawValue)"
|
||||
pickerView.isHidden = true
|
||||
}
|
||||
}
|
||||
|
||||
@ -122,17 +122,14 @@ class BadgeViewController: ModelScrollViewController<DefaultBadgeModel> {
|
||||
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
||||
self?.badge.surface = item
|
||||
self?.contentTopView.backgroundColor = item.color
|
||||
self?.surfacePickerSelectorView.text = item.rawValue
|
||||
}
|
||||
|
||||
fillColorPickerSelectorView.onPickerDidSelect = { [weak self] item in
|
||||
self?.badge.fillColor = item
|
||||
self?.fillColorPickerSelectorView.text = item.rawValue
|
||||
}
|
||||
|
||||
numberOfLinesPickerSelectorView.onPickerDidSelect = { [weak self] item in
|
||||
self?.badge.numberOfLines = item.intValue
|
||||
self?.numberOfLinesPickerSelectorView.text = item.rawValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,18 +112,15 @@ class ButtonViewController: ModelScrollViewController<DefaultButtonModel> {
|
||||
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
||||
self?.button.surface = item
|
||||
self?.contentTopView.backgroundColor = item.color
|
||||
self?.surfacePickerSelectorView.text = item.rawValue
|
||||
}
|
||||
|
||||
usePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
||||
self?.button.use = item
|
||||
self?.button.backgroundColor = item.color
|
||||
self?.usePickerSelectorView.text = item.rawValue
|
||||
}
|
||||
|
||||
buttonSizePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
||||
self?.button.size = item
|
||||
self?.buttonSizePickerSelectorView.text = item.rawValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,7 +119,6 @@ class CheckboxGroupViewController: ModelScrollViewController<DefaultCheckboxGro
|
||||
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
||||
self?.checkboxGroup.surface = item
|
||||
self?.contentTopView.backgroundColor = item.color
|
||||
self?.surfacePickerSelectorView.text = item.rawValue
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -116,7 +116,6 @@ class CheckboxViewController: ModelScrollViewController<DefaultCheckboxModel> {
|
||||
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
||||
self?.checkbox.surface = item
|
||||
self?.contentTopView.backgroundColor = item.color
|
||||
self?.surfacePickerSelectorView.text = item.rawValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,7 +127,6 @@ class LabelViewController: ModelScrollViewController<DefaultLabelModel> {
|
||||
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
||||
self?.label.surface = item
|
||||
self?.contentTopView.backgroundColor = item.color
|
||||
self?.surfacePickerSelectorView.text = item.rawValue
|
||||
}
|
||||
|
||||
textSizePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
||||
|
||||
@ -27,6 +27,7 @@ class MenuViewController: UITableViewController {
|
||||
MenuComponent(title: "RadioButtonGroup", viewController: RadioButtonViewController.self),
|
||||
MenuComponent(title: "RadioBoxGroup", viewController: RadioBoxGroupViewController.self),
|
||||
MenuComponent(title: "RadioSwatchGroup", viewController: RadioSwatchGroupViewController.self),
|
||||
MenuComponent(title: "TextEntryField", viewController: TextEntryFieldViewController.self),
|
||||
MenuComponent(title: "Toggle", viewController: ToggleViewController.self)
|
||||
]
|
||||
|
||||
|
||||
@ -71,6 +71,7 @@ public class ModelScrollViewController<ModelType: Modelable>: UIViewController,
|
||||
initialSetupPerformed = true
|
||||
setupUpdateView()
|
||||
setup()
|
||||
surfacePickerSelectorView.scrollToBottom = { [weak self] in self?.scrollToBottom()}
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,6 +81,7 @@ public class ModelScrollViewController<ModelType: Modelable>: UIViewController,
|
||||
|
||||
public var picker: UIPickerView = {
|
||||
return UIPickerView().with {
|
||||
$0.backgroundColor = .white
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
}
|
||||
}()
|
||||
@ -138,7 +140,7 @@ public class ModelScrollViewController<ModelType: Modelable>: UIViewController,
|
||||
formStackView.topAnchor.constraint(equalTo: contentBottomView.topAnchor, constant: edgeSpacing).isActive = true
|
||||
formStackView.leadingAnchor.constraint(equalTo: contentBottomView.leadingAnchor, constant: edgeSpacing).isActive = true
|
||||
formStackView.trailingAnchor.constraint(equalTo: contentBottomView.trailingAnchor, constant: -edgeSpacing).isActive = true
|
||||
formStackView.bottomAnchor.constraint(equalTo: contentBottomView.bottomAnchor, constant: -150).isActive = true
|
||||
formStackView.bottomAnchor.constraint(equalTo: contentBottomView.bottomAnchor, constant: -100).isActive = true
|
||||
|
||||
view.addSubview(picker)
|
||||
picker.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor).isActive = true
|
||||
@ -149,6 +151,11 @@ public class ModelScrollViewController<ModelType: Modelable>: UIViewController,
|
||||
|
||||
private let scrollViewController = ScrollViewController()
|
||||
|
||||
public func scrollToBottom() {
|
||||
let bottomOffset = CGPoint(x: 0, y: scrollViewController.scrollView.contentSize.height - scrollViewController.scrollView.bounds.height + scrollViewController.scrollView.contentInset.bottom)
|
||||
scrollViewController.scrollView.setContentOffset(bottomOffset, animated: true)
|
||||
}
|
||||
|
||||
private func embed(_ viewController: UIViewController) {
|
||||
addChild(viewController)
|
||||
view.addSubview(viewController.view)
|
||||
@ -190,6 +197,10 @@ public class ModelScrollViewController<ModelType: Modelable>: UIViewController,
|
||||
} else {
|
||||
formStackView.addArrangedSubview(formRow)
|
||||
}
|
||||
|
||||
if let pickerViewable = view as? any PickerViewable {
|
||||
pickerViewable.scrollToBottom = { [weak self] in self?.scrollToBottom() }
|
||||
}
|
||||
}
|
||||
|
||||
open func setup() {}
|
||||
|
||||
@ -130,7 +130,6 @@ class RadioBoxGroupViewController: ModelScrollViewController<DefaultRadioBoxGro
|
||||
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
||||
self?.radioBoxGroup.surface = item
|
||||
self?.contentTopView.backgroundColor = item.color
|
||||
self?.surfacePickerSelectorView.text = item.rawValue
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -126,7 +126,6 @@ class RadioButtonViewController: ModelScrollViewController<DefaultRadioButtonGr
|
||||
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
||||
self?.radioButtonGroup.surface = item
|
||||
self?.contentTopView.backgroundColor = item.color
|
||||
self?.surfacePickerSelectorView.text = item.rawValue
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -134,7 +134,6 @@ class RadioSwatchGroupViewController: ModelScrollViewController<DefaultRadioSwa
|
||||
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
||||
self?.radioSwatchGroup.surface = item
|
||||
self?.contentTopView.backgroundColor = item.color
|
||||
self?.surfacePickerSelectorView.text = item.rawValue
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -113,17 +113,14 @@ class ToggleViewController: ModelScrollViewController<DefaultToggleModel> {
|
||||
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
||||
self?.toggle.surface = item
|
||||
self?.contentTopView.backgroundColor = item.color
|
||||
self?.surfacePickerSelectorView.text = item.rawValue
|
||||
}
|
||||
|
||||
textSizePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
||||
self?.toggle.fontSize = item
|
||||
self?.textSizePickerSelectorView.text = item.rawValue
|
||||
}
|
||||
|
||||
textPositionPickerSelectorView.onPickerDidSelect = { [weak self] item in
|
||||
self?.toggle.textPosition = item
|
||||
self?.textPositionPickerSelectorView.text = item.rawValue
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user