diff --git a/VDSSample/ViewControllers/TableViewTestController.swift b/VDSSample/ViewControllers/TableViewTestController.swift index 191791b..d5bff3a 100644 --- a/VDSSample/ViewControllers/TableViewTestController.swift +++ b/VDSSample/ViewControllers/TableViewTestController.swift @@ -95,8 +95,6 @@ public class TableViewTestController: UIViewController, Initable, Surfaceable { var components:[ComponentSample] = [] lazy var tableView = UITableView().with { $0.translatesAutoresizingMaskIntoConstraints = false - $0.delegate = self - $0.dataSource = self } public var surface: Surface = .light { @@ -127,11 +125,11 @@ public class TableViewTestController: UIViewController, Initable, Surfaceable { self?.surface = toggle.isOn ? .dark : .light } } - - let toggleSample = ComponentSample(component: toggle, leadingPinningType: .none) + + let toggleSample = ComponentSample(component: toggle, leadingPinningType: .none) let wrapper = UIView().with { $0.translatesAutoresizingMaskIntoConstraints = false } 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 { $0.translatesAutoresizingMaskIntoConstraints = false @@ -161,7 +159,7 @@ public class TableViewTestController: UIViewController, Initable, Surfaceable { MenuComponent(title: "TextLink", completed: true, viewController: TextLinkViewController.self), MenuComponent(title: "TextLinkCaret", completed: true, viewController: TextLinkCaretViewController.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 @@ -170,17 +168,14 @@ public class TableViewTestController: UIViewController, Initable, Surfaceable { } } - tableView.register(VDSCell.self, forCellReuseIdentifier: "cell") tableView.allowsSelection = false - tableView.estimatedRowHeight = 45 + tableView.estimatedRowHeight = 20 + tableView.rowHeight = UITableView.automaticDimension tableView.separatorStyle = .singleLine + tableView.delegate = self + tableView.dataSource = self } - public override func viewDidAppear(_ animated: Bool) { - super.viewDidAppear(animated) - tableView.reloadData() - } - public func refresh() { DispatchQueue.main.async { [self] in tableView.beginUpdates() @@ -200,31 +195,14 @@ extension TableViewTestController : UITableViewDelegate, UITableViewDataSource { } public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - guard let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as? VDSCell else { return UITableViewCell() } - cell.prepareForReuse() - cell.surface = surface - cell.sample = components[indexPath.row] + let cell = UITableViewCell() + let sample = components[indexPath.row] + var component = sample.component + 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 } + } - -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 - } - } -} - -