Refactored table controller

This commit is contained in:
Sumanth Nadigadda 2024-05-09 18:21:25 +05:30
parent 45d4897d61
commit 89bf60714c

View File

@ -7,11 +7,10 @@
import Foundation import Foundation
import VDS import VDS
import UIKit
class TableViewController: BaseViewController<Table> { class TableViewController: BaseViewController<Table> {
var showHeaderLine = Toggle()
var showRowLine = Toggle()
var striped = Toggle() var striped = Toggle()
lazy var headerLineStylePicker = { lazy var headerLineStylePicker = {
@ -30,33 +29,18 @@ class TableViewController: BaseViewController<Table> {
super.viewDidLoad() super.viewDidLoad()
self.setupPicker() self.setupPicker()
self.setupModel() self.setupModel()
showHeaderLine.isOn = true
showRowLine.isOn = true
component.headerBottomLine = showHeaderLine.isOn
component.rowBottomLine = showRowLine.isOn
} }
override func setupForm() { override func setupForm() {
super.setupForm() super.setupForm()
addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Padding", view: paddingPicker) addFormRow(label: "Padding", view: paddingPicker)
addFormRow(label: "Striped", view: striped)
addFormRow(label: "Header line style", view: headerLineStylePicker) addFormRow(label: "Header line style", view: headerLineStylePicker)
addFormRow(label: "Row line style", view: rowLineStylePicker) addFormRow(label: "Row line style", view: rowLineStylePicker)
addFormRow(label: "Show header line", view: showHeaderLine)
addFormRow(label: "Show row line", view: showRowLine)
addFormRow(label: "Striped", view: striped)
addContentTopView(view: component) addContentTopView(view: component)
showHeaderLine.onChange = { [weak self] sender in
self?.component.headerBottomLine = sender.isOn
}
showRowLine.onChange = { [weak self] sender in
self?.component.rowBottomLine = sender.isOn
}
striped.onChange = { [weak self] sender in striped.onChange = { [weak self] sender in
self?.component.striped = sender.isOn self?.component.striped = sender.isOn
} }
@ -69,11 +53,24 @@ class TableViewController: BaseViewController<Table> {
} }
headerLineStylePicker.onPickerDidSelect = { [weak self] item in headerLineStylePicker.onPickerDidSelect = { [weak self] item in
self?.component.headerBottomLineType = item let headers = self?.component.tableHeader ?? [[]]
for currentRow in headers {
for var currentItem in currentRow {
currentItem.bottomLine = item
}
}
self?.component.tableHeader = headers
} }
rowLineStylePicker.onPickerDidSelect = { [weak self] item in rowLineStylePicker.onPickerDidSelect = { [weak self] item in
self?.component.rowBottomLineType = item
let rows = self?.component.tableRows ?? [[]]
for currentRow in rows {
for var currentItem in currentRow {
currentItem.bottomLine = item
}
}
self?.component.tableRows = rows
} }
paddingPicker.onPickerDidSelect = { [weak self] item in paddingPicker.onPickerDidSelect = { [weak self] item in
@ -82,9 +79,25 @@ class TableViewController: BaseViewController<Table> {
} }
func setupModel() { func setupModel() {
self.component.tableData = [[Table.TableCellLabelModel.init(text: ""), Table.TableCellLabelModel.init(text: "Verizon smart family"), Table.TableCellLabelModel.init(text: "Call filter")], ///Header row
[Table.TableCellLabelModel.init(text: "Cost"), Table.TableCellLabelModel.init(text: "$5/month for up to 10 lines"), Table.TableCellLabelModel.init(text: "$2.99/month per device")], self.component.tableHeader = [[TableItemModel(bottomLine: .primary, component: Label().with { $0.text = ""}),
[Table.TableCellLabelModel.init(text: "Block web domains"), Table.TableCellImageModel.init(name: Icon.Name.checkmark, size: .medium), Table.TableCellImageModel.init(name: Icon.Name.checkmark, size: .medium)], TableItemModel(bottomLine: .primary, component: Label().with { $0.text = "Verizon smart family"; $0.textStyle = .boldTitleSmall; $0.lineBreakMode = .byWordWrapping}),
[Table.TableCellLabelModel.init(text: "Block calls and messages from specific numbers "), Table.TableCellLabelModel.init(text: "Permanently"), Table.TableCellLabelModel.init(text: "Permanently")],] 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}),
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})]]
///second row
rows.append([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 })])
///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}),
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})])
self.component.tableRows = rows
} }
} }