Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#12] HandyTabs & Main화면 #32

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions Handy/Handy-Storybook/Atom/TabsViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
//
// TabsViewController.swift
// Handy
//
// Created by chongin on 12/29/24.
//

import Handy
import UIKit

final class TabsViewController: BaseViewController {
var tabs: [(title: String, viewController: UIViewController)]

private let handyTabs: HandyTabs = {
let tabs = HandyTabs(sizeType: .small)
return tabs
}()

private let addingTabButton: HandyFab = {
let button = HandyFab()
button.iconImage = .add
return button
}()
Comment on lines +19 to +23
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금 HandyFab 관련된 레이아웃 경고가 엄청 많이 뜨는 것 같은데 혹시 이거 때문일까요??

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HandyFab 자체 경고인 것 같아요..!! ㅠ

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wjdalswl 혹시 레이아웃 경고 확인 해볼 수 있을까요?


init(_ tabCount: Int) {
self.tabs = [
{
let viewController = SnackbarViewController()
return ("SnackbarViewController", viewController)
}(),
{
let viewController = LabelViewController()
return ("LabelViewController", viewController)
}(),
{
let viewController = FabViewController()
return ("FabViewController", viewController)
}(),
{
let viewController = HandyBoxButtonViewController()
return ("HandyBoxButtonViewController", viewController)
}(),
{
let viewController = ChipViewController()
return ("ChipViewController", viewController)
}(),
{
let viewController = DividerViewController()
return ("DividerViewController", viewController)
}(),
{
let viewController = CheckBoxViewController()
return ("CheckBoxViewController", viewController)
}(),
{
let viewController = RadioButtonViewController()
return ("RadioButtonViewController", viewController)
}(),
{
let viewController = HansySwitchViewController()
return ("HansySwitchViewController", viewController)
}(),
][..<tabCount].map { $0 }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

주어진 정적 배열 중 인자로 받는 개수까지만 표현되도록 했습니다.

super.init(nibName: nil, bundle: nil)
}

@MainActor required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
super.viewDidLoad()
addingTabButton.addTarget(self, action: #selector(addingTabButtonDidTap(_:)), for: .touchUpInside)
self.handyTabs.tabs = self.tabs
}

@objc private func addingTabButtonDidTap(_ sender: UIButton) {
let randomViewController = UIViewController()
randomViewController.view.backgroundColor = UIColor.init(red: .random(in: 0...1), green: .random(in: 0...1), blue: .random(in: 0...1), alpha: 1)
handyTabs.tabs.append(("newTab!!", randomViewController))
}

override func setViewHierarchies() {
self.addChild(handyTabs)
self.view.addSubview(handyTabs.view)
self.view.addSubview(addingTabButton)
}

override func setViewLayouts() {
handyTabs.view.snp.makeConstraints {
$0.edges.equalTo(self.view.safeAreaLayoutGuide)
}

addingTabButton.snp.makeConstraints {
$0.trailing.bottom.equalTo(self.view.safeAreaLayoutGuide).inset(32)
$0.width.height.equalTo(100)
}
}
}
2 changes: 1 addition & 1 deletion Handy/Handy-Storybook/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 = HandyListViewController()
window?.rootViewController = UINavigationController(rootViewController: MainViewController())
window?.makeKeyAndVisible()
}

