120 lines
4.9 KiB
Swift
120 lines
4.9 KiB
Swift
//
|
||
// TableViewTestController.swift
|
||
// VDSSample
|
||
//
|
||
// Created by Matt Bruce on 5/3/23.
|
||
//
|
||
|
||
import Foundation
|
||
import UIKit
|
||
import VDS
|
||
|
||
protocol Componentable {
|
||
func getCompontent() -> UIView
|
||
}
|
||
|
||
extension BaseViewController: Componentable {
|
||
func getCompontent() -> UIView { contentTopView.removeFromSuperview(); return contentTopView }
|
||
}
|
||
|
||
//public class TableViewTestController: UIViewController, Initable {
|
||
// let component = TrailingTooltipLabel()
|
||
//
|
||
// public override func viewDidLoad() {
|
||
// super.viewDidLoad()
|
||
//
|
||
// component.layer.borderColor = UIColor.red.cgColor
|
||
// component.label.layer.borderWidth = 1
|
||
// component.labelText = "Label Component"
|
||
// component.labelTextStyle = .titleLarge
|
||
// component.tooltipTitle = "5G Ultra Wideband is available in your area."
|
||
// component.tooltipContent = "$799.99 (128 GB only) device payment purchase w/new or upgrade smartphone line on postpaid 5G Unlimited plans only req'd. Less up to $800 trade-in/promo credit applied over 36 mos.; promo credit ends if eligibility req’s are no longer met; 0% APR. Trade-in conditions apply.$799.99 (128 GB only) device payment purchase w/new or upgrade smartphone line on postpaid 5G Unlimited plans only req'd. Less up to $800 trade-in."
|
||
//
|
||
// view.addSubview(component)
|
||
// view.backgroundColor = .white
|
||
// NSLayoutConstraint.activate([
|
||
// component.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 16),
|
||
// component.leftAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leftAnchor, constant: 16),
|
||
// component.rightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.rightAnchor)
|
||
// ])
|
||
// }
|
||
//
|
||
// public override func viewDidAppear(_ animated: Bool) {
|
||
// super.viewDidAppear(animated)
|
||
//
|
||
// DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
||
// self.component.tooltipTitle = "q234"
|
||
// }
|
||
// }
|
||
//}
|
||
|
||
public class TableViewTestController: UITableViewController, Initable {
|
||
|
||
var controllers:[UIViewController] = []
|
||
|
||
//--------------------------------------------------
|
||
// MARK: - Initializers
|
||
//--------------------------------------------------
|
||
required public init() {
|
||
super.init(nibName: nil, bundle: nil)
|
||
}
|
||
|
||
required init?(coder: NSCoder) {
|
||
fatalError("init(coder:) has not been implemented")
|
||
}
|
||
|
||
public override func viewDidLoad() {
|
||
super.viewDidLoad()
|
||
let menus = MenuViewController()
|
||
controllers = menus.items.compactMap({ menuItem in
|
||
guard let vc = menuItem.viewController as? Initable.Type,
|
||
let controller = vc.init() as? UIViewController,
|
||
menuItem.viewController != Self.self else { return nil }
|
||
|
||
controller.title = menuItem.title
|
||
controller.viewDidLoad()
|
||
return controller
|
||
})
|
||
tableView.register(VDSCell.self, forCellReuseIdentifier: "cell")
|
||
tableView.allowsSelection = false
|
||
tableView.estimatedRowHeight = 100
|
||
tableView.rowHeight = UITableView.automaticDimension
|
||
tableView.reloadData()
|
||
}
|
||
|
||
public override func numberOfSections(in tableView: UITableView) -> Int {
|
||
1 //controllers.count
|
||
}
|
||
|
||
public override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
||
let vc = controllers[section]
|
||
return vc.title
|
||
}
|
||
|
||
public override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||
1
|
||
}
|
||
|
||
public override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||
guard let vc = controllers[indexPath.section] as? Componentable, let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as? VDSCell else { return UITableViewCell() }
|
||
//let component = vc.getCompontent()
|
||
let component = TrailingTooltipLabel()
|
||
component.labelText = "Label Component"
|
||
component.labelTextStyle = .bodyLarge
|
||
component.tooltipTitle = "5G Ultra Wideband is available in your area."
|
||
component.tooltipContent = "$799.99 (128 GB only) device payment purchase w/new or upgrade smartphone line on postpaid 5G Unlimited plans only req'd. Less up to $800 trade-in/promo credit applied over 36 mos.; promo credit ends if eligibility req’s are no longer met; 0% APR. Trade-in conditions apply.$799.99 (128 GB only) device payment purchase w/new or upgrade smartphone line on postpaid 5G Unlimited plans only req'd. Less up to $800 trade-in."
|
||
|
||
cell.subviews.forEach { $0.removeFromSuperview() }
|
||
cell.addSubview(component)
|
||
component.pinToSuperView()
|
||
return cell
|
||
}
|
||
}
|
||
|
||
public class VDSCell: UITableViewCell, AppleGuidlinesTouchable {
|
||
override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
|
||
Self.acceptablyOutsideBounds(point: point, bounds: bounds)
|
||
}
|
||
}
|
||
|