From db070921d9c5838651d3b3b82b7dadaa67c6ad9f Mon Sep 17 00:00:00 2001 From: JH713 Date: Wed, 3 Jan 2024 18:54:27 +0900 Subject: [PATCH 1/8] =?UTF-8?q?feat:=20BoxListView=20=EA=B0=84=EB=8B=A8?= =?UTF-8?q?=ED=9E=88=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iBox/Sources/BaseViewController.swift | 1 + iBox/Sources/BoxList/BoxListView.swift | 65 +++++++++++++++++++ .../BoxList/BoxListViewController.swift | 18 +++++ iBox/Sources/BoxListViewController.swift | 29 --------- iBox/Sources/ColorPalette.swift | 40 ++++++++++++ iBox/Sources/MainTabBarController.swift | 8 +++ 6 files changed, 132 insertions(+), 29 deletions(-) create mode 100644 iBox/Sources/BoxList/BoxListView.swift create mode 100644 iBox/Sources/BoxList/BoxListViewController.swift delete mode 100644 iBox/Sources/BoxListViewController.swift create mode 100644 iBox/Sources/ColorPalette.swift diff --git a/iBox/Sources/BaseViewController.swift b/iBox/Sources/BaseViewController.swift index fd38cb5..c4be0a0 100644 --- a/iBox/Sources/BaseViewController.swift +++ b/iBox/Sources/BaseViewController.swift @@ -15,4 +15,5 @@ class BaseViewController: UIViewController { super.viewDidLoad() view.addSubview(baseView) } + } diff --git a/iBox/Sources/BoxList/BoxListView.swift b/iBox/Sources/BoxList/BoxListView.swift new file mode 100644 index 0000000..ef023f0 --- /dev/null +++ b/iBox/Sources/BoxList/BoxListView.swift @@ -0,0 +1,65 @@ +// +// BoxListView.swift +// iBox +// +// Created by 이지현 on 1/3/24. +// + +import UIKit + +class BoxListView: UIView { + + let folders = ["folder1", "folder2", "folder3"] + + private lazy var tableView = { + let tableView = UITableView() + tableView.dataSource = self + tableView.delegate = self + tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell") + + tableView.tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: frame.width, height: 10)) + tableView.separatorInset = UIEdgeInsets(top: 0, left: 15, bottom: 0, right: 15) + tableView.clipsToBounds = true + tableView.layer.cornerRadius = 20 + tableView.backgroundColor = ColorPalette.tableViewBackgroundColor + tableView.separatorColor = .secondaryLabel + return tableView + }() + + override init(frame: CGRect) { + super.init(frame: frame) + backgroundColor = ColorPalette.backgroundColor + + setupLayout() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + private func setupLayout() { + addSubview(tableView) + tableView.snp.makeConstraints { make in + make.top.equalTo(safeAreaLayoutGuide).inset(10) + make.leading.trailing.bottom.equalTo(safeAreaLayoutGuide).inset(20) + } + } +} + +extension BoxListView: UITableViewDataSource { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return folders.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) + cell.textLabel?.text = folders[indexPath.row] + cell.backgroundColor = .clear + return cell + } + +} + +extension BoxListView: UITableViewDelegate { + +} diff --git a/iBox/Sources/BoxList/BoxListViewController.swift b/iBox/Sources/BoxList/BoxListViewController.swift new file mode 100644 index 0000000..f753544 --- /dev/null +++ b/iBox/Sources/BoxList/BoxListViewController.swift @@ -0,0 +1,18 @@ +// +// BoxListViewController.swift +// iBox +// +// Created by 이지현 on 12/27/23. +// + +import UIKit + +class BoxListViewController: BaseViewController { + + override func viewDidLoad() { + super.viewDidLoad() + title = "iBox" + navigationController?.navigationBar.prefersLargeTitles = true // BaseViewController에 추가해도 될 듯? + } + +} diff --git a/iBox/Sources/BoxListViewController.swift b/iBox/Sources/BoxListViewController.swift deleted file mode 100644 index 3ea9aa1..0000000 --- a/iBox/Sources/BoxListViewController.swift +++ /dev/null @@ -1,29 +0,0 @@ -// -// BoxListViewController.swift -// iBox -// -// Created by 이지현 on 12/27/23. -// - -import UIKit - -class BoxListViewController: BaseViewController { - - override func viewDidLoad() { - super.viewDidLoad() - - // Do any additional setup after loading the view. - } - - - /* - // MARK: - Navigation - - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destination. - // Pass the selected object to the new view controller. - } - */ - -} diff --git a/iBox/Sources/ColorPalette.swift b/iBox/Sources/ColorPalette.swift new file mode 100644 index 0000000..5b290a4 --- /dev/null +++ b/iBox/Sources/ColorPalette.swift @@ -0,0 +1,40 @@ +// +// ColorPalette.swift +// iBox +// +// Created by 이지현 on 1/3/24. +// + +import UIKit + +struct ColorPalette { + + public static var backgroundColor = { + if #available(iOS 13, *) { + return UIColor { (UITraitCollection: UITraitCollection) -> UIColor in + if UITraitCollection.userInterfaceStyle == .dark { + return UIColor.black + } else { + return .systemGray5 + } + } + } else { + return .systemGray5 + } + }() + + public static var tableViewBackgroundColor = { + if #available(iOS 13, *) { + return UIColor { (UITraitCollection: UITraitCollection) -> UIColor in + if UITraitCollection.userInterfaceStyle == .dark { + return UIColor.systemGray5 + } else { + return .white + } + } + } else { + return .white + } + }() + +} diff --git a/iBox/Sources/MainTabBarController.swift b/iBox/Sources/MainTabBarController.swift index d5e0e6e..833df2f 100644 --- a/iBox/Sources/MainTabBarController.swift +++ b/iBox/Sources/MainTabBarController.swift @@ -14,6 +14,7 @@ class MainTabBarController: UITabBarController { view.backgroundColor = .systemBackground setupTabBar() + setupTabBarAppearance() } private func setupTabBar() { @@ -25,8 +26,15 @@ class MainTabBarController: UITabBarController { } private func setupViewController(viewController: UIViewController, image: UIImage?) -> UIViewController { + viewController.tabBarItem.title = "" viewController.tabBarItem.image = image return UINavigationController(rootViewController: viewController) } + + private func setupTabBarAppearance() { + let appearance = UITabBarItem.appearance() + appearance.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.clear], for: .normal) + appearance.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.clear], for: .selected) + } } From 753343482c1a55e0a8c1ca114e2fe5863a8ff1e1 Mon Sep 17 00:00:00 2001 From: JH713 Date: Thu, 4 Jan 2024 14:37:22 +0900 Subject: [PATCH 2/8] =?UTF-8?q?feat:=20table=20view=20expand/close=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iBox/Sources/BoxList/BoxListView.swift | 53 +++++++++++++++++++++++-- iBox/Sources/BoxList/Model/Folder.swift | 19 +++++++++ 2 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 iBox/Sources/BoxList/Model/Folder.swift diff --git a/iBox/Sources/BoxList/BoxListView.swift b/iBox/Sources/BoxList/BoxListView.swift index ef023f0..2698e24 100644 --- a/iBox/Sources/BoxList/BoxListView.swift +++ b/iBox/Sources/BoxList/BoxListView.swift @@ -6,10 +6,18 @@ // import UIKit +import SnapKit class BoxListView: UIView { - let folders = ["folder1", "folder2", "folder3"] + var folderArr = [ + Folder(name: "folder1", webs: [ + Web(name: "42 Intra", url: "https://profile.intra.42.fr/"), + Web(name: "42Where", url: "https://where42.kr/") + ]), + Folder(name: "folder2", webs: [Web(name: "Cabi", url: "https://cabi.42seoul.io/")]), + Folder(name: "folder3", webs: []) + ] private lazy var tableView = { let tableView = UITableView() @@ -47,19 +55,56 @@ class BoxListView: UIView { } extension BoxListView: UITableViewDataSource { + + func numberOfSections(in tableView: UITableView) -> Int { + return folderArr.count + } + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return folders.count + if !folderArr[section].isExpanded { + return 0 + } + return folderArr[section].webs.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) - cell.textLabel?.text = folders[indexPath.row] - cell.backgroundColor = .clear + cell.textLabel?.text = folderArr[indexPath.section].webs[indexPath.row].name return cell } } extension BoxListView: UITableViewDelegate { + func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { + let button = UIButton(type: .system) + button.setTitle(folderArr[section].name, for: .normal) + button.setTitleColor(.label, for: .normal) + button.backgroundColor = ColorPalette.tableViewBackgroundColor + button.titleLabel?.font = .boldSystemFont(ofSize: 16) + button.tag = section + + button.addTarget(self, action: #selector(handleExpandClose), for: .touchUpInside) + + return button + } + @objc private func handleExpandClose(button: UIButton) { + let section = button.tag + + var indexPaths = [IndexPath]() + for row in folderArr[section].webs.indices { + let indexPath = IndexPath(row: row, section: section) + indexPaths.append(indexPath) + } + + folderArr[section].isExpanded.toggle() + + if folderArr[section].isExpanded { + tableView.insertRows(at: indexPaths, with: .fade) + } else { + tableView.deleteRows(at: indexPaths, with: .fade) + } + } } + diff --git a/iBox/Sources/BoxList/Model/Folder.swift b/iBox/Sources/BoxList/Model/Folder.swift new file mode 100644 index 0000000..594c825 --- /dev/null +++ b/iBox/Sources/BoxList/Model/Folder.swift @@ -0,0 +1,19 @@ +// +// Folder.swift +// iBox +// +// Created by 이지현 on 1/4/24. +// + +import Foundation + +struct Folder { + let name: String + let webs: [Web] + var isExpanded: Bool = true +} + +struct Web { + let name: String + let url: String +} From 9b2fd95be5062cc752a063b0f3038955c2477df8 Mon Sep 17 00:00:00 2001 From: JH713 Date: Thu, 4 Jan 2024 14:58:01 +0900 Subject: [PATCH 3/8] =?UTF-8?q?feat:=20WebViewController=EB=A1=9C=20?= =?UTF-8?q?=EC=A0=84=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iBox/Sources/BoxList/BoxListView.swift | 11 +++++++++++ .../BoxList/BoxListViewController.swift | 12 +++++++++++- iBox/Sources/Web/WebViewController.swift | 19 +++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 iBox/Sources/Web/WebViewController.swift diff --git a/iBox/Sources/BoxList/BoxListView.swift b/iBox/Sources/BoxList/BoxListView.swift index 2698e24..45e7cfb 100644 --- a/iBox/Sources/BoxList/BoxListView.swift +++ b/iBox/Sources/BoxList/BoxListView.swift @@ -8,7 +8,12 @@ import UIKit import SnapKit +protocol BoxListViewDelegate: AnyObject { + func didSelectWeb(at url: String) +} + class BoxListView: UIView { + weak var delegate: BoxListViewDelegate? var folderArr = [ Folder(name: "folder1", webs: [ @@ -69,6 +74,7 @@ extension BoxListView: UITableViewDataSource { func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) + cell.selectionStyle = .none cell.textLabel?.text = folderArr[indexPath.section].webs[indexPath.row].name return cell } @@ -106,5 +112,10 @@ extension BoxListView: UITableViewDelegate { tableView.deleteRows(at: indexPaths, with: .fade) } } + + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let webUrl = folderArr[indexPath.section].webs[indexPath.row].url + delegate?.didSelectWeb(at: webUrl) + } } diff --git a/iBox/Sources/BoxList/BoxListViewController.swift b/iBox/Sources/BoxList/BoxListViewController.swift index f753544..9938f4e 100644 --- a/iBox/Sources/BoxList/BoxListViewController.swift +++ b/iBox/Sources/BoxList/BoxListViewController.swift @@ -11,8 +11,18 @@ class BoxListViewController: BaseViewController { override func viewDidLoad() { super.viewDidLoad() + baseView.delegate = self + title = "iBox" - navigationController?.navigationBar.prefersLargeTitles = true // BaseViewController에 추가해도 될 듯? + navigationController?.navigationBar.prefersLargeTitles = true } } + +extension BoxListViewController: BoxListViewDelegate { + func didSelectWeb(at url: String) { + let viewController = WebViewController() + viewController.selectedWebsite = url + navigationController?.pushViewController(viewController, animated: true) + } +} diff --git a/iBox/Sources/Web/WebViewController.swift b/iBox/Sources/Web/WebViewController.swift new file mode 100644 index 0000000..22da71c --- /dev/null +++ b/iBox/Sources/Web/WebViewController.swift @@ -0,0 +1,19 @@ +// +// WebViewController.swift +// iBox +// +// Created by 이지현 on 1/4/24. +// + +import UIKit + +class WebViewController: UIViewController { + var selectedWebsite: String? + + override func viewDidLoad() { + super.viewDidLoad() + view.backgroundColor = .systemBackground + + } + +} From e387b009882ab13d35b2b0478e143bb0ac9c51ad Mon Sep 17 00:00:00 2001 From: JH713 Date: Thu, 4 Jan 2024 15:56:14 +0900 Subject: [PATCH 4/8] feat: WebView --- iBox/Sources/Web/WebView.swift | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 iBox/Sources/Web/WebView.swift diff --git a/iBox/Sources/Web/WebView.swift b/iBox/Sources/Web/WebView.swift new file mode 100644 index 0000000..ed0acd9 --- /dev/null +++ b/iBox/Sources/Web/WebView.swift @@ -0,0 +1,8 @@ +// +// WebView.swift +// iBox +// +// Created by 이지현 on 1/4/24. +// + +import Foundation From 6ee34c49d6effe2535a687a82cc538713587c4e5 Mon Sep 17 00:00:00 2001 From: JH713 Date: Thu, 4 Jan 2024 17:38:20 +0900 Subject: [PATCH 5/8] =?UTF-8?q?feat:=20=ED=8F=B4=EB=8D=94=20=EB=B2=84?= =?UTF-8?q?=ED=8A=BC=20=EB=94=94=EC=9E=90=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iBox/Sources/BoxList/FolderButton.swift | 12 ++++++++++++ iBox/Sources/BoxList/FolderHeaderView.swift | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 iBox/Sources/BoxList/FolderButton.swift create mode 100644 iBox/Sources/BoxList/FolderHeaderView.swift diff --git a/iBox/Sources/BoxList/FolderButton.swift b/iBox/Sources/BoxList/FolderButton.swift new file mode 100644 index 0000000..dba1f14 --- /dev/null +++ b/iBox/Sources/BoxList/FolderButton.swift @@ -0,0 +1,12 @@ +// +// FolderButton.swift +// iBox +// +// Created by 이지현 on 1/4/24. +// + +import UIKit + +class FolderButton: UButton { + +} diff --git a/iBox/Sources/BoxList/FolderHeaderView.swift b/iBox/Sources/BoxList/FolderHeaderView.swift new file mode 100644 index 0000000..e82a2ba --- /dev/null +++ b/iBox/Sources/BoxList/FolderHeaderView.swift @@ -0,0 +1,20 @@ +// +// FolderHeaderView.swift +// iBox +// +// Created by 이지현 on 1/4/24. +// + +import UIKit + +class FolderHeaderView: UITableViewHeaderFooterView { + + /* + // Only override draw() if you perform custom drawing. + // An empty implementation adversely affects performance during animation. + override func draw(_ rect: CGRect) { + // Drawing code + } + */ + +} From 9afbbffb06f07129487d8c2bc2fc7af4bf5bb631 Mon Sep 17 00:00:00 2001 From: JH713 Date: Thu, 4 Jan 2024 17:52:42 +0900 Subject: [PATCH 6/8] =?UTF-8?q?feat:=20boxlist=20=EB=94=94=EC=9E=90?= =?UTF-8?q?=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iBox/Sources/BoxList/BoxListView.swift | 86 ++++++++++++++----- .../BoxList/BoxListViewController.swift | 3 +- iBox/Sources/BoxList/FolderButton.swift | 71 ++++++++++++++- iBox/Sources/BoxList/FolderHeaderView.swift | 20 ----- iBox/Sources/BoxList/Model/Folder.swift | 3 +- iBox/Sources/ColorPalette.swift | 51 +++++++---- iBox/Sources/Web/WebView.swift | 50 ++++++++++- iBox/Sources/Web/WebViewController.swift | 6 +- 8 files changed, 224 insertions(+), 66 deletions(-) delete mode 100644 iBox/Sources/BoxList/FolderHeaderView.swift diff --git a/iBox/Sources/BoxList/BoxListView.swift b/iBox/Sources/BoxList/BoxListView.swift index 45e7cfb..f536daf 100644 --- a/iBox/Sources/BoxList/BoxListView.swift +++ b/iBox/Sources/BoxList/BoxListView.swift @@ -6,36 +6,53 @@ // import UIKit + import SnapKit protocol BoxListViewDelegate: AnyObject { - func didSelectWeb(at url: String) + func didSelectWeb(at url: String, withName name: String) } class BoxListView: UIView { weak var delegate: BoxListViewDelegate? var folderArr = [ - Folder(name: "folder1", webs: [ + Folder(name: "기본 폴더", color: .gray, webs: [ Web(name: "42 Intra", url: "https://profile.intra.42.fr/"), - Web(name: "42Where", url: "https://where42.kr/") + Web(name: "42Where", url: "https://where42.kr/"), + Web(name: "42Stat", url: "https://stat.42seoul.kr/"), + Web(name: "집현전", url: "https://42library.kr/") ]), - Folder(name: "folder2", webs: [Web(name: "Cabi", url: "https://cabi.42seoul.io/")]), - Folder(name: "folder3", webs: []) + Folder(name: "새 폴더", color: .green, webs: [Web(name: "Cabi", url: "https://cabi.42seoul.io/")], isOpened: false), + Folder(name: "새 폴더(2)", color: .yellow, webs: [Web(name: "24HANE", url: "https://24hoursarenotenough.42seoul.kr/")], isOpened: false) ] + private lazy var backgroundView = { + let view = UIView() + view.clipsToBounds = true + view.layer.cornerRadius = 20 + view.backgroundColor = ColorPalette.tableViewBackgroundColor + + view.addSubview(tableView) + tableView.snp.makeConstraints { make in + make.top.bottom.equalToSuperview().offset(10) + make.leading.trailing.equalToSuperview() + } + return view + }() + private lazy var tableView = { let tableView = UITableView() tableView.dataSource = self tableView.delegate = self tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell") - tableView.tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: frame.width, height: 10)) - tableView.separatorInset = UIEdgeInsets(top: 0, left: 15, bottom: 0, right: 15) + tableView.sectionHeaderTopPadding = 0 +// tableView.separatorInset = UIEdgeInsets(top: 0, left: 15, bottom: 0, right: 15) tableView.clipsToBounds = true tableView.layer.cornerRadius = 20 - tableView.backgroundColor = ColorPalette.tableViewBackgroundColor - tableView.separatorColor = .secondaryLabel + tableView.backgroundColor = .clear + tableView.separatorColor = .clear return tableView }() @@ -51,8 +68,8 @@ class BoxListView: UIView { } private func setupLayout() { - addSubview(tableView) - tableView.snp.makeConstraints { make in + addSubview(backgroundView) + backgroundView.snp.makeConstraints { make in make.top.equalTo(safeAreaLayoutGuide).inset(10) make.leading.trailing.bottom.equalTo(safeAreaLayoutGuide).inset(20) } @@ -66,7 +83,7 @@ extension BoxListView: UITableViewDataSource { } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - if !folderArr[section].isExpanded { + if !folderArr[section].isOpened { return 0 } return folderArr[section].webs.count @@ -75,27 +92,50 @@ extension BoxListView: UITableViewDataSource { func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) cell.selectionStyle = .none + cell.backgroundColor = .clear cell.textLabel?.text = folderArr[indexPath.section].webs[indexPath.row].name + cell.imageView?.image = UIImage(systemName: "ellipsis.rectangle.fill") + cell.imageView?.tintColor = .systemGray return cell } } extension BoxListView: UITableViewDelegate { + + public func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { + let view = UIView() + let line = UIView() + view.addSubview(line) + line.snp.makeConstraints { make in + make.top.bottom.equalToSuperview() + make.leading.trailing.equalToSuperview().inset(15) + } + view.backgroundColor = ColorPalette.tableViewBackgroundColor + line.backgroundColor = .tertiaryLabel + return view + } + + public func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { + return 0.3 + } + + func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { + return 50 + } + func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { - let button = UIButton(type: .system) - button.setTitle(folderArr[section].name, for: .normal) - button.setTitleColor(.label, for: .normal) - button.backgroundColor = ColorPalette.tableViewBackgroundColor - button.titleLabel?.font = .boldSystemFont(ofSize: 16) + let button = FolderButton(isOpen: folderArr[section].isOpened) + button.setFolderName(folderArr[section].name) + button.setFolderColor(folderArr[section].color.toUIColor()) button.tag = section - button.addTarget(self, action: #selector(handleExpandClose), for: .touchUpInside) + button.addTarget(self, action: #selector(handleOpenClose), for: .touchUpInside) return button } - @objc private func handleExpandClose(button: UIButton) { + @objc private func handleOpenClose(button: FolderButton) { let section = button.tag var indexPaths = [IndexPath]() @@ -104,9 +144,10 @@ extension BoxListView: UITableViewDelegate { indexPaths.append(indexPath) } - folderArr[section].isExpanded.toggle() + folderArr[section].isOpened.toggle() + button.toggleStatus() - if folderArr[section].isExpanded { + if folderArr[section].isOpened { tableView.insertRows(at: indexPaths, with: .fade) } else { tableView.deleteRows(at: indexPaths, with: .fade) @@ -115,7 +156,8 @@ extension BoxListView: UITableViewDelegate { func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let webUrl = folderArr[indexPath.section].webs[indexPath.row].url - delegate?.didSelectWeb(at: webUrl) + let webName = folderArr[indexPath.section].webs[indexPath.row].name + delegate?.didSelectWeb(at: webUrl, withName: webName) } } diff --git a/iBox/Sources/BoxList/BoxListViewController.swift b/iBox/Sources/BoxList/BoxListViewController.swift index 9938f4e..35806f8 100644 --- a/iBox/Sources/BoxList/BoxListViewController.swift +++ b/iBox/Sources/BoxList/BoxListViewController.swift @@ -20,8 +20,9 @@ class BoxListViewController: BaseViewController { } extension BoxListViewController: BoxListViewDelegate { - func didSelectWeb(at url: String) { + func didSelectWeb(at url: String, withName name: String) { let viewController = WebViewController() + viewController.title = name viewController.selectedWebsite = url navigationController?.pushViewController(viewController, animated: true) } diff --git a/iBox/Sources/BoxList/FolderButton.swift b/iBox/Sources/BoxList/FolderButton.swift index dba1f14..a2587f9 100644 --- a/iBox/Sources/BoxList/FolderButton.swift +++ b/iBox/Sources/BoxList/FolderButton.swift @@ -7,6 +7,75 @@ import UIKit -class FolderButton: UButton { +import SnapKit +class FolderButton: UIButton { + private var isOpen: Bool = true + + private lazy var folderImageView = { + let imageView = UIImageView() + imageView.image = UIImage(systemName: "folder.fill") + imageView.contentMode = .scaleAspectFit + return imageView + }() + + private lazy var folderNameLabel = { + let label = UILabel() + label.textColor = .label + label.font = .systemFont(ofSize: 18, weight: .semibold) + return label + }() + + private lazy var openCloseImageView = { + let imageView = UIImageView() + imageView.tintColor = .tertiaryLabel + imageView.image = isOpen ? UIImage(systemName: "chevron.up") : UIImage(systemName: "chevron.down") + return imageView + }() + + init(isOpen: Bool) { + self.isOpen = isOpen + super.init(frame: .zero) + backgroundColor = .clear + + setupLayout() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + private func setupLayout() { + addSubview(folderImageView) + folderImageView.snp.makeConstraints { make in + make.centerY.equalToSuperview() + make.width.height.equalTo(30) + make.leading.equalToSuperview().offset(20) + } + + addSubview(folderNameLabel) + folderNameLabel.snp.makeConstraints { make in + make.centerY.equalToSuperview() + make.leading.equalTo(folderImageView.snp.trailing).offset(10) + } + + addSubview(openCloseImageView) + openCloseImageView.snp.makeConstraints { make in + make.centerY.equalToSuperview() + make.trailing.equalToSuperview().offset(-20) + } + } + + func setFolderName(_ name: String) { + folderNameLabel.text = name + } + + func setFolderColor(_ color: UIColor) { + folderImageView.tintColor = color + } + + func toggleStatus() { + isOpen = !isOpen + openCloseImageView.image = isOpen ? UIImage(systemName: "chevron.up") : UIImage(systemName: "chevron.down") + } } diff --git a/iBox/Sources/BoxList/FolderHeaderView.swift b/iBox/Sources/BoxList/FolderHeaderView.swift deleted file mode 100644 index e82a2ba..0000000 --- a/iBox/Sources/BoxList/FolderHeaderView.swift +++ /dev/null @@ -1,20 +0,0 @@ -// -// FolderHeaderView.swift -// iBox -// -// Created by 이지현 on 1/4/24. -// - -import UIKit - -class FolderHeaderView: UITableViewHeaderFooterView { - - /* - // Only override draw() if you perform custom drawing. - // An empty implementation adversely affects performance during animation. - override func draw(_ rect: CGRect) { - // Drawing code - } - */ - -} diff --git a/iBox/Sources/BoxList/Model/Folder.swift b/iBox/Sources/BoxList/Model/Folder.swift index 594c825..9ea6fc4 100644 --- a/iBox/Sources/BoxList/Model/Folder.swift +++ b/iBox/Sources/BoxList/Model/Folder.swift @@ -9,8 +9,9 @@ import Foundation struct Folder { let name: String + let color: ColorName let webs: [Web] - var isExpanded: Bool = true + var isOpened: Bool = true } struct Web { diff --git a/iBox/Sources/ColorPalette.swift b/iBox/Sources/ColorPalette.swift index 5b290a4..95084d5 100644 --- a/iBox/Sources/ColorPalette.swift +++ b/iBox/Sources/ColorPalette.swift @@ -7,33 +7,48 @@ import UIKit +enum ColorName: String { + case gray + case green + case red + case blue + case yellow + + func toUIColor() -> UIColor { + switch self { + case .gray: + return UIColor.systemGray2 + case .green: + return UIColor.systemGreen + case .red: + return UIColor.systemRed + case .blue: + return UIColor.systemBlue + case .yellow: + return UIColor.systemYellow + } + } +} + struct ColorPalette { public static var backgroundColor = { - if #available(iOS 13, *) { - return UIColor { (UITraitCollection: UITraitCollection) -> UIColor in - if UITraitCollection.userInterfaceStyle == .dark { - return UIColor.black - } else { - return .systemGray5 - } + return UIColor { (UITraitCollection: UITraitCollection) -> UIColor in + if UITraitCollection.userInterfaceStyle == .dark { + return UIColor.black + } else { + return .systemGray5 } - } else { - return .systemGray5 } }() public static var tableViewBackgroundColor = { - if #available(iOS 13, *) { - return UIColor { (UITraitCollection: UITraitCollection) -> UIColor in - if UITraitCollection.userInterfaceStyle == .dark { - return UIColor.systemGray5 - } else { - return .white - } + return UIColor { (UITraitCollection: UITraitCollection) -> UIColor in + if UITraitCollection.userInterfaceStyle == .dark { + return UIColor.systemGray5 + } else { + return .white } - } else { - return .white } }() diff --git a/iBox/Sources/Web/WebView.swift b/iBox/Sources/Web/WebView.swift index ed0acd9..bd72e75 100644 --- a/iBox/Sources/Web/WebView.swift +++ b/iBox/Sources/Web/WebView.swift @@ -5,4 +5,52 @@ // Created by 이지현 on 1/4/24. // -import Foundation +import UIKit +import WebKit + +import SnapKit + +class WebView: UIView { + var selectedWebsite: String? { + didSet { + loadWebsite() + } + } + + private lazy var webView = { + let webView = WKWebView() + webView.navigationDelegate = self +// webView.scrollView.contentInsetAdjustmentBehavior = .always + + return webView + }() + + override init(frame: CGRect) { + super.init(frame: frame) + backgroundColor = .systemBackground + + setupLayout() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + private func setupLayout() { + addSubview(webView) + webView.snp.makeConstraints { make in + make.edges.equalToSuperview() + } + } + + private func loadWebsite() { + guard let website = selectedWebsite, let url = URL(string: website) else { return } + webView.load(URLRequest(url: url)) + webView.allowsBackForwardNavigationGestures = true + } + +} + +extension WebView: WKNavigationDelegate { + +} diff --git a/iBox/Sources/Web/WebViewController.swift b/iBox/Sources/Web/WebViewController.swift index 22da71c..5b47a29 100644 --- a/iBox/Sources/Web/WebViewController.swift +++ b/iBox/Sources/Web/WebViewController.swift @@ -7,13 +7,15 @@ import UIKit -class WebViewController: UIViewController { +class WebViewController: BaseViewController { var selectedWebsite: String? override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .systemBackground - + navigationItem.largeTitleDisplayMode = .never + + baseView.selectedWebsite = selectedWebsite } } From 91afe152aeba20ac4227895310e2a17360ff3459 Mon Sep 17 00:00:00 2001 From: JH713 Date: Thu, 4 Jan 2024 18:10:10 +0900 Subject: [PATCH 7/8] =?UTF-8?q?feat:=20=ED=8F=B4=EB=8D=94=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EC=83=89=EC=83=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iBox/Sources/ColorPalette.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/iBox/Sources/ColorPalette.swift b/iBox/Sources/ColorPalette.swift index 95084d5..6b611c1 100644 --- a/iBox/Sources/ColorPalette.swift +++ b/iBox/Sources/ColorPalette.swift @@ -53,3 +53,4 @@ struct ColorPalette { }() } + From af962af52291c62e613e7bea16a53b7854cb28f8 Mon Sep 17 00:00:00 2001 From: JH713 Date: Thu, 4 Jan 2024 18:21:20 +0900 Subject: [PATCH 8/8] =?UTF-8?q?feat:=20=ED=8F=B4=EB=8D=94=20=EB=B0=8F=20?= =?UTF-8?q?=EC=95=84=EC=9D=B4=EC=BD=98=20=EC=83=89=EC=83=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iBox/Sources/BoxList/BoxListView.swift | 2 +- iBox/Sources/ColorPalette.swift | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/iBox/Sources/BoxList/BoxListView.swift b/iBox/Sources/BoxList/BoxListView.swift index f536daf..93d1e45 100644 --- a/iBox/Sources/BoxList/BoxListView.swift +++ b/iBox/Sources/BoxList/BoxListView.swift @@ -95,7 +95,7 @@ extension BoxListView: UITableViewDataSource { cell.backgroundColor = .clear cell.textLabel?.text = folderArr[indexPath.section].webs[indexPath.row].name cell.imageView?.image = UIImage(systemName: "ellipsis.rectangle.fill") - cell.imageView?.tintColor = .systemGray + cell.imageView?.tintColor = ColorPalette.webIconColor return cell } diff --git a/iBox/Sources/ColorPalette.swift b/iBox/Sources/ColorPalette.swift index 6b611c1..da9113b 100644 --- a/iBox/Sources/ColorPalette.swift +++ b/iBox/Sources/ColorPalette.swift @@ -35,7 +35,7 @@ struct ColorPalette { public static var backgroundColor = { return UIColor { (UITraitCollection: UITraitCollection) -> UIColor in if UITraitCollection.userInterfaceStyle == .dark { - return UIColor.black + return .black } else { return .systemGray5 } @@ -45,12 +45,32 @@ struct ColorPalette { public static var tableViewBackgroundColor = { return UIColor { (UITraitCollection: UITraitCollection) -> UIColor in if UITraitCollection.userInterfaceStyle == .dark { - return UIColor.systemGray5 + return .systemGray5 } else { return .white } } }() + public static var folderGray = { + return UIColor { (UITraitCollection: UITraitCollection) -> UIColor in + if UITraitCollection.userInterfaceStyle == .dark { + return .systemGray2 + } else { + return .systemGray3 + } + } + }() + + public static var webIconColor = { + return UIColor { (UITraitCollection: UITraitCollection) -> UIColor in + if UITraitCollection.userInterfaceStyle == .dark { + return .systemGray + } else { + return .black + } + } + }() + }