Expand Down
90 changes: 90 additions & 0 deletions Handy/Handy-Storybook/Storybook/MainViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//
// 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(2개)", TabsViewController(2))),
.init(("TabsViewController(3개)", TabsViewController(3))),
.init(("TabsViewController(9개)", TabsViewController(9))),
.init(("HandyListViewController", HandyListViewController())),
]

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<VC: UIViewController>(_ component: (title: String, viewController: VC)) {
self.title = component.title
self.viewController = component.viewController as UIViewController
}
}
30 changes: 29 additions & 1 deletion Handy/Handy.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
02ED764C2C57BD09001569F1 /* HandyBoxButtonViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02ED764B2C57BD09001569F1 /* HandyBoxButtonViewController.swift */; };
2D41E8142C5A21930043161D /* FabViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D41E8132C5A21930043161D /* FabViewController.swift */; };
2D41E8162C5A21B50043161D /* HandyFab.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D41E8152C5A21B50043161D /* HandyFab.swift */; };
6F1A18D02D26606D004C6083 /* CALayer+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F1A18CF2D26606A004C6083 /* CALayer+.swift */; };
6FD1A1802D213129001E6F2E /* TabsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FD1A17F2D21311C001E6F2E /* TabsViewController.swift */; };
6FE73E942D23C52F00E06422 /* HandyTabs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FE73E932D23C52C00E06422 /* HandyTabs.swift */; };
6FE73E962D23C55900E06422 /* HandyTabCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FE73E952D23C55900E06422 /* HandyTabCell.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 */; };
Expand Down Expand Up @@ -121,6 +126,11 @@
02ED764B2C57BD09001569F1 /* HandyBoxButtonViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HandyBoxButtonViewController.swift; sourceTree = "<group>"; };
2D41E8132C5A21930043161D /* FabViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FabViewController.swift; sourceTree = "<group>"; };
2D41E8152C5A21B50043161D /* HandyFab.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HandyFab.swift; sourceTree = "<group>"; };
6F1A18CF2D26606A004C6083 /* CALayer+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CALayer+.swift"; sourceTree = "<group>"; };
6FD1A17F2D21311C001E6F2E /* TabsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabsViewController.swift; sourceTree = "<group>"; };
6FE73E932D23C52C00E06422 /* HandyTabs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HandyTabs.swift; sourceTree = "<group>"; };
6FE73E952D23C55900E06422 /* HandyTabCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HandyTabCell.swift; sourceTree = "<group>"; };
6FE73E972D23D6E500E06422 /* MainViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = "<group>"; };
A56B3DE12C4E51D300C3610A /* HandyChip.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HandyChip.swift; sourceTree = "<group>"; };
A5A12A7C2C57A6C200996916 /* ChipViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChipViewController.swift; sourceTree = "<group>"; };
A5F6D36A2C96F32D00FB961F /* HandyDivider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HandyDivider.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -183,6 +193,7 @@
025776482C4EB0E700272EC6 /* Atom */ = {
isa = PBXGroup;
children = (
6FD1A17F2D21311C001E6F2E /* TabsViewController.swift */,
02150E4B2CCABAE500EE690E /* SnackbarViewController.swift */,
025776382C4EA98C00272EC6 /* LabelViewController.swift */,
2D41E8132C5A21930043161D /* FabViewController.swift */,
Expand Down Expand Up @@ -217,6 +228,7 @@
0257765A2C4EB9B800272EC6 /* Storybook */ = {
isa = PBXGroup;
children = (
6FE73E972D23D6E500E06422 /* MainViewController.swift */,
0257763F2C4EA98E00272EC6 /* LaunchScreen.storyboard */,
0257765B2C4EB9C700272EC6 /* Base */,
);
Expand Down Expand Up @@ -244,7 +256,8 @@
029E47FE2C49FD2E00D2F3B7 /* Atom */ = {
isa = PBXGroup;
children = (
02ED762F2C52849A001569F1 /* Button */,
6FE73E922D23C51600E06422 /* HandyTabs */,
02ED762F2C52849A001569F1 /* HandyButton */,
029E47FC2C49FD1A00D2F3B7 /* HandyLabel.swift */,
2D41E8152C5A21B50043161D /* HandyFab.swift */,
A56B3DE12C4E51D300C3610A /* HandyChip.swift */,
Expand Down Expand Up @@ -325,11 +338,21 @@
02ED76482C577998001569F1 /* Extension */ = {
isa = PBXGroup;
children = (
6F1A18CF2D26606A004C6083 /* CALayer+.swift */,
02ED76492C5779C3001569F1 /* UIImage+.swift */,
);
path = Extension;
sourceTree = "<group>";
};
6FE73E922D23C51600E06422 /* HandyTabs */ = {
isa = PBXGroup;
children = (
6FE73E952D23C55900E06422 /* HandyTabCell.swift */,
6FE73E932D23C52C00E06422 /* HandyTabs.swift */,
);
path = HandyTabs;
sourceTree = "<group>";
};
E5650D412C4D30B9002790CC /* Asset */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -479,12 +502,14 @@
A5A12A7E2C57A6D900996916 /* ChipViewController.swift in Sources */,
A5A12A7F2C57A92000996916 /* HandySematic.swift in Sources */,
A5F6D36D2C97099C00FB961F /* DividerViewController.swift in Sources */,
6FE73E982D23D7A900E06422 /* MainViewController.swift in Sources */,
021C77042CEA504B00AC7D7D /* HandyListViewController.swift in Sources */,
025776392C4EA98C00272EC6 /* LabelViewController.swift in Sources */,
0257765D2C4EB9EF00272EC6 /* BaseViewController.swift in Sources */,
02ED764C2C57BD09001569F1 /* HandyBoxButtonViewController.swift in Sources */,
E51FBFA22C54CD350097B0DA /* RadioButtonViewController.swift in Sources */,
E51FBF9B2C5399A00097B0DA /* CheckBoxViewController.swift in Sources */,
6FD1A1802D213129001E6F2E /* TabsViewController.swift in Sources */,
025776352C4EA98C00272EC6 /* AppDelegate.swift in Sources */,
02697A262C99DDA30027A362 /* HansySwitchViewController.swift in Sources */,
025776372C4EA98C00272EC6 /* SceneDelegate.swift in Sources */,
Expand All @@ -501,15 +526,18 @@
02697A242C99D7230027A362 /* HandySwitch.swift in Sources */,
02150E4A2CC8D7AB00EE690E /* HandySnackbar.swift in Sources */,
E5D02B002C480A180056CE7B /* HandyPrimitive.swift in Sources */,
6FE73E942D23C52F00E06422 /* HandyTabs.swift in Sources */,
E5D02AFD2C46C5A70056CE7B /* HandySematic.swift in Sources */,
E5D02B002C480A180056CE7B /* HandyPrimitive.swift in Sources */,
E51FBFA02C54CB260097B0DA /* HandyRadioButton.swift in Sources */,
E5669A3F2C443E7300DABC21 /* HandyBasicColor.swift in Sources */,
02ED76312C5284BB001569F1 /* HandyButtonProtocol.swift in Sources */,
02ED76352C5284F3001569F1 /* HandyTextButton.swift in Sources */,
6F1A18D02D26606D004C6083 /* CALayer+.swift in Sources */,
02BCB2302CDF417500D0C796 /* HandyListItem.swift in Sources */,
A5F6D36B2C96F32D00FB961F /* HandyDivider.swift in Sources */,
02BDB7FC2C3E99920050FB67 /* HandyFont.swift in Sources */,
6FE73E962D23C55900E06422 /* HandyTabCell.swift in Sources */,
02ED764A2C5779C3001569F1 /* UIImage+.swift in Sources */,
029E48002C49FD4000D2F3B7 /* HandyTypography.swift in Sources */,
E5650D432C4D326D002790CC /* HandyCheckBox.swift in Sources */,
Expand Down

This file was deleted.

Loading