fixed issue with buttons in selector

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-05-25 14:14:52 -05:00
parent a4598644f7
commit ee772648b1
3 changed files with 12 additions and 5 deletions

View File

@ -10,7 +10,7 @@ import VDS
import UIKit import UIKit
extension UIView { extension UIView {
public static func makeWrapper(for view: UIView, edgeSpacing: CGFloat = 0.0) -> UIView { public static func makeWrapper(for view: UIView, edgeSpacing: CGFloat = 0.0, isTrailing: Bool = true) -> UIView {
let wrapper = UIView().with { let wrapper = UIView().with {
$0.translatesAutoresizingMaskIntoConstraints = false $0.translatesAutoresizingMaskIntoConstraints = false
} }
@ -18,8 +18,14 @@ extension UIView {
view view
.pinTop(edgeSpacing) .pinTop(edgeSpacing)
.pinBottom(edgeSpacing) .pinBottom(edgeSpacing)
.pinLeading(edgeSpacing)
view.trailingAnchor.constraint(lessThanOrEqualTo: wrapper.trailingAnchor).isActive = true if isTrailing {
view.pinLeading(edgeSpacing)
view.trailingAnchor.constraint(lessThanOrEqualTo: wrapper.trailingAnchor).isActive = true
} else {
view.leadingAnchor.constraint(greaterThanOrEqualTo: wrapper.leadingAnchor).isActive = true
view.pinTrailing(edgeSpacing)
}
return wrapper return wrapper
} }
} }

View File

@ -60,6 +60,7 @@ public class PickerSelectorView<EnumType: RawRepresentable>: UIStackView, Picker
public var items: [EnumType] { public var items: [EnumType] {
didSet { selectedIndex = 0 } didSet { selectedIndex = 0 }
} }
public var onClick: AnyCancellable?
public var onPickerDidSelect: ((EnumType) -> Void)? public var onPickerDidSelect: ((EnumType) -> Void)?
public var scrollToBottom: (()->Void)? public var scrollToBottom: (()->Void)?
public init(title: String, picker: UIPickerView? = nil, items: [EnumType]) { public init(title: String, picker: UIPickerView? = nil, items: [EnumType]) {
@ -74,7 +75,7 @@ public class PickerSelectorView<EnumType: RawRepresentable>: UIStackView, Picker
label.text = title label.text = title
updateSelectedIndex() updateSelectedIndex()
addArrangedSubview(label) addArrangedSubview(label)
addArrangedSubview(button) addArrangedSubview(.makeWrapper(for: button, isTrailing: false))
button.onClick = { [weak self] _ in button.onClick = { [weak self] _ in
self?.picker?.delegate = self self?.picker?.delegate = self
self?.picker?.dataSource = self self?.picker?.dataSource = self

View File

@ -57,7 +57,7 @@ class TabsViewController: BaseViewController<Tabs> {
addFormRow(label: "Show Borderline", view: .makeWrapper(for: borderlineSwitch)) addFormRow(label: "Show Borderline", view: .makeWrapper(for: borderlineSwitch))
addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Size", view: sizePickerSelectorView) addFormRow(label: "Size", view: sizePickerSelectorView)
if UIDevice.isIPad { if UIDevice.isIPad {
addFormRow(label: "Orientation", view: orientationPickerSelectorView) addFormRow(label: "Orientation", view: orientationPickerSelectorView)
} }