Merge branch 'feature/Table' of https://gitlab.verizon.com/BPHV_MIPS/vds_ios_sample.git into feature/Table

This commit is contained in:
Matt Bruce 2024-06-07 09:37:54 -05:00
commit 8638ee04c3

View File

@ -8,11 +8,18 @@
import Foundation
import VDS
import UIKit
import VDSTokens
class TableViewController: BaseViewController<Table> {
var striped = Toggle()
var fillContainer = Toggle()
var customColumnWidthSize = NumericField().with {
$0.placeholder = "Minimum 50px"
}
lazy var headerLineStylePicker = {
PickerSelectorView(title: "primary", picker: self.picker, items: Line.Style.allCases)
}()
@ -38,12 +45,33 @@ class TableViewController: BaseViewController<Table> {
addFormRow(label: "Striped", view: striped)
addFormRow(label: "Header line style", view: headerLineStylePicker)
addFormRow(label: "Row line style", view: rowLineStylePicker)
addFormRow(label: "Fill container", view: fillContainer)
addFormRow(label: "Custom column size", view: customColumnWidthSize)
fillContainer.isOn = component.fillContainer
updateTextFieldStatus(enable: !fillContainer.isOn)
addContentTopView(view: component)
striped.onChange = { [weak self] sender in
self?.component.striped = sender.isOn
}
fillContainer.onChange = { [weak self] sender in
self?.component.fillContainer = sender.isOn
self?.updateTextFieldStatus(enable:!sender.isOn)
if let count = self?.component.tableHeader.first?.columnsCount,
let text = self?.customColumnWidthSize.text,
let width = NumberFormatter().number(from: text) {
self?.component.columnWidths = Array(repeating: CGFloat(truncating: width), count: count)
}
}
customColumnWidthSize.numberPublisher.sink { [weak self] text in
if let count = self?.component.tableHeader.first?.columnsCount, let text, text.intValue > 50 {
self?.component.columnWidths = Array(repeating: CGFloat(truncating: text), count: count)
}
}.store(in: &subscribers)
}
func setupPicker() {
@ -53,11 +81,11 @@ class TableViewController: BaseViewController<Table> {
}
headerLineStylePicker.onPickerDidSelect = { [weak self] item in
var headers = self?.component.tableHeader ?? [[]]
var headers = self?.component.tableHeader ?? [TableRowModel]()
for currentHeaderIndex in 0..<headers.count {
var currentHeader = headers[currentHeaderIndex]
for currentHeaderItem in 0..<currentHeader.count {
currentHeader[currentHeaderItem].bottomLine = item
for currentHeaderItem in 0..<currentHeader.columnsCount {
currentHeader.columns[currentHeaderItem].bottomLine = item
}
headers[currentHeaderIndex] = currentHeader
}
@ -66,12 +94,12 @@ class TableViewController: BaseViewController<Table> {
rowLineStylePicker.onPickerDidSelect = { [weak self] item in
var rows = self?.component.tableRows ?? [[]]
var rows = self?.component.tableRows ?? [TableRowModel]()
for currentRowIndex in 0..<rows.count {
var currentRow = rows[currentRowIndex]
for currentRowItem in 0..<currentRow.count {
currentRow[currentRowItem].bottomLine = item
for currentRowItem in 0..<currentRow.columnsCount {
currentRow.columns[currentRowItem].bottomLine = item
}
rows[currentRowIndex] = currentRow
}
@ -84,25 +112,80 @@ class TableViewController: BaseViewController<Table> {
}
}
func updateTextFieldStatus(enable: Bool) {
customColumnWidthSize.isEnabled = enable
customColumnWidthSize.backgroundColor = enable ? UIColor.white : VDSColor.paletteGray85
}
func setupModel() {
///Header row
self.component.tableHeader = [[TableItemModel(bottomLine: .primary, component: Label().with { $0.text = ""}),
TableItemModel(bottomLine: .primary, component: Label().with { $0.text = "Verizon smart family"; $0.textStyle = .boldTitleSmall; $0.lineBreakMode = .byWordWrapping}),
TableItemModel(bottomLine: .primary, component: Label().with { $0.text = "Call filter"; $0.textStyle = .boldTitleSmall; $0.lineBreakMode = .byWordWrapping })]]
self.component.tableHeader = [TableRowModel(columns: [TableItemModel(bottomLine: .primary, component: nil),
TableItemModel(bottomLine: .primary, component: Label().with { $0.text = "Verizon smart family"; $0.textStyle = .boldTitleSmall; $0.lineBreakMode = .byWordWrapping}),
TableItemModel(bottomLine: .primary, component: Label().with { $0.text = "Call filter"; $0.textStyle = .boldTitleSmall; $0.lineBreakMode = .byWordWrapping })])]
///First row
var rows = [[TableItemModel(bottomLine: .secondary, component: Label().with { $0.text = "Cost"; $0.textStyle = UIDevice.isIPad ? .bodyLarge : .bodySmall; $0.lineBreakMode = .byWordWrapping}),
var rows = [TableRowModel(columns: [TableItemModel(bottomLine: .secondary, component: Label().with { $0.text = "Cost"; $0.textStyle = UIDevice.isIPad ? .bodyLarge : .bodySmall; $0.lineBreakMode = .byWordWrapping}),
TableItemModel(bottomLine: .secondary, component: Label().with { $0.text = "$5/month for up to 10 lines"; $0.textStyle = UIDevice.isIPad ? .bodyLarge : .bodySmall; $0.lineBreakMode = .byWordWrapping}),
TableItemModel(bottomLine: .secondary, component: Label().with { $0.text = "$2.99/month per device"; $0.textStyle = UIDevice.isIPad ? .bodyLarge : .bodySmall; $0.lineBreakMode = .byWordWrapping})]]
TableItemModel(bottomLine: .secondary, component: Label().with { $0.text = "$2.99/month per device"; $0.textStyle = UIDevice.isIPad ? .bodyLarge : .bodySmall; $0.lineBreakMode = .byWordWrapping})])]
///second row
rows.append([TableItemModel(bottomLine: .secondary, component: Label().with { $0.text = "Block web domains"; $0.textStyle = UIDevice.isIPad ? .bodyLarge : .bodySmall; $0.lineBreakMode = .byWordWrapping}),
rows.append(TableRowModel(columns: [TableItemModel(bottomLine: .secondary, component: Label().with { $0.text = "Block web domains"; $0.textStyle = UIDevice.isIPad ? .bodyLarge : .bodySmall; $0.lineBreakMode = .byWordWrapping}),
TableItemModel(bottomLine: .secondary, component: Icon().with { $0.name = Icon.Name.checkmark }),
TableItemModel(bottomLine: .secondary, component: Icon().with { $0.name = Icon.Name.checkmark })])
TableItemModel(bottomLine: .secondary, component: Icon().with { $0.name = Icon.Name.checkmark })]))
///Third row
rows.append([TableItemModel(bottomLine: .secondary, component: Label().with { $0.text = "Block calls and messages from specific numbers"; $0.textStyle = UIDevice.isIPad ? .bodyLarge : .bodySmall; $0.lineBreakMode = .byWordWrapping}),
rows.append(TableRowModel(columns: [TableItemModel(bottomLine: .secondary, component: Label().with { $0.text = "Block calls and messages from specific numbers"; $0.textStyle = UIDevice.isIPad ? .bodyLarge : .bodySmall; $0.lineBreakMode = .byWordWrapping}),
TableItemModel(bottomLine: .secondary, component: Label().with { $0.text = "Permanently"; $0.textStyle = UIDevice.isIPad ? .bodyLarge : .bodySmall; $0.lineBreakMode = .byWordWrapping}),
TableItemModel(bottomLine: .secondary, component: Label().with { $0.text = "Permanently"; $0.textStyle = UIDevice.isIPad ? .bodyLarge : .bodySmall; $0.lineBreakMode = .byWordWrapping})])
TableItemModel(bottomLine: .secondary, component: Label().with { $0.text = "Permanently"; $0.textStyle = UIDevice.isIPad ? .bodyLarge : .bodySmall; $0.lineBreakMode = .byWordWrapping})]))
if UIDevice.isIPad {
///Fourth row
let titleLockUp = TitleLockup()
let eyebrowModel = TitleLockup.EyebrowModel(text: "Today only.")
let titleModel = TitleLockup.TitleModel(text: "Get more of our best")
let subTitleModel = TitleLockup.SubTitleModel(text: "Get both of our best and pay less. Pair 5G Home Internet with Verizon mobile to save every month.")
titleLockUp.eyebrowModel = eyebrowModel
titleLockUp.titleModel = titleModel
titleLockUp.subTitleModel = subTitleModel
let button = Button()
button.text = "Testing"
rows.append(TableRowModel(columns: [TableItemModel(bottomLine: .secondary, component:Toggle()),
TableItemModel(bottomLine: .secondary, component:titleLockUp),
TableItemModel(bottomLine: .secondary, component: button)]))
///Fifth row
let tilelet = Tilelet()
let ftitleModel = Tilelet.TitleModel(text: "Save $XX on your monthly bill.")
let fsubTitleModel = Tilelet.SubTitleModel(text: "Enroll in Auto Pay & paper-free billing to save on your monthly bill.")
tilelet.titleModel = ftitleModel
tilelet.subTitleModel = fsubTitleModel
let textArea = TextArea()
textArea.labelText = "Street Address"
textArea.helperText = "For example: 123 Verizon St"
textArea.errorText = "Enter a valid address."
textArea.tooltipModel = .init(title: "Check the formatting of your address", content:"House/Building number then street name")
let trailingToolTip = TrailingTooltipLabel()
trailingToolTip.labelText = "5G Ultra Wideband is available in your area"
trailingToolTip.tooltipModel = .init(title: "Check the formatting of your address",
content:"House/Building number then street name")
let image = UIImage(named: "clean-surface")
let imageView = UIImageView(image: image)
rows.append(TableRowModel(columns: [TableItemModel(bottomLine: .secondary, component:textArea),
TableItemModel(bottomLine: .secondary, component:imageView),
TableItemModel(bottomLine: .secondary, component:trailingToolTip)]))
}
component.fillContainer = true
component.columnWidths = [400.0, 400.0, 400.0]
self.component.tableRows = rows
}