Merge branch 'develop' of https://gitlab.verizon.com/BPHV_MIPS/vds_ios_sample into vasavk/modal

This commit is contained in:
Vasavi Kanamarlapudi 2024-10-03 12:50:30 +05:30
commit 62e0a6387b
25 changed files with 163 additions and 60 deletions

View File

@ -110,11 +110,8 @@ class BadgeViewController: BaseViewController<Badge> {
extension BadgeViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
component.fillColor = .red
component.text = "Terms and conditions"
component.maxWidth = 70
component.numberOfLines = 3
return ComponentSample(component: component, trailingPinningType: .lessThanOrEqual)
let c = Self()
c.setupModel()
return ComponentSample(component: c.component, trailingPinningType: .lessThanOrEqual)
}
}

View File

@ -334,15 +334,33 @@ public class BaseViewController<Component: UIView>: UIViewController, Initable ,
viewController.didMove(toParent: self)
}
var componentTrailingEqualConstraint: NSLayoutConstraint?
var componentTrailingLessThanEqualConstraint: NSLayoutConstraint?
open func addContentTopView(view: UIView, edgeSpacing: CGFloat = 16.0, pinTrailing: Bool = true) {
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 {
contentTopView.addSubview(view)
view.pinToSuperView(.uniform(edgeSpacing))
componentTrailingEqualConstraint?.activate()
} else {
let wrapper = UIView.makeWrapper(for: view)
contentTopView.addSubview(wrapper)
wrapper.pinToSuperView(.uniform(edgeSpacing))
componentTrailingLessThanEqualConstraint?.activate()
}
}
open func updateComponentConstraint(pinTrailing: Bool = true) {
componentTrailingEqualConstraint?.deactivate()
componentTrailingLessThanEqualConstraint?.deactivate()
if pinTrailing {
componentTrailingEqualConstraint?.activate()
} else {
componentTrailingLessThanEqualConstraint?.activate()
}
}

View File

@ -71,7 +71,7 @@ class ButtonIconViewController: BaseViewController<ButtonIcon> {
override func viewDidLoad() {
super.viewDidLoad()
addContentTopView(view: component, pinTrailing: false)
addContentTopView(view: component, pinTrailing: false)
setupPicker()
setupModel()
}

View File

@ -47,13 +47,6 @@ class CalendarViewController: BaseViewController<CalendarBase> {
override func viewDidLoad() {
super.viewDidLoad()
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()
setupModel()
}
@ -206,6 +199,13 @@ class CalendarViewController: BaseViewController<CalendarBase> {
func setupModel() {
let calendar = Calendar.current
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
legendOneField.text = "Due Date"
legendTwoField.text = "Auto Pay"
@ -303,3 +303,11 @@ class CalendarViewController: BaseViewController<CalendarBase> {
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))
}
}

View File

@ -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)
}
}

View File

@ -138,6 +138,6 @@ extension CheckboxGroupViewController: ComponentSampleable {
component.selectorModels = [checkbox1, checkbox2]
return ComponentSample(component: component, trailingPinningType: .lessThanOrEqual)
return ComponentSample(component: component)
}
}

View File

@ -110,6 +110,6 @@ extension CheckboxItemViewController: ComponentSampleable {
component.childText = "I agree to Verizon's terms and conditions click here"
component.errorText = "Error Text"
return ComponentSample(component: component, trailingPinningType: .lessThanOrEqual)
return ComponentSample(component: component)
}
}

View File

@ -171,6 +171,7 @@ class DatePickerViewController: BaseViewController<DatePicker> {
widthTextField
.numberPublisher
.sink { [weak self] number in
self?.updateComponentConstraint(pinTrailing: number == nil)
self?.component.width = number?.cgFloatValue
}.store(in: &subscribers)
@ -479,3 +480,12 @@ extension DatePickerViewController {
}
}
extension DatePickerViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let c = Self()
c.setupModel()
c.setupCalendar()
return ComponentSample(component: c.component)
}
}

View File

