diff --git a/Handy/Handy-Storybook/SceneDelegate.swift b/Handy/Handy-Storybook/SceneDelegate.swift index a10553a..a1095e0 100644 --- a/Handy/Handy-Storybook/SceneDelegate.swift +++ b/Handy/Handy-Storybook/SceneDelegate.swift @@ -16,7 +16,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { guard let windowScene = (scene as? UIWindowScene) else { return } window = UIWindow(frame: UIScreen.main.bounds) window?.windowScene = windowScene - window?.rootViewController = TabsViewController() + window?.rootViewController = UINavigationController(rootViewController: MainViewController()) window?.makeKeyAndVisible() } diff --git a/Handy/Handy-Storybook/Storybook/MainViewController.swift b/Handy/Handy-Storybook/Storybook/MainViewController.swift new file mode 100644 index 0000000..83e307b --- /dev/null +++ b/Handy/Handy-Storybook/Storybook/MainViewController.swift @@ -0,0 +1,87 @@ +// +// MainViewController.swift +// Handy +// +// Created by chongin on 12/31/24. +// + +import UIKit + +class MainViewController: UITableViewController { + + private let components: [HandyStorybookComponent] = [ + .init(("SnackbarViewController", SnackbarViewController())), + .init(("LabelViewController", LabelViewController())), + .init(("FabViewController", FabViewController())), + .init(("HandyBoxButtonViewController", HandyBoxButtonViewController())), + .init(("ChipViewController", ChipViewController())), + .init(("DividerViewController", DividerViewController())), + .init(("CheckBoxViewController", CheckBoxViewController())), + .init(("RadioButtonViewController", RadioButtonViewController())), + .init(("HansySwitchViewController", HansySwitchViewController())), + .init(("TabsViewController", TabsViewController())), + ] + + override func viewDidLoad() { + super.viewDidLoad() + + tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell") + } +} + +extension MainViewController { + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + switch section { + case 0: + return components.count + default: + return 0 + } + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + switch indexPath.section { + case 0: + let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) + let component = components[indexPath.row] + cell.textLabel?.text = component.title + return cell + default: + fatalError() + } + } + + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + switch indexPath.section { + case 0: + let component = components[indexPath.row] + navigationController?.pushViewController(component.viewController, animated: true) + default: + fatalError() + } + } + + override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { + switch section { + case 0: + return "Components" + default: + fatalError() + } + } +} + +struct HandyStorybookComponent { + let title: String + let viewController: UIViewController + + init(title: String, viewController: UIViewController) { + self.title = title + self.viewController = viewController + } + + init(_ component: (title: String, viewController: VC)) { + self.title = component.title + self.viewController = component.viewController as UIViewController + } +} diff --git a/Handy/Handy.xcodeproj/project.pbxproj b/Handy/Handy.xcodeproj/project.pbxproj index 242c8e3..ec89e93 100644 --- a/Handy/Handy.xcodeproj/project.pbxproj +++ b/Handy/Handy.xcodeproj/project.pbxproj @@ -41,6 +41,7 @@ 6FD1A1802D213129001E6F2E /* TabsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FD1A17F2D21311C001E6F2E /* TabsViewController.swift */; }; 6FE73E942D23C52F00E06422 /* HandyTabs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FE73E932D23C52C00E06422 /* HandyTabs.swift */; }; 6FE73E962D23C55900E06422 /* HandyTabComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FE73E952D23C55900E06422 /* HandyTabComponent.swift */; }; + 6FE73E982D23D7A900E06422 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FE73E972D23D6E500E06422 /* MainViewController.swift */; }; A56B3DE22C4E51D300C3610A /* HandyChip.swift in Sources */ = {isa = PBXBuildFile; fileRef = A56B3DE12C4E51D300C3610A /* HandyChip.swift */; }; A5A12A7E2C57A6D900996916 /* ChipViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5A12A7C2C57A6C200996916 /* ChipViewController.swift */; }; A5A12A7F2C57A92000996916 /* HandySematic.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5D02AFC2C46C5A70056CE7B /* HandySematic.swift */; }; @@ -121,6 +122,7 @@ 6FD1A17F2D21311C001E6F2E /* TabsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabsViewController.swift; sourceTree = ""; }; 6FE73E932D23C52C00E06422 /* HandyTabs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HandyTabs.swift; sourceTree = ""; }; 6FE73E952D23C55900E06422 /* HandyTabComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HandyTabComponent.swift; sourceTree = ""; }; + 6FE73E972D23D6E500E06422 /* MainViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = ""; }; A56B3DE12C4E51D300C3610A /* HandyChip.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HandyChip.swift; sourceTree = ""; }; A5A12A7C2C57A6C200996916 /* ChipViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChipViewController.swift; sourceTree = ""; }; A5F6D36A2C96F32D00FB961F /* HandyDivider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HandyDivider.swift; sourceTree = ""; }; @@ -208,6 +210,7 @@ 0257765A2C4EB9B800272EC6 /* Storybook */ = { isa = PBXGroup; children = ( + 6FE73E972D23D6E500E06422 /* MainViewController.swift */, 0257763F2C4EA98E00272EC6 /* LaunchScreen.storyboard */, 0257765B2C4EB9C700272EC6 /* Base */, ); @@ -479,6 +482,7 @@ A5A12A7E2C57A6D900996916 /* ChipViewController.swift in Sources */, A5A12A7F2C57A92000996916 /* HandySematic.swift in Sources */, A5F6D36D2C97099C00FB961F /* DividerViewController.swift in Sources */, + 6FE73E982D23D7A900E06422 /* MainViewController.swift in Sources */, 025776392C4EA98C00272EC6 /* LabelViewController.swift in Sources */, 0257765D2C4EB9EF00272EC6 /* BaseViewController.swift in Sources */, 02ED764C2C57BD09001569F1 /* HandyBoxButtonViewController.swift in Sources */,