added sample
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
9ff3351842
commit
62ee98c34e
@ -306,6 +306,7 @@
|
|||||||
EA89203E28B66CE2006B9984 /* ScrollViewController */,
|
EA89203E28B66CE2006B9984 /* ScrollViewController */,
|
||||||
EA3C3BB228996775000CA526 /* MenuViewController.swift */,
|
EA3C3BB228996775000CA526 /* MenuViewController.swift */,
|
||||||
EAD062A22A3913920015965D /* DropShawdowViewController.swift */,
|
EAD062A22A3913920015965D /* DropShawdowViewController.swift */,
|
||||||
|
EA297A672A02F5320031ED56 /* TableViewTestController.swift */,
|
||||||
EAB1D2C828AAAA1D00DAE764 /* BaseViewController.swift */,
|
EAB1D2C828AAAA1D00DAE764 /* BaseViewController.swift */,
|
||||||
EA4DB30328DCD25B00103EE3 /* BadgeViewController.swift */,
|
EA4DB30328DCD25B00103EE3 /* BadgeViewController.swift */,
|
||||||
EAD062AC2A3B86950015965D /* BadgeIndicatorViewController.swift */,
|
EAD062AC2A3B86950015965D /* BadgeIndicatorViewController.swift */,
|
||||||
@ -336,8 +337,7 @@
|
|||||||
EA5E30542950EA6E0082B959 /* TitleLockupViewController.swift */,
|
EA5E30542950EA6E0082B959 /* TitleLockupViewController.swift */,
|
||||||
EA3C3BB328996775000CA526 /* ToggleViewController.swift */,
|
EA3C3BB328996775000CA526 /* ToggleViewController.swift */,
|
||||||
EAB2375F29E88D5D00AABE9A /* TooltipViewController.swift */,
|
EAB2375F29E88D5D00AABE9A /* TooltipViewController.swift */,
|
||||||
EAB2376B29E9E74900AABE9A /* TrailingTooltipLabel.swift */,
|
EAB2376B29E9E74900AABE9A /* TrailingTooltipLabelViewController.swift */,
|
||||||
EA297A672A02F5320031ED56 /* TableViewTestController.swift */,
|
|
||||||
);
|
);
|
||||||
path = ViewControllers;
|
path = ViewControllers;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
|||||||
@ -107,3 +107,14 @@ class BadgeViewController: BaseViewController<Badge> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension BadgeViewController: Componentable {
|
||||||
|
static func getComponent() -> TestViewWrapper {
|
||||||
|
let component = Self.makeComponent()
|
||||||
|
component.fillColor = .red
|
||||||
|
component.text = "Terms and conditions"
|
||||||
|
component.maxWidth = 70
|
||||||
|
component.numberOfLines = 3
|
||||||
|
return TestViewWrapper(component: component, isTrailing: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -71,6 +71,10 @@ public class BaseViewController<Component: UIView>: UIViewController, Initable {
|
|||||||
print("\(Self.self) deinit")
|
print("\(Self.self) deinit")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static func makeComponent() -> Component {
|
||||||
|
Component()
|
||||||
|
}
|
||||||
|
|
||||||
private let edgeSpacing = 16.0
|
private let edgeSpacing = 16.0
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -64,19 +64,7 @@ class MenuCell: UITableViewCell {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class MenuViewController: UITableViewController, TooltipLaunchable {
|
class MenuViewController: UITableViewController, TooltipLaunchable {
|
||||||
override func viewDidLoad() {
|
static let items: [MenuComponent] = [
|
||||||
title = "VDS Sample: Build \(Bundle.main.build ?? "none")"
|
|
||||||
let tooltip = VDS.Tooltip()
|
|
||||||
let bundle = VDS.Bundle(for: VDS.Badge.self)
|
|
||||||
tooltip.title = "Release Notes: \(bundle.build ?? "")"
|
|
||||||
tooltip.content = bundle.contents("ReleaseNotes")
|
|
||||||
navigationItem.rightBarButtonItem = UIBarButtonItem(customView: tooltip) // UIBarButtonItem(barButtonSystemItem: .compose, target: self, action: #selector(buildInfoTapped))
|
|
||||||
super.viewDidLoad()
|
|
||||||
overrideUserInterfaceStyle = .light
|
|
||||||
tableView.register(MenuCell.self, forCellReuseIdentifier: "cell")
|
|
||||||
}
|
|
||||||
|
|
||||||
let items: [MenuComponent] = [
|
|
||||||
MenuComponent(title: "DropShadow Tester", completed: true, viewController: DropShadowViewController.self),
|
MenuComponent(title: "DropShadow Tester", completed: true, viewController: DropShadowViewController.self),
|
||||||
MenuComponent(title: "TableView Tester", completed: true, viewController: TableViewTestController.self),
|
MenuComponent(title: "TableView Tester", completed: true, viewController: TableViewTestController.self),
|
||||||
MenuComponent(title: "Badge", completed: true, viewController: BadgeViewController.self),
|
MenuComponent(title: "Badge", completed: true, viewController: BadgeViewController.self),
|
||||||
@ -109,9 +97,24 @@ class MenuViewController: UITableViewController, TooltipLaunchable {
|
|||||||
MenuComponent(title: "Toggle", completed: true, viewController: ToggleViewController.self),
|
MenuComponent(title: "Toggle", completed: true, viewController: ToggleViewController.self),
|
||||||
MenuComponent(title: "Tooltip", completed: true, viewController: TooltipViewController.self),
|
MenuComponent(title: "Tooltip", completed: true, viewController: TooltipViewController.self),
|
||||||
MenuComponent(title: "TrailingTooltipLabel", completed: true, viewController: TrailingTooltipLabelViewController.self),
|
MenuComponent(title: "TrailingTooltipLabel", completed: true, viewController: TrailingTooltipLabelViewController.self),
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
var items: [MenuComponent] {
|
||||||
|
Self.items
|
||||||
|
}
|
||||||
|
|
||||||
|
override func viewDidLoad() {
|
||||||
|
title = "VDS Sample: Build \(Bundle.main.build ?? "none")"
|
||||||
|
let tooltip = VDS.Tooltip()
|
||||||
|
let bundle = VDS.Bundle(for: VDS.Badge.self)
|
||||||
|
tooltip.title = "Release Notes: \(bundle.build ?? "")"
|
||||||
|
tooltip.content = bundle.contents("ReleaseNotes")
|
||||||
|
navigationItem.rightBarButtonItem = UIBarButtonItem(customView: tooltip) // UIBarButtonItem(barButtonSystemItem: .compose, target: self, action: #selector(buildInfoTapped))
|
||||||
|
super.viewDidLoad()
|
||||||
|
overrideUserInterfaceStyle = .light
|
||||||
|
tableView.register(MenuCell.self, forCellReuseIdentifier: "cell")
|
||||||
|
}
|
||||||
|
|
||||||
override func numberOfSections(in tableView: UITableView) -> Int {
|
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,49 +8,17 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import UIKit
|
import UIKit
|
||||||
import VDS
|
import VDS
|
||||||
|
import VDSColorTokens
|
||||||
|
|
||||||
|
public typealias TestView = UIView
|
||||||
|
public typealias TestViewWrapper = (component: TestView, isTrailing: Bool)
|
||||||
protocol Componentable {
|
protocol Componentable {
|
||||||
func getCompontent() -> UIView
|
static func getComponent() -> TestViewWrapper
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
public class TableViewTestController: UITableViewController, Initable {
|
||||||
|
|
||||||
var controllers:[UIViewController] = []
|
var components:[TestViewWrapper] = []
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Initializers
|
// MARK: - Initializers
|
||||||
@ -65,49 +33,77 @@ public class TableViewTestController: UITableViewController, Initable {
|
|||||||
|
|
||||||
public override func viewDidLoad() {
|
public override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
let menus = MenuViewController()
|
MenuViewController.items.forEach { menuItem in
|
||||||
controllers = menus.items.compactMap({ menuItem in
|
if let componentable = menuItem.viewController as? Componentable.Type {
|
||||||
guard let vc = menuItem.viewController as? Initable.Type,
|
components.append(componentable.getComponent())
|
||||||
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.register(VDSCell.self, forCellReuseIdentifier: "cell")
|
||||||
tableView.allowsSelection = false
|
tableView.allowsSelection = false
|
||||||
tableView.estimatedRowHeight = 100
|
tableView.estimatedRowHeight = 100
|
||||||
|
tableView.separatorStyle = .none
|
||||||
tableView.rowHeight = UITableView.automaticDimension
|
tableView.rowHeight = UITableView.automaticDimension
|
||||||
tableView.reloadData()
|
tableView.reloadData()
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func numberOfSections(in tableView: UITableView) -> Int {
|
public override func numberOfSections(in tableView: UITableView) -> Int {
|
||||||
controllers.count
|
components.count
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
public override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
||||||
let vc = controllers[section]
|
let header = UIView().with { $0.backgroundColor = VDSColor.paletteGray44 }
|
||||||
return vc.title
|
let label = Label().with {
|
||||||
|
$0.text = "\(type(of: components[section].component))"
|
||||||
|
$0.surface = .dark
|
||||||
|
$0.textStyle = .boldTitleSmall
|
||||||
|
}
|
||||||
|
header.addSubview(label)
|
||||||
|
label.pinTrailing(16)
|
||||||
|
label.pinLeading(16)
|
||||||
|
label.centerYAnchor.constraint(equalTo: header.centerYAnchor).activate()
|
||||||
|
return header
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
||||||
|
40
|
||||||
|
}
|
||||||
|
|
||||||
public override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
public override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
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() }
|
guard let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as? VDSCell else { return UITableViewCell() }
|
||||||
let component = vc.getCompontent()
|
let wrapper = components[indexPath.row]
|
||||||
cell.subviews.forEach { $0.removeFromSuperview() }
|
cell.component = wrapper.component
|
||||||
cell.addSubview(component)
|
cell.isTrailing = wrapper.isTrailing
|
||||||
component.pinToSuperView()
|
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class VDSCell: UITableViewCell, AppleGuidlinesTouchable {
|
public class VDSCell: UITableViewCell, AppleGuidlinesTouchable {
|
||||||
|
public var isTrailing: Bool = true
|
||||||
|
public var component: TestView? {
|
||||||
|
didSet {
|
||||||
|
guard let component else { return }
|
||||||
|
contentView.addSubview(.makeWrapper(for: component, edgeSpacing: 16, isTrailing: isTrailing))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
|
override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
|
||||||
Self.acceptablyOutsideBounds(point: point, bounds: bounds)
|
Self.acceptablyOutsideBounds(point: point, bounds: bounds)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override var intrinsicContentSize: CGSize {
|
||||||
|
guard let component else { return .zero }
|
||||||
|
return component.intrinsicContentSize
|
||||||
|
}
|
||||||
|
|
||||||
|
public override func prepareForReuse() {
|
||||||
|
super.prepareForReuse()
|
||||||
|
contentView.subviews.forEach { $0.removeFromSuperview() }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user