diff --git a/VDSSample.xcodeproj/project.pbxproj b/VDSSample.xcodeproj/project.pbxproj index 86fbec2..4809ce8 100644 --- a/VDSSample.xcodeproj/project.pbxproj +++ b/VDSSample.xcodeproj/project.pbxproj @@ -39,6 +39,7 @@ EA0D1C312A673F3500E5C127 /* RadioButtonViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA0D1C302A673F3500E5C127 /* RadioButtonViewController.swift */; }; EA0D1C332A673FD400E5C127 /* RadioButtonItemViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA0D1C322A673FD400E5C127 /* RadioButtonItemViewController.swift */; }; EA0FC2C12912DC5500DF80B4 /* TextLinkCaretViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA0FC2C02912DC5500DF80B4 /* TextLinkCaretViewController.swift */; }; + EA297A682A02F5320031ED56 /* TableViewTestController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA297A672A02F5320031ED56 /* TableViewTestController.swift */; }; EA3C3B9D289966EF000CA526 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3C3B9C289966EF000CA526 /* AppDelegate.swift */; }; EA3C3B9F289966EF000CA526 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3C3B9E289966EF000CA526 /* SceneDelegate.swift */; }; EA3C3BA4289966EF000CA526 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EA3C3BA2289966EF000CA526 /* Main.storyboard */; }; @@ -132,6 +133,7 @@ EA0D1C302A673F3500E5C127 /* RadioButtonViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioButtonViewController.swift; sourceTree = ""; }; EA0D1C322A673FD400E5C127 /* RadioButtonItemViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioButtonItemViewController.swift; sourceTree = ""; }; EA0FC2C02912DC5500DF80B4 /* TextLinkCaretViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextLinkCaretViewController.swift; sourceTree = ""; }; + EA297A672A02F5320031ED56 /* TableViewTestController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewTestController.swift; sourceTree = ""; }; EA3C3B99289966EF000CA526 /* VDSSample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = VDSSample.app; sourceTree = BUILT_PRODUCTS_DIR; }; EA3C3B9C289966EF000CA526 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; EA3C3B9E289966EF000CA526 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; @@ -334,7 +336,8 @@ EA5E30542950EA6E0082B959 /* TitleLockupViewController.swift */, EA3C3BB328996775000CA526 /* ToggleViewController.swift */, EAB2375F29E88D5D00AABE9A /* TooltipViewController.swift */, - EAB2376B29E9E74900AABE9A /* TrailingTooltipLabelViewController.swift */, + EAB2376B29E9E74900AABE9A /* TrailingTooltipLabel.swift */, + EA297A672A02F5320031ED56 /* TableViewTestController.swift */, ); path = ViewControllers; sourceTree = ""; @@ -485,6 +488,7 @@ EAB5FEEF2927E28400998C17 /* ButtonGroupViewController.swift in Sources */, EA89204C28B66CE2006B9984 /* ScrollWrapperView.swift in Sources */, EA89205128B68307006B9984 /* TextField.swift in Sources */, + EA297A682A02F5320031ED56 /* TableViewTestController.swift in Sources */, 44604AD929CE1CF900E62B51 /* LineViewController.swift in Sources */, EA3C3BB528996775000CA526 /* StoryboardInitable.swift in Sources */, EA89201928B56DF5006B9984 /* RadioBoxGroupViewController.swift in Sources */, diff --git a/VDSSample/ViewControllers/MenuViewController.swift b/VDSSample/ViewControllers/MenuViewController.swift index 3d858b8..a1de6f8 100644 --- a/VDSSample/ViewControllers/MenuViewController.swift +++ b/VDSSample/ViewControllers/MenuViewController.swift @@ -78,6 +78,7 @@ class MenuViewController: UITableViewController, TooltipLaunchable { let items: [MenuComponent] = [ MenuComponent(title: "DropShadow Tester", completed: true, viewController: DropShadowViewController.self), + MenuComponent(title: "TableView Tester", completed: true, viewController: TableViewTestController.self), MenuComponent(title: "Badge", completed: true, viewController: BadgeViewController.self), MenuComponent(title: "Badge Indicator", completed: true, viewController: BadgeIndicatorViewController.self), MenuComponent(title: "Button", completed: true, viewController: ButtonViewController.self), diff --git a/VDSSample/ViewControllers/TableViewTestController.swift b/VDSSample/ViewControllers/TableViewTestController.swift new file mode 100644 index 0000000..6d48cd3 --- /dev/null +++ b/VDSSample/ViewControllers/TableViewTestController.swift @@ -0,0 +1,113 @@ +// +// 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 { + 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() + 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) + } +} +