updated samples
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
c1c92f0926
commit
f31db5e614
@ -110,11 +110,8 @@ class BadgeViewController: BaseViewController<Badge> {
|
|||||||
|
|
||||||
extension BadgeViewController: ComponentSampleable {
|
extension BadgeViewController: ComponentSampleable {
|
||||||
static func makeSample() -> ComponentSample {
|
static func makeSample() -> ComponentSample {
|
||||||
let component = Self.makeComponent()
|
let c = Self()
|
||||||
component.fillColor = .red
|
c.setupModel()
|
||||||
component.text = "Terms and conditions"
|
return ComponentSample(component: c.component, trailingPinningType: .lessThanOrEqual)
|
||||||
component.maxWidth = 70
|
|
||||||
component.numberOfLines = 3
|
|
||||||
return ComponentSample(component: component, trailingPinningType: .lessThanOrEqual)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -334,15 +334,33 @@ public class BaseViewController<Component: UIView>: UIViewController, Initable ,
|
|||||||
viewController.didMove(toParent: self)
|
viewController.didMove(toParent: self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var componentTrailingEqualConstraint: NSLayoutConstraint?
|
||||||
|
var componentTrailingLessThanEqualConstraint: NSLayoutConstraint?
|
||||||
open func addContentTopView(view: UIView, edgeSpacing: CGFloat = 16.0, pinTrailing: Bool = true) {
|
open func addContentTopView(view: UIView, edgeSpacing: CGFloat = 16.0, pinTrailing: Bool = true) {
|
||||||
view.translatesAutoresizingMaskIntoConstraints = false
|
view.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
contentTopView.addSubview(view)
|
||||||
|
componentTrailingEqualConstraint = view.pinTrailing(anchor: contentTopView.trailingAnchor, constant: edgeSpacing)?.deactivate()
|
||||||
|
componentTrailingLessThanEqualConstraint = view.pinTrailingLessThanOrEqualTo(anchor: contentTopView.trailingAnchor, constant: edgeSpacing)?.deactivate()
|
||||||
|
view
|
||||||
|
.pinTop(edgeSpacing)
|
||||||
|
.pinLeading(edgeSpacing)
|
||||||
|
.pinBottom(edgeSpacing)
|
||||||
|
|
||||||
if pinTrailing {
|
if pinTrailing {
|
||||||
contentTopView.addSubview(view)
|
componentTrailingEqualConstraint?.activate()
|
||||||
view.pinToSuperView(.uniform(edgeSpacing))
|
|
||||||
} else {
|
} else {
|
||||||
let wrapper = UIView.makeWrapper(for: view)
|
componentTrailingLessThanEqualConstraint?.activate()
|
||||||
contentTopView.addSubview(wrapper)
|
}
|
||||||
wrapper.pinToSuperView(.uniform(edgeSpacing))
|
}
|
||||||
|
|
||||||
|
open func updateComponentConstraint(pinTrailing: Bool = true) {
|
||||||
|
componentTrailingEqualConstraint?.deactivate()
|
||||||
|
componentTrailingLessThanEqualConstraint?.deactivate()
|
||||||
|
|
||||||
|
if pinTrailing {
|
||||||
|
componentTrailingEqualConstraint?.activate()
|
||||||
|
} else {
|
||||||
|
componentTrailingLessThanEqualConstraint?.activate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -71,7 +71,7 @@ class ButtonIconViewController: BaseViewController<ButtonIcon> {
|
|||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
addContentTopView(view: component, pinTrailing: false)
|
addContentTopView(view: component, pinTrailing: false)
|
||||||
setupPicker()
|
setupPicker()
|
||||||
setupModel()
|
setupModel()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,13 +47,6 @@ class CalendarViewController: BaseViewController<CalendarBase> {
|
|||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
addContentTopView(view: component)
|
addContentTopView(view: component)
|
||||||
component.minDate = Date().startOfMonth
|
|
||||||
component.maxDate = Date().endOfMonth
|
|
||||||
component.onChange = { [weak self] control in
|
|
||||||
self?.label.text = DateFormatter.localizedString(from: control.selectedDate, dateStyle: .short, timeStyle: .none)
|
|
||||||
}
|
|
||||||
minDatePicker.date = component.minDate
|
|
||||||
maxDatePicker.date = component.maxDate
|
|
||||||
setupPicker()
|
setupPicker()
|
||||||
setupModel()
|
setupModel()
|
||||||
}
|
}
|
||||||
@ -206,6 +199,13 @@ class CalendarViewController: BaseViewController<CalendarBase> {
|
|||||||
func setupModel() {
|
func setupModel() {
|
||||||
let calendar = Calendar.current
|
let calendar = Calendar.current
|
||||||
let indicatorDate = calendar.startOfDay(for: calendar.date(byAdding: .day, value: 1, to: Date())!)
|
let indicatorDate = calendar.startOfDay(for: calendar.date(byAdding: .day, value: 1, to: Date())!)
|
||||||
|
component.minDate = Date().startOfMonth
|
||||||
|
component.maxDate = Date().endOfMonth
|
||||||
|
component.onChange = { [weak self] control in
|
||||||
|
self?.label.text = DateFormatter.localizedString(from: control.selectedDate, dateStyle: .short, timeStyle: .none)
|
||||||
|
}
|
||||||
|
minDatePicker.date = component.minDate
|
||||||
|
maxDatePicker.date = component.maxDate
|
||||||
component.indicators = indicators
|
component.indicators = indicators
|
||||||
legendOneField.text = "Due Date"
|
legendOneField.text = "Due Date"
|
||||||
legendTwoField.text = "Auto Pay"
|
legendTwoField.text = "Auto Pay"
|
||||||
@ -303,3 +303,11 @@ class CalendarViewController: BaseViewController<CalendarBase> {
|
|||||||
return day
|
return day
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension CalendarViewController: ComponentSampleable {
|
||||||
|
static func makeSample() -> ComponentSample {
|
||||||
|
let c = Self()
|
||||||
|
c.viewDidLoad()
|
||||||
|
return ComponentSample(component: c.component, edgeInset: .init(top: 16, left: 0, bottom: 16, right: 0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -219,3 +219,11 @@ class CarouselViewController: BaseViewController<Carousel> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension CarouselViewController: ComponentSampleable {
|
||||||
|
static func makeSample() -> ComponentSample {
|
||||||
|
let c = Self()
|
||||||
|
c.setupModel()
|
||||||
|
return ComponentSample(component: c.component)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -138,6 +138,6 @@ extension CheckboxGroupViewController: ComponentSampleable {
|
|||||||
|
|
||||||
component.selectorModels = [checkbox1, checkbox2]
|
component.selectorModels = [checkbox1, checkbox2]
|
||||||
|
|
||||||
return ComponentSample(component: component, trailingPinningType: .lessThanOrEqual)
|
return ComponentSample(component: component)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -110,6 +110,6 @@ extension CheckboxItemViewController: ComponentSampleable {
|
|||||||
component.childText = "I agree to Verizon's terms and conditions click here"
|
component.childText = "I agree to Verizon's terms and conditions click here"
|
||||||
component.errorText = "Error Text"
|
component.errorText = "Error Text"
|
||||||
|
|
||||||
return ComponentSample(component: component, trailingPinningType: .lessThanOrEqual)
|
return ComponentSample(component: component)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -142,3 +142,11 @@ class PriceLockupViewController: BaseViewController<PriceLockup> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension PriceLockupViewController: ComponentSampleable {
|
||||||
|
static func makeSample() -> ComponentSample {
|
||||||
|
let c = Self()
|
||||||
|
c.setupModel()
|
||||||
|
return ComponentSample(component: c.component)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -140,6 +140,6 @@ extension RadioBoxGroupViewController: ComponentSampleable {
|
|||||||
|
|
||||||
component.selectorModels = [radioBox1, radioBox2]
|
component.selectorModels = [radioBox1, radioBox2]
|
||||||
|
|
||||||
return ComponentSample(component: component, trailingPinningType: .lessThanOrEqual)
|
return ComponentSample(component: component)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -133,6 +133,6 @@ extension RadioButtonGroupViewController: ComponentSampleable {
|
|||||||
|
|
||||||
component.selectorModels = [radioButton1, radioButton2, radioButton3]
|
component.selectorModels = [radioButton1, radioButton2, radioButton3]
|
||||||
|
|
||||||
return ComponentSample(component: component, trailingPinningType: .lessThanOrEqual)
|
return ComponentSample(component: component)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -105,6 +105,6 @@ extension RadioButtonItemViewController: ComponentSampleable {
|
|||||||
component.childText = "I agree to Verizon's terms and conditions click here"
|
component.childText = "I agree to Verizon's terms and conditions click here"
|
||||||
component.errorText = "Error Text"
|
component.errorText = "Error Text"
|
||||||
|
|
||||||
return ComponentSample(component: component, trailingPinningType: .lessThanOrEqual)
|
return ComponentSample(component: component)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -218,3 +218,11 @@ class TableViewController: BaseViewController<Table> {
|
|||||||
self.component.tableRows = rows
|
self.component.tableRows = rows
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension TableViewController: ComponentSampleable {
|
||||||
|
static func makeSample() -> ComponentSample {
|
||||||
|
let c = Self()
|
||||||
|
c.setupModel()
|
||||||
|
return ComponentSample(component: c.component)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -20,7 +20,7 @@ public struct ComponentSample {
|
|||||||
public enum LessThanPinningType: String {
|
public enum LessThanPinningType: String {
|
||||||
case none, equalTo, lessThanOrEqual
|
case none, equalTo, lessThanOrEqual
|
||||||
}
|
}
|
||||||
|
public var edgeInset: UIEdgeInsets = .uniform(16)
|
||||||
public var top: GreaterThanPinningType = .equalTo
|
public var top: GreaterThanPinningType = .equalTo
|
||||||
public var leading: GreaterThanPinningType = .equalTo
|
public var leading: GreaterThanPinningType = .equalTo
|
||||||
public var trailing: LessThanPinningType = .equalTo
|
public var trailing: LessThanPinningType = .equalTo
|
||||||
@ -30,16 +30,18 @@ public struct ComponentSample {
|
|||||||
topPinningType: GreaterThanPinningType = .equalTo,
|
topPinningType: GreaterThanPinningType = .equalTo,
|
||||||
leadingPinningType: GreaterThanPinningType = .equalTo,
|
leadingPinningType: GreaterThanPinningType = .equalTo,
|
||||||
trailingPinningType: LessThanPinningType = .equalTo,
|
trailingPinningType: LessThanPinningType = .equalTo,
|
||||||
bottomPinningType: LessThanPinningType = .equalTo) {
|
bottomPinningType: LessThanPinningType = .equalTo,
|
||||||
|
edgeInset: UIEdgeInsets = .uniform(16)) {
|
||||||
|
|
||||||
self.component = component
|
self.component = component
|
||||||
self.top = topPinningType
|
self.top = topPinningType
|
||||||
self.leading = leadingPinningType
|
self.leading = leadingPinningType
|
||||||
self.trailing = trailingPinningType
|
self.trailing = trailingPinningType
|
||||||
self.bottom = bottomPinningType
|
self.bottom = bottomPinningType
|
||||||
|
self.edgeInset = edgeInset
|
||||||
}
|
}
|
||||||
|
|
||||||
public func pin(edgeInset: UIEdgeInsets = .zero) {
|
public func pin() {
|
||||||
|
|
||||||
guard let superview = component.superview else { return }
|
guard let superview = component.superview else { return }
|
||||||
switch top {
|
switch top {
|
||||||
@ -126,10 +128,10 @@ public class TableViewTestController: UIViewController, Initable, Surfaceable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let toggleSample = ComponentSample(component: toggle, leadingPinningType: .none)
|
let toggleSample = ComponentSample(component: toggle, leadingPinningType: .none, edgeInset: .init(top: 5, left: 0, bottom: 5, right: 16))
|
||||||
let wrapper = UIView().with { $0.translatesAutoresizingMaskIntoConstraints = false }
|
let wrapper = UIView().with { $0.translatesAutoresizingMaskIntoConstraints = false }
|
||||||
wrapper.addSubview(toggle)
|
wrapper.addSubview(toggle)
|
||||||
toggleSample.pin(edgeInset: .init(top: 5, left: 0, bottom: 5, right: 16))
|
toggleSample.pin()
|
||||||
|
|
||||||
let stackView = UIStackView(arrangedSubviews: [wrapper, tableView]).with {
|
let stackView = UIStackView(arrangedSubviews: [wrapper, tableView]).with {
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
@ -193,7 +195,7 @@ extension TableViewTestController : UITableViewDelegate, UITableViewDataSource {
|
|||||||
|
|
||||||
let cell = UITableViewCell()
|
let cell = UITableViewCell()
|
||||||
cell.contentView.addSubview(component)
|
cell.contentView.addSubview(component)
|
||||||
sample.pin(edgeInset: .uniform(16))
|
sample.pin()
|
||||||
cell.backgroundColor = surface.color
|
cell.backgroundColor = surface.color
|
||||||
cell.layoutIfNeeded()
|
cell.layoutIfNeeded()
|
||||||
return cell
|
return cell
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user