made simple

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-08-21 17:36:59 -05:00
parent 17f074b949
commit 7f649ba5e6

View File

@ -95,8 +95,6 @@ public class TableViewTestController: UIViewController, Initable, Surfaceable {
var components:[ComponentSample] = [] var components:[ComponentSample] = []
lazy var tableView = UITableView().with { lazy var tableView = UITableView().with {
$0.translatesAutoresizingMaskIntoConstraints = false $0.translatesAutoresizingMaskIntoConstraints = false
$0.delegate = self
$0.dataSource = self
} }
public var surface: Surface = .light { public var surface: Surface = .light {
@ -128,10 +126,10 @@ public class TableViewTestController: UIViewController, Initable, Surfaceable {
} }
} }
let toggleSample = ComponentSample(component: toggle, leadingPinningType: .none) let toggleSample = ComponentSample(component: toggle, leadingPinningType: .none)
let wrapper = UIView().with { $0.translatesAutoresizingMaskIntoConstraints = false } let wrapper = UIView().with { $0.translatesAutoresizingMaskIntoConstraints = false }
wrapper.addSubview(toggle) wrapper.addSubview(toggle)
toggleSample.pin(edgeInset: .init(top: 5, left: 5, bottom: 5, right: 5)) toggleSample.pin(edgeInset: .init(top: 5, left: 0, bottom: 5, right: 16))
let stackView = UIStackView(arrangedSubviews: [wrapper, tableView]).with { let stackView = UIStackView(arrangedSubviews: [wrapper, tableView]).with {
$0.translatesAutoresizingMaskIntoConstraints = false $0.translatesAutoresizingMaskIntoConstraints = false
@ -161,7 +159,7 @@ public class TableViewTestController: UIViewController, Initable, Surfaceable {
MenuComponent(title: "TextLink", completed: true, viewController: TextLinkViewController.self), MenuComponent(title: "TextLink", completed: true, viewController: TextLinkViewController.self),
MenuComponent(title: "TextLinkCaret", completed: true, viewController: TextLinkCaretViewController.self), MenuComponent(title: "TextLinkCaret", completed: true, viewController: TextLinkCaretViewController.self),
MenuComponent(title: "TitleLockup", completed: true, viewController: TitleLockupViewController.self), MenuComponent(title: "TitleLockup", completed: true, viewController: TitleLockupViewController.self),
MenuComponent(title: "Tooltip", completed: true, viewController: TooltipViewController.self) MenuComponent(title: "Tooltip", completed: true, viewController: TooltipViewController.self),
] ]
items.forEach { menuItem in items.forEach { menuItem in
@ -170,15 +168,12 @@ public class TableViewTestController: UIViewController, Initable, Surfaceable {
} }
} }
tableView.register(VDSCell.self, forCellReuseIdentifier: "cell")
tableView.allowsSelection = false tableView.allowsSelection = false
tableView.estimatedRowHeight = 45 tableView.estimatedRowHeight = 20
tableView.rowHeight = UITableView.automaticDimension
tableView.separatorStyle = .singleLine tableView.separatorStyle = .singleLine
} tableView.delegate = self
tableView.dataSource = self
public override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
tableView.reloadData()
} }
public func refresh() { public func refresh() {
@ -200,31 +195,14 @@ extension TableViewTestController : UITableViewDelegate, UITableViewDataSource {
} }
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as? VDSCell else { return UITableViewCell() } let cell = UITableViewCell()
cell.prepareForReuse() let sample = components[indexPath.row]
cell.surface = surface var component = sample.component
cell.sample = components[indexPath.row] component.surface = surface
cell.contentView.addSubview(component)
sample.pin(edgeInset: .init(top: 16, left: 16, bottom: 16, right: 16))
cell.backgroundColor = surface.color
return cell return cell
} }
} }
public class VDSCell: UITableViewCell, Surfaceable {
public var surface: Surface = .light
public var sample: ComponentSample? {
didSet {
contentView.subviews.forEach { $0.removeFromSuperview() }
guard let sample else { return }
var component = sample.component
component.surface = surface
contentView.addSubview(component)
sample.pin(edgeInset: .init(top: 16, left: 16, bottom: 16, right: 16))
backgroundColor = surface.color
}
}
}