Minor refactoring changes.

This commit is contained in:
Sumanth Nadigadda 2024-05-27 10:56:09 +05:30
parent e51b4dfe37
commit 7a47221d62

View File

@ -8,6 +8,7 @@
import Foundation import Foundation
import VDS import VDS
import UIKit import UIKit
import VDSTokens
class TableViewController: BaseViewController<Table> { class TableViewController: BaseViewController<Table> {
@ -15,7 +16,9 @@ class TableViewController: BaseViewController<Table> {
var fillContainer = Toggle() var fillContainer = Toggle()
var customColumnWidthSize = NumericField() var customColumnWidthSize = NumericField().with {
$0.placeholder = "Minimum 50px"
}
lazy var headerLineStylePicker = { lazy var headerLineStylePicker = {
PickerSelectorView(title: "primary", picker: self.picker, items: Line.Style.allCases) PickerSelectorView(title: "primary", picker: self.picker, items: Line.Style.allCases)
@ -46,6 +49,7 @@ class TableViewController: BaseViewController<Table> {
addFormRow(label: "Custom column size", view: customColumnWidthSize) addFormRow(label: "Custom column size", view: customColumnWidthSize)
fillContainer.isOn = component.fillContainer fillContainer.isOn = component.fillContainer
updateTextFieldStatus(enable: !fillContainer.isOn)
addContentTopView(view: component) addContentTopView(view: component)
@ -55,14 +59,13 @@ 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?.customColumnWidthSize.isEnabled = !sender.isOn self?.updateTextFieldStatus(enable:!sender.isOn)
} }
customColumnWidthSize.textPublisher.sink { [weak self] text in customColumnWidthSize.numberPublisher.sink { [weak self] text in
if let width = NumberFormatter().number(from: text), let count = self?.component.tableHeader.first?.count { if let count = self?.component.tableHeader.first?.count, let text, text.intValue > 50 {
self?.component.columnWidths = Array(repeating: CGFloat(truncating: width), count: count) self?.component.columnWidths = Array(repeating: CGFloat(truncating: text), count: count)
} }
}.store(in: &subscribers) }.store(in: &subscribers)
} }
@ -104,6 +107,11 @@ class TableViewController: BaseViewController<Table> {
} }
} }
func updateTextFieldStatus(enable: Bool) {
customColumnWidthSize.isEnabled = enable
customColumnWidthSize.backgroundColor = enable ? UIColor.white : VDSColor.paletteGray85
}
func setupModel() { func setupModel() {
///Header row ///Header row
self.component.tableHeader = [[TableItemModel(bottomLine: .primary, component: Label().with { $0.text = ""}), self.component.tableHeader = [[TableItemModel(bottomLine: .primary, component: Label().with { $0.text = ""}),