using TableRowModel to populate data for Table component.

This commit is contained in:
Sumanth Nadigadda 2024-05-27 15:00:38 +05:30
parent 7a47221d62
commit 0590309726

View File

@ -60,10 +60,15 @@ class TableViewController: BaseViewController<Table> {
fillContainer.onChange = { [weak self] sender in fillContainer.onChange = { [weak self] sender in
self?.component.fillContainer = sender.isOn self?.component.fillContainer = sender.isOn
self?.updateTextFieldStatus(enable:!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 customColumnWidthSize.numberPublisher.sink { [weak self] text in
if let count = self?.component.tableHeader.first?.count, let text, text.intValue > 50 { if let count = self?.component.tableHeader.first?.columnsCount, let text, text.intValue > 50 {
self?.component.columnWidths = Array(repeating: CGFloat(truncating: text), count: count) self?.component.columnWidths = Array(repeating: CGFloat(truncating: text), count: count)
} }
}.store(in: &subscribers) }.store(in: &subscribers)
@ -76,11 +81,11 @@ class TableViewController: BaseViewController<Table> {
} }
headerLineStylePicker.onPickerDidSelect = { [weak self] item in headerLineStylePicker.onPickerDidSelect = { [weak self] item in
var headers = self?.component.tableHeader ?? [[]] var headers = self?.component.tableHeader ?? [TableRowModel]()
for currentHeaderIndex in 0..<headers.count { for currentHeaderIndex in 0..<headers.count {
var currentHeader = headers[currentHeaderIndex] var currentHeader = headers[currentHeaderIndex]
for currentHeaderItem in 0..<currentHeader.count { for currentHeaderItem in 0..<currentHeader.columnsCount {
currentHeader[currentHeaderItem].bottomLine = item currentHeader.columns[currentHeaderItem].bottomLine = item
} }
headers[currentHeaderIndex] = currentHeader headers[currentHeaderIndex] = currentHeader
} }
@ -89,12 +94,12 @@ class TableViewController: BaseViewController<Table> {
rowLineStylePicker.onPickerDidSelect = { [weak self] item in rowLineStylePicker.onPickerDidSelect = { [weak self] item in
var rows = self?.component.tableRows ?? [[]] var rows = self?.component.tableRows ?? [TableRowModel]()
for currentRowIndex in 0..<rows.count { for currentRowIndex in 0..<rows.count {
var currentRow = rows[currentRowIndex] var currentRow = rows[currentRowIndex]
for currentRowItem in 0..<currentRow.count { for currentRowItem in 0..<currentRow.columnsCount {
currentRow[currentRowItem].bottomLine = item currentRow.columns[currentRowItem].bottomLine = item
} }
rows[currentRowIndex] = currentRow rows[currentRowIndex] = currentRow
} }
@ -114,23 +119,24 @@ class TableViewController: BaseViewController<Table> {
func setupModel() { func setupModel() {
///Header row ///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}), self.component.tableHeader = [TableRowModel(columns: [TableItemModel(bottomLine: .primary, component: nil),
TableItemModel(bottomLine: .primary, component: Label().with { $0.text = "Call filter"; $0.textStyle = .boldTitleSmall; $0.lineBreakMode = .byWordWrapping })]] 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 ///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 = "$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 ///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 })]) TableItemModel(bottomLine: .secondary, component: Icon().with { $0.name = Icon.Name.checkmark })]))
///Third row ///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})]) TableItemModel(bottomLine: .secondary, component: Label().with { $0.text = "Permanently"; $0.textStyle = UIDevice.isIPad ? .bodyLarge : .bodySmall; $0.lineBreakMode = .byWordWrapping})]))
if UIDevice.isIPad { if UIDevice.isIPad {
@ -147,9 +153,9 @@ class TableViewController: BaseViewController<Table> {
let button = Button() let button = Button()
button.text = "Testing" button.text = "Testing"
rows.append([TableItemModel(bottomLine: .secondary, component:Toggle()), rows.append(TableRowModel(columns: [TableItemModel(bottomLine: .secondary, component:Toggle()),
TableItemModel(bottomLine: .secondary, component:titleLockUp), TableItemModel(bottomLine: .secondary, component:titleLockUp),
TableItemModel(bottomLine: .secondary, component: button)]) TableItemModel(bottomLine: .secondary, component: button)]))
///Fifth row ///Fifth row
@ -172,9 +178,9 @@ class TableViewController: BaseViewController<Table> {
let image = UIImage(named: "clean-surface") let image = UIImage(named: "clean-surface")
let imageView = UIImageView(image: image) let imageView = UIImageView(image: image)
rows.append([TableItemModel(bottomLine: .secondary, component:textArea), rows.append(TableRowModel(columns: [TableItemModel(bottomLine: .secondary, component:textArea),
TableItemModel(bottomLine: .secondary, component:imageView), TableItemModel(bottomLine: .secondary, component:imageView),
TableItemModel(bottomLine: .secondary, component:trailingToolTip)]) TableItemModel(bottomLine: .secondary, component:trailingToolTip)]))
} }