@ -131,6 +131,7 @@ class DropdownSelectViewController: BaseViewController<DropdownSelect> {
widthTextField
.numberPublisher
.sink { [weak self] number in
self?.updateComponentConstraint(pinTrailing: number == nil)
self?.component.width = number?.cgFloatValue
}.store(in: &subscribers)

View File

@ -17,7 +17,7 @@ class FootnoteGroupViewController: BaseViewController<FootnoteGroup> {
override func viewDidLoad() {
super.viewDidLoad()
addContentTopView(view: component, pinTrailing: false)
addContentTopView(view: component)
setupPicker()
setupModel()
}
@ -31,6 +31,7 @@ class FootnoteGroupViewController: BaseViewController<FootnoteGroup> {
widthTextField
.numberPublisher
.sink { [weak self] number in
self?.updateComponentConstraint(pinTrailing: number == nil)
if let number {
self?.component.width = .value(number.cgFloatValue)
self?.percentageTextField.text = ""
@ -42,6 +43,7 @@ class FootnoteGroupViewController: BaseViewController<FootnoteGroup> {
percentageTextField
.numberPublisher
.sink { [weak self] number in
self?.updateComponentConstraint(pinTrailing: number == nil)
if let number, number.intValue > 9 {
self?.component.width = .percentage(number.cgFloatValue)
self?.widthTextField.text = ""
@ -67,3 +69,11 @@ class FootnoteGroupViewController: BaseViewController<FootnoteGroup> {
}
}
}
extension FootnoteGroupViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let c = Self()
c.setupModel()
return ComponentSample(component: c.component)
}
}

View File

@ -61,7 +61,7 @@ class FootnoteItemViewController: BaseViewController<FootnoteItem> {
override func viewDidLoad() {
super.viewDidLoad()
addContentTopView(view: component, pinTrailing: false)
addContentTopView(view: component)
setupPicker()
setupModel()
}
@ -92,6 +92,7 @@ class FootnoteItemViewController: BaseViewController<FootnoteItem> {
widthTextField
.numberPublisher
.sink { [weak self] number in
self?.updateComponentConstraint(pinTrailing: number == nil)
if let number {
self?.component.width = .value(number.cgFloatValue)
self?.percentageTextField.text = ""
@ -103,6 +104,7 @@ class FootnoteItemViewController: BaseViewController<FootnoteItem> {
percentageTextField
.numberPublisher
.sink { [weak self] number in
self?.updateComponentConstraint(pinTrailing: number == nil)
if let number, number.intValue > 9 {
self?.component.width = .percentage(number.cgFloatValue)
self?.widthTextField.text = ""
@ -164,3 +166,11 @@ class FootnoteItemViewController: BaseViewController<FootnoteItem> {
}
}
extension FootnoteItemViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let c = Self()
c.setupModel()
return ComponentSample(component: c.component)
}
}

View File

@ -181,6 +181,7 @@ class InputFieldViewController: BaseViewController<InputField> {
widthTextField
.numberPublisher
.sink { [weak self] number in
self?.updateComponentConstraint(pinTrailing: number == nil)
self?.component.width = number?.cgFloatValue
}.store(in: &subscribers)
@ -329,14 +330,8 @@ class InputFieldViewController: BaseViewController<InputField> {
extension InputFieldViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
component.fieldType = .text
component.width = 328
component.labelText = "Street Address"
component.helperText = "For example: 123 Verizon St"
component.errorText = "Enter a valid address."
component.successText = "Good job entering a valid address!"
component.tooltipModel = .init(title: "Check the formatting of your address", content: "House/Building number then street name")
return ComponentSample(component: component, trailingPinningType: .lessThanOrEqual)
let c = Self()
c.setupModel()
return ComponentSample(component: c.component)
}
}

View File

@ -163,6 +163,7 @@ class InputStepperViewController: BaseViewController<InputStepper> {
widthTextField
.numberPublisher
.sink { [weak self] number in
self?.updateComponentConstraint(pinTrailing: number == nil)
if let number {
self?.component.widthPercentage = nil
self?.component.width = number.cgFloatValue
@ -175,6 +176,7 @@ class InputStepperViewController: BaseViewController<InputStepper> {
widthPercentageTextField
.numberPublisher
.sink { [weak self] number in
self?.updateComponentConstraint(pinTrailing: number == nil)
if let number, number.intValue > 10 {
self?.component.width = nil
self?.component.widthPercentage = number.cgFloatValue
@ -253,3 +255,11 @@ class InputStepperViewController: BaseViewController<InputStepper> {
helperTextPlacementPickerSelectorView.text = component.helperTextPlacement.rawValue
}
}
extension InputStepperViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let c = Self()
c.setupModel()
return ComponentSample(component: c.component)
}
}

View File

@ -145,6 +145,7 @@ class LabelViewController: BaseViewController<Label> {
override func setupForm(){
super.setupForm()
addFormRow(label: "Current Language", view: Label().with { $0.text = LanguageManager.currentLanguage.description })
addFormRow(label: "Disabled", view: disabledSwitch, pinTrailing: false)
addFormRow(label: "Bold", view: boldSwitch, pinTrailing: false)
addFormRow(label: "Surface", view: surfacePickerSelectorView)

View File

@ -128,6 +128,20 @@ class MenuViewController: UITableViewController, TooltipLaunchable {
navigationItem.rightBarButtonItem = UIBarButtonItem(customView: tooltip)
}
var useSpanish = Toggle().with {
$0.offText = "English"
$0.onText = "Spanish"
$0.showText = true
$0.textPosition = .right
}
useSpanish.isOn = LanguageManager.currentLanguage == .spanish
useSpanish.onChange = { control in
LanguageManager.currentLanguage = control.isOn ? .spanish : .english
}
navigationItem.leftBarButtonItem = UIBarButtonItem(customView: useSpanish)
super.viewDidLoad()
overrideUserInterfaceStyle = .light
tableView.register(MenuCell.self, forCellReuseIdentifier: "cell")

View File

@ -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)
}
}

View File

@ -140,6 +140,6 @@ extension RadioBoxGroupViewController: ComponentSampleable {
component.selectorModels = [radioBox1, radioBox2]
return ComponentSample(component: component, trailingPinningType: .lessThanOrEqual)
return ComponentSample(component: component)
}
}

View File

@ -133,6 +133,6 @@ extension RadioButtonGroupViewController: ComponentSampleable {
component.selectorModels = [radioButton1, radioButton2, radioButton3]
return ComponentSample(component: component, trailingPinningType: .lessThanOrEqual)
return ComponentSample(component: component)
}
}

View File

@ -105,6 +105,6 @@ extension RadioButtonItemViewController: ComponentSampleable {
component.childText = "I agree to Verizon's terms and conditions click here"
component.errorText = "Error Text"
return ComponentSample(component: component, trailingPinningType: .lessThanOrEqual)
return ComponentSample(component: component)
}
}

View File

@ -218,3 +218,11 @@ class TableViewController: BaseViewController<Table> {
self.component.tableRows = rows
}
}
extension TableViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let c = Self()
c.setupModel()
return ComponentSample(component: c.component)
}
}

View File

@ -20,7 +20,7 @@ public struct ComponentSample {
public enum LessThanPinningType: String {
case none, equalTo, lessThanOrEqual
}
public var edgeInset: UIEdgeInsets = .uniform(16)
public var top: GreaterThanPinningType = .equalTo
public var leading: GreaterThanPinningType = .equalTo
public var trailing: LessThanPinningType = .equalTo
@ -30,16 +30,18 @@ public struct ComponentSample {
topPinningType: GreaterThanPinningType = .equalTo,
leadingPinningType: GreaterThanPinningType = .equalTo,
trailingPinningType: LessThanPinningType = .equalTo,
bottomPinningType: LessThanPinningType = .equalTo) {
bottomPinningType: LessThanPinningType = .equalTo,
edgeInset: UIEdgeInsets = .uniform(16)) {
self.component = component
self.top = topPinningType
self.leading = leadingPinningType
self.trailing = trailingPinningType
self.bottom = bottomPinningType
self.edgeInset = edgeInset
}
public func pin(edgeInset: UIEdgeInsets = .zero) {
public func pin() {
guard let superview = component.superview else { return }
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 }
wrapper.addSubview(toggle)
toggleSample.pin(edgeInset: .init(top: 5, left: 0, bottom: 5, right: 16))
toggleSample.pin()
let stackView = UIStackView(arrangedSubviews: [wrapper, tableView]).with {
$0.translatesAutoresizingMaskIntoConstraints = false
@ -193,7 +195,7 @@ extension TableViewTestController : UITableViewDelegate, UITableViewDataSource {
let cell = UITableViewCell()
cell.contentView.addSubview(component)
sample.pin(edgeInset: .uniform(16))
sample.pin()
cell.backgroundColor = surface.color
cell.layoutIfNeeded()
return cell

View File

@ -101,11 +101,8 @@ class TextAreaViewController: BaseViewController<TextArea> {
widthTextField
.numberPublisher
.sink { [weak self] number in
guard let number else {
self?.component.width = nil
return
}
self?.component.width = number.cgFloatValue
self?.updateComponentConstraint(pinTrailing: number == nil)
self?.component.width = number?.cgFloatValue
}.store(in: &subscribers)
tooltipTitleTextField
@ -182,13 +179,8 @@ class TextAreaViewController: BaseViewController<TextArea> {
extension TextAreaViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
component.width = 328
component.labelText = "Street Address"
component.helperText = "For example: 123 Verizon St"
component.errorText = "Enter a valid address."
component.tooltipModel = .init(title: "Check the formatting of your address",
content:"House/Building number then street name")
return ComponentSample(component: component, trailingPinningType: .lessThanOrEqual)
let c = Self()
c.setupModel()
return ComponentSample(component: c.component)
}
}

View File

@ -186,7 +186,7 @@ class TileContainerViewController: BaseViewController<TileContainer> {
component.color = .secondary
component.accessibilityLabel = "Tile Container"
addContentTopView(view: component, pinTrailing: false)
addContentTopView(view: component)
component.addContentView(mainView)
setupPicker()
setupModel()
@ -290,6 +290,7 @@ class TileContainerViewController: BaseViewController<TileContainer> {
widthTextField
.numberPublisher
.sink { [weak self] number in
self?.updateComponentConstraint(pinTrailing: number == nil)
guard let self, let number = number?.cgFloatValue else {
self?.widthTextField.text = ""
return

View File

@ -317,7 +317,7 @@ class TileletViewController: BaseViewController<Tilelet> {
override func viewDidLoad() {
super.viewDidLoad()
addContentTopView(view: component, pinTrailing: false)
addContentTopView(view: component)
setupPicker()
setupModel()
}
@ -362,9 +362,14 @@ class TileletViewController: BaseViewController<Tilelet> {
$0.addFormRow(label: "Max Width", view: maxWidthTextField)
}))
append(section: .init().with({
$0.title = "Text Styles"
$0.addFormRow(label: "Title", view: titleStandardStylePickerSelectorView)
$0.addFormRow(label: "Eyebrow/Subtitle", view: otherStandardStylePickerSelectorView)
}))
append(section: .init().with({
$0.title = "Eyebrow"
$0.addFormRow(label: "Text Style", tooltip: .init(title: "Text Style", content: "Eyebrow and Subtitle will share the same textStyle."), view: otherStandardStylePickerSelectorView)
$0.addFormRow(label: "is Bold", view: eyebrowIsBold, pinTrailing: false)
$0.addFormRow(label: "Text", view: eyebrowTextField)
$0.addFormRow(label: "Color", view: eyebrowColorPickerSelectorView)
@ -377,11 +382,11 @@ class TileletViewController: BaseViewController<Tilelet> {
append(section: .init().with({
$0.title = "Title"
$0.addFormRow(label: "Text Style", view: titleStandardStylePickerSelectorView)
$0.addFormRow(label: "is Bold", view: titleIsBold, pinTrailing: false)
$0.addFormRow(label: "Text", view: titleTextField)
$0.addFormRow(label: "Color", view: titleColorPickerSelectorView)
}))
titleTokenFormStackView.addFormRow(label: "Token", view: titleTokenColorView)
titleColorFormStackView.addFormRow(label: "Custom", view: titleCustomColorView)
append(section: titleTokenFormStackView)
@ -459,6 +464,7 @@ class TileletViewController: BaseViewController<Tilelet> {
widthTextField
.numberPublisher
.sink { [weak self] number in
self?.updateComponentConstraint(pinTrailing: number == nil)
guard let self, let number = number?.cgFloatValue else {
self?.widthTextField.text = ""
return

View File

@ -146,9 +146,14 @@ class TitleLockupViewController: BaseViewController<TitleLockup> {
addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Text Alignment", view: textAlignmentPickerSelectorView)
append(section: .init().with({
$0.title = "Text Styles"
$0.addFormRow(label: "Title", view: titleStandardStylePickerSelectorView)
$0.addFormRow(label: "Eyebrow/Subtitle", view: otherStandardStylePickerSelectorView)
}))
append(section: .init().with({
$0.title = "\nEyebrow"
$0.addFormRow(label: "TextStyle (Subtitle)", view: otherStandardStylePickerSelectorView)
$0.addFormRow(label: "is Bold", view: eyebrowIsBold, pinTrailing: false)
$0.addFormRow(label: "Text", view: eyebrowTextField)
$0.addFormRow(label: "Color", view: eyebrowColorPickerSelectorView)
@ -161,7 +166,6 @@ class TitleLockupViewController: BaseViewController<TitleLockup> {
append(section: .init().with({
$0.title = "\nTitle"
$0.addFormRow(label: "TextStyle", view: titleStandardStylePickerSelectorView)
$0.addFormRow(label: "is Bold", view: titleIsBold, pinTrailing: false)
$0.addFormRow(label: "Text", view: titleTextField)
$0.addFormRow(label: "Color", view: titleColorPickerSelectorView)