From 4b0e6a9718d09a1cdfc94502a13d273021e057b0 Mon Sep 17 00:00:00 2001 From: noeyiz Date: Thu, 22 Feb 2024 17:04:43 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=EC=B2=AB=20=ED=99=94=EB=A9=B4=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iBox/Sources/Model/MainTabType.swift | 20 ++++ .../Presenter/MainTabBarController.swift | 1 + .../MyPage/MainTab/MainTabCell.swift | 69 ++++++++++++++ .../MyPage/MainTab/MainTabView.swift | 95 +++++++++++++++++++ .../MainTab/MainTabViewController.swift | 34 +++++++ .../MyPage/MyPageViewController.swift | 8 +- iBox/Sources/Utils/UserDefaultsManager.swift | 5 + iBox/Sources/ViewModel/MainTabViewModel.swift | 15 +++ iBox/Sources/ViewModel/MyPageViewModel.swift | 5 +- 9 files changed, 249 insertions(+), 3 deletions(-) create mode 100644 iBox/Sources/Model/MainTabType.swift create mode 100644 iBox/Sources/Presenter/MyPage/MainTab/MainTabCell.swift create mode 100644 iBox/Sources/Presenter/MyPage/MainTab/MainTabView.swift create mode 100644 iBox/Sources/Presenter/MyPage/MainTab/MainTabViewController.swift create mode 100644 iBox/Sources/ViewModel/MainTabViewModel.swift diff --git a/iBox/Sources/Model/MainTabType.swift b/iBox/Sources/Model/MainTabType.swift new file mode 100644 index 0000000..63e3f0a --- /dev/null +++ b/iBox/Sources/Model/MainTabType.swift @@ -0,0 +1,20 @@ +// +// MainTabType.swift +// iBox +// +// Created by jiyeon on 2/22/24. +// + +import Foundation + +enum MainTabType: CaseIterable { + case boxList + case favorite + + func toString() -> String { + switch self { + case .boxList: "북마크 목록" + case .favorite: "즐겨찾기" + } + } +} diff --git a/iBox/Sources/Presenter/MainTabBarController.swift b/iBox/Sources/Presenter/MainTabBarController.swift index 7ffd765..98bf4e7 100644 --- a/iBox/Sources/Presenter/MainTabBarController.swift +++ b/iBox/Sources/Presenter/MainTabBarController.swift @@ -25,6 +25,7 @@ class MainTabBarController: UITabBarController { ] tabBar.tintColor = .box tabBar.backgroundColor = .systemBackground + selectedIndex = UserDefaultsManager.mainTabIndex.value } private func setupViewController(viewController: UIViewController, image: UIImage?) -> UIViewController { diff --git a/iBox/Sources/Presenter/MyPage/MainTab/MainTabCell.swift b/iBox/Sources/Presenter/MyPage/MainTab/MainTabCell.swift new file mode 100644 index 0000000..6ab2bcf --- /dev/null +++ b/iBox/Sources/Presenter/MyPage/MainTab/MainTabCell.swift @@ -0,0 +1,69 @@ +// +// MainTabCell.swift +// iBox +// +// Created by jiyeon on 2/22/24. +// + +import UIKit + +import SnapKit + +class MainTabCell: UITableViewCell { + + // MARK: - Properties + + static let reuseIdentifier = "MainTabCell" + + // MARK: - UI Components + + let titleLabel = UILabel().then { + $0.font = .systemFont(ofSize: 16) + } + + let selectButton = UIButton().then { + $0.configuration = .plain() + } + + // MARK: - Initializer + + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) + setupLayout() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + // MARK: - Setup Methods + + private func setupLayout() { + selectionStyle = .none + + addSubview(titleLabel) + addSubview(selectButton) + + titleLabel.snp.makeConstraints { + $0.left.equalToSuperview().inset(20) + $0.centerY.equalToSuperview() + } + + selectButton.snp.makeConstraints { + $0.right.equalToSuperview().inset(20) + $0.centerY.equalToSuperview() + $0.width.height.equalTo(20) + } + } + + func setupSelectButton(_ selected: Bool) { + if selected { + selectButton.configuration?.image = UIImage(systemName: "circle.inset.filled") + selectButton.tintColor = .box2 + } else { + selectButton.configuration?.image = UIImage(systemName: "circle") + selectButton.tintColor = .gray + } + } + +} diff --git a/iBox/Sources/Presenter/MyPage/MainTab/MainTabView.swift b/iBox/Sources/Presenter/MyPage/MainTab/MainTabView.swift new file mode 100644 index 0000000..c2a3a35 --- /dev/null +++ b/iBox/Sources/Presenter/MyPage/MainTab/MainTabView.swift @@ -0,0 +1,95 @@ +// +// MainTabView.swift +// iBox +// +// Created by jiyeon on 2/22/24. +// + +import Combine +import UIKit + +class MainTabView: BaseView { + + // MARK: - Properties + + private var viewModel: MainTabViewModel? + private var cancellables = Set() + + // MARK: - UI Components + + let tableView = UITableView().then { + $0.separatorStyle = .none + $0.register(MainTabCell.self, forCellReuseIdentifier: MainTabCell.reuseIdentifier) + } + + // MARK: - Initializer + + override init(frame: CGRect) { + super.init(frame: frame) + setupProperty() + setupLayout() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + // MARK: - Setup Methods + + private func setupProperty() { + tableView.delegate = self + tableView.dataSource = self + } + + private func setupLayout() { + addSubview(tableView) + + tableView.snp.makeConstraints { + $0.edges.equalToSuperview() + } + } + + // MARK: - Bind ViewModel + + func bindViewModel(_ viewModel: MainTabViewModel) { + self.viewModel = viewModel + viewModel.$selectedIndex + .receive(on: RunLoop.main) + .sink { [weak self] selectedIndex in + UserDefaultsManager.mainTabIndex.value = selectedIndex + self?.tableView.reloadData() + }.store(in: &cancellables) + } + +} + +extension MainTabView: UITableViewDelegate { + + // 셀의 높이 설정 + func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { + return 55 + } + + // 테이블 뷰 셀이 선택되었을 때 실행되는 메서드 + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + guard let viewModel = viewModel else { return } + viewModel.selectedIndex = indexPath.row + } + +} + +extension MainTabView: UITableViewDataSource { + + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return MainTabType.allCases.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + guard let viewModel = viewModel, + let cell = tableView.dequeueReusableCell(withIdentifier: MainTabCell.reuseIdentifier) as? MainTabCell else { return UITableViewCell() } + cell.titleLabel.text = MainTabType.allCases[indexPath.row].toString() + cell.setupSelectButton(viewModel.selectedIndex == indexPath.row) + return cell + } + +} diff --git a/iBox/Sources/Presenter/MyPage/MainTab/MainTabViewController.swift b/iBox/Sources/Presenter/MyPage/MainTab/MainTabViewController.swift new file mode 100644 index 0000000..75b29c9 --- /dev/null +++ b/iBox/Sources/Presenter/MyPage/MainTab/MainTabViewController.swift @@ -0,0 +1,34 @@ +// +// MainTabViewController.swift +// iBox +// +// Created by jiyeon on 2/22/24. +// + +import UIKit + +class MainTabViewController: BaseNavigationBarViewController { + + // MARK: - Properties + + private let viewModel = MainTabViewModel() + + // MARK: - life cycle + + override func viewDidLoad() { + super.viewDidLoad() + setupNavigationBar() // 얘는 왜 여기에 적어줘야 전부 다 적용이 될까 ..? 🧐 + + guard let contentView = contentView as? MainTabView else { return } + contentView.bindViewModel(viewModel) + } + + // MARK: - BaseNavigationBarViewControllerProtocol + + override func setupNavigationBar() { + setNavigationBarTitleLabelText("첫 화면 설정하기") + setNavigationBarTitleLabelFont(.systemFont(ofSize: 17, weight: .semibold)) + setNavigationBarBackButtonHidden(false) + } + +} diff --git a/iBox/Sources/Presenter/MyPage/MyPageViewController.swift b/iBox/Sources/Presenter/MyPage/MyPageViewController.swift index 886a2f6..0a57a44 100644 --- a/iBox/Sources/Presenter/MyPage/MyPageViewController.swift +++ b/iBox/Sources/Presenter/MyPage/MyPageViewController.swift @@ -39,13 +39,17 @@ extension MyPageViewController: MyPageViewDelegate { func pushViewController(_ indexPath: IndexPath) { if indexPath.section == 0 { - navigationController?.pushViewController(ThemeViewController(), animated: true) + switch indexPath.row { + case 0: navigationController?.pushViewController(ThemeViewController(), animated: true) + case 1: navigationController?.pushViewController(MainTabViewController(), animated: true) + default: break + } } else { switch indexPath.row { case 0: print("이용 가이드 탭 !") case 1: print("앱 피드백 탭 !") case 2: print("개발자 정보 탭 !") - default: break; + default: break } } } diff --git a/iBox/Sources/Utils/UserDefaultsManager.swift b/iBox/Sources/Utils/UserDefaultsManager.swift index 479734c..f010786 100644 --- a/iBox/Sources/Utils/UserDefaultsManager.swift +++ b/iBox/Sources/Utils/UserDefaultsManager.swift @@ -10,6 +10,7 @@ import Foundation enum UserDefaultsAccessKey: String { case theme // 다크 모드 case favorite // 즐겨찾기 + case mainTab // 첫 화면 } final class UserDefaultsManager { @@ -21,6 +22,10 @@ final class UserDefaultsManager { key: .favorite, defaultValue: Bookmark(name: "42 Intra", url: "https://profile.intra.42.fr/") ) + static let mainTabIndex = UserDefaultValue( + key: .mainTab, + defaultValue: 0 + ) } class UserDefaultValue { diff --git a/iBox/Sources/ViewModel/MainTabViewModel.swift b/iBox/Sources/ViewModel/MainTabViewModel.swift new file mode 100644 index 0000000..76d2e6c --- /dev/null +++ b/iBox/Sources/ViewModel/MainTabViewModel.swift @@ -0,0 +1,15 @@ +// +// MainTabViewModel.swift +// iBox +// +// Created by jiyeon on 2/22/24. +// + +import Combine +import Foundation + +class MainTabViewModel { + + @Published var selectedIndex: Int = UserDefaultsManager.mainTabIndex.value + +} diff --git a/iBox/Sources/ViewModel/MyPageViewModel.swift b/iBox/Sources/ViewModel/MyPageViewModel.swift index 75ce095..198a4cf 100644 --- a/iBox/Sources/ViewModel/MyPageViewModel.swift +++ b/iBox/Sources/ViewModel/MyPageViewModel.swift @@ -12,7 +12,10 @@ class MyPageViewModel { let myPageSectionViewModels: [MyPageSectionViewModel] = [ MyPageSectionViewModel(MyPageSection( title: "settings", - items: [MyPageItem(title: "테마")] + items: [ + MyPageItem(title: "테마"), + MyPageItem(title: "첫 화면") + ] )), MyPageSectionViewModel(MyPageSection( title: "help", From 68b1e362b4d3a430a4bf7e3198a22ccb33f6e18a Mon Sep 17 00:00:00 2001 From: noeyiz Date: Thu, 22 Feb 2024 17:11:40 +0900 Subject: [PATCH 2/4] =?UTF-8?q?rename:=20MainTabView=20->=20HomeTabSelecto?= =?UTF-8?q?rView=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{MainTabType.swift => HomeTabType.swift} | 4 ++-- .../Presenter/MainTabBarController.swift | 2 +- .../HomeTabSelectorCell.swift} | 4 ++-- .../HomeTabSelectorView.swift} | 22 +++++++++---------- .../HomeTabSelectorViewController.swift} | 8 +++---- .../MyPage/MyPageViewController.swift | 2 +- iBox/Sources/Utils/UserDefaultsManager.swift | 6 ++--- .../ViewModel/HomeTabSelectorViewModel.swift | 15 +++++++++++++ iBox/Sources/ViewModel/MainTabViewModel.swift | 15 ------------- 9 files changed, 39 insertions(+), 39 deletions(-) rename iBox/Sources/Model/{MainTabType.swift => HomeTabType.swift} (82%) rename iBox/Sources/Presenter/MyPage/{MainTab/MainTabCell.swift => HomeTab/HomeTabSelectorCell.swift} (95%) rename iBox/Sources/Presenter/MyPage/{MainTab/MainTabView.swift => HomeTab/HomeTabSelectorView.swift} (75%) rename iBox/Sources/Presenter/MyPage/{MainTab/MainTabViewController.swift => HomeTab/HomeTabSelectorViewController.swift} (71%) create mode 100644 iBox/Sources/ViewModel/HomeTabSelectorViewModel.swift delete mode 100644 iBox/Sources/ViewModel/MainTabViewModel.swift diff --git a/iBox/Sources/Model/MainTabType.swift b/iBox/Sources/Model/HomeTabType.swift similarity index 82% rename from iBox/Sources/Model/MainTabType.swift rename to iBox/Sources/Model/HomeTabType.swift index 63e3f0a..2d7bb4c 100644 --- a/iBox/Sources/Model/MainTabType.swift +++ b/iBox/Sources/Model/HomeTabType.swift @@ -1,5 +1,5 @@ // -// MainTabType.swift +// HomeTabType.swift // iBox // // Created by jiyeon on 2/22/24. @@ -7,7 +7,7 @@ import Foundation -enum MainTabType: CaseIterable { +enum HomeTabType: CaseIterable { case boxList case favorite diff --git a/iBox/Sources/Presenter/MainTabBarController.swift b/iBox/Sources/Presenter/MainTabBarController.swift index 98bf4e7..57541e5 100644 --- a/iBox/Sources/Presenter/MainTabBarController.swift +++ b/iBox/Sources/Presenter/MainTabBarController.swift @@ -25,7 +25,7 @@ class MainTabBarController: UITabBarController { ] tabBar.tintColor = .box tabBar.backgroundColor = .systemBackground - selectedIndex = UserDefaultsManager.mainTabIndex.value + selectedIndex = UserDefaultsManager.homeTabIndex.value } private func setupViewController(viewController: UIViewController, image: UIImage?) -> UIViewController { diff --git a/iBox/Sources/Presenter/MyPage/MainTab/MainTabCell.swift b/iBox/Sources/Presenter/MyPage/HomeTab/HomeTabSelectorCell.swift similarity index 95% rename from iBox/Sources/Presenter/MyPage/MainTab/MainTabCell.swift rename to iBox/Sources/Presenter/MyPage/HomeTab/HomeTabSelectorCell.swift index 6ab2bcf..224e640 100644 --- a/iBox/Sources/Presenter/MyPage/MainTab/MainTabCell.swift +++ b/iBox/Sources/Presenter/MyPage/HomeTab/HomeTabSelectorCell.swift @@ -1,5 +1,5 @@ // -// MainTabCell.swift +// HomeTabSelectorCell.swift // iBox // // Created by jiyeon on 2/22/24. @@ -9,7 +9,7 @@ import UIKit import SnapKit -class MainTabCell: UITableViewCell { +class HomeTabSelectorCell: UITableViewCell { // MARK: - Properties diff --git a/iBox/Sources/Presenter/MyPage/MainTab/MainTabView.swift b/iBox/Sources/Presenter/MyPage/HomeTab/HomeTabSelectorView.swift similarity index 75% rename from iBox/Sources/Presenter/MyPage/MainTab/MainTabView.swift rename to iBox/Sources/Presenter/MyPage/HomeTab/HomeTabSelectorView.swift index c2a3a35..454ae24 100644 --- a/iBox/Sources/Presenter/MyPage/MainTab/MainTabView.swift +++ b/iBox/Sources/Presenter/MyPage/HomeTab/HomeTabSelectorView.swift @@ -1,5 +1,5 @@ // -// MainTabView.swift +// HomeTabSelectorView.swift // iBox // // Created by jiyeon on 2/22/24. @@ -8,18 +8,18 @@ import Combine import UIKit -class MainTabView: BaseView { +class HomeTabSelectorView: BaseView { // MARK: - Properties - private var viewModel: MainTabViewModel? + private var viewModel: HomeTabSelectorViewModel? private var cancellables = Set() // MARK: - UI Components let tableView = UITableView().then { $0.separatorStyle = .none - $0.register(MainTabCell.self, forCellReuseIdentifier: MainTabCell.reuseIdentifier) + $0.register(HomeTabSelectorCell.self, forCellReuseIdentifier: HomeTabSelectorCell.reuseIdentifier) } // MARK: - Initializer @@ -51,19 +51,19 @@ class MainTabView: BaseView { // MARK: - Bind ViewModel - func bindViewModel(_ viewModel: MainTabViewModel) { + func bindViewModel(_ viewModel: HomeTabSelectorViewModel) { self.viewModel = viewModel viewModel.$selectedIndex .receive(on: RunLoop.main) .sink { [weak self] selectedIndex in - UserDefaultsManager.mainTabIndex.value = selectedIndex + UserDefaultsManager.homeTabIndex.value = selectedIndex self?.tableView.reloadData() }.store(in: &cancellables) } } -extension MainTabView: UITableViewDelegate { +extension HomeTabSelectorView: UITableViewDelegate { // 셀의 높이 설정 func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { @@ -78,16 +78,16 @@ extension MainTabView: UITableViewDelegate { } -extension MainTabView: UITableViewDataSource { +extension HomeTabSelectorView: UITableViewDataSource { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return MainTabType.allCases.count + return HomeTabType.allCases.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { guard let viewModel = viewModel, - let cell = tableView.dequeueReusableCell(withIdentifier: MainTabCell.reuseIdentifier) as? MainTabCell else { return UITableViewCell() } - cell.titleLabel.text = MainTabType.allCases[indexPath.row].toString() + let cell = tableView.dequeueReusableCell(withIdentifier: HomeTabSelectorCell.reuseIdentifier) as? HomeTabSelectorCell else { return UITableViewCell() } + cell.titleLabel.text = HomeTabType.allCases[indexPath.row].toString() cell.setupSelectButton(viewModel.selectedIndex == indexPath.row) return cell } diff --git a/iBox/Sources/Presenter/MyPage/MainTab/MainTabViewController.swift b/iBox/Sources/Presenter/MyPage/HomeTab/HomeTabSelectorViewController.swift similarity index 71% rename from iBox/Sources/Presenter/MyPage/MainTab/MainTabViewController.swift rename to iBox/Sources/Presenter/MyPage/HomeTab/HomeTabSelectorViewController.swift index 75b29c9..e67c207 100644 --- a/iBox/Sources/Presenter/MyPage/MainTab/MainTabViewController.swift +++ b/iBox/Sources/Presenter/MyPage/HomeTab/HomeTabSelectorViewController.swift @@ -1,5 +1,5 @@ // -// MainTabViewController.swift +// HomeTabSelectorViewwController.swift // iBox // // Created by jiyeon on 2/22/24. @@ -7,11 +7,11 @@ import UIKit -class MainTabViewController: BaseNavigationBarViewController { +class HomeTabSelectorViewController: BaseNavigationBarViewController { // MARK: - Properties - private let viewModel = MainTabViewModel() + private let viewModel = HomeTabSelectorViewModel() // MARK: - life cycle @@ -19,7 +19,7 @@ class MainTabViewController: BaseNavigationBarViewController { super.viewDidLoad() setupNavigationBar() // 얘는 왜 여기에 적어줘야 전부 다 적용이 될까 ..? 🧐 - guard let contentView = contentView as? MainTabView else { return } + guard let contentView = contentView as? HomeTabSelectorView else { return } contentView.bindViewModel(viewModel) } diff --git a/iBox/Sources/Presenter/MyPage/MyPageViewController.swift b/iBox/Sources/Presenter/MyPage/MyPageViewController.swift index 0a57a44..ee79a6c 100644 --- a/iBox/Sources/Presenter/MyPage/MyPageViewController.swift +++ b/iBox/Sources/Presenter/MyPage/MyPageViewController.swift @@ -41,7 +41,7 @@ extension MyPageViewController: MyPageViewDelegate { if indexPath.section == 0 { switch indexPath.row { case 0: navigationController?.pushViewController(ThemeViewController(), animated: true) - case 1: navigationController?.pushViewController(MainTabViewController(), animated: true) + case 1: navigationController?.pushViewController(HomeTabSelectorViewController(), animated: true) default: break } } else { diff --git a/iBox/Sources/Utils/UserDefaultsManager.swift b/iBox/Sources/Utils/UserDefaultsManager.swift index f010786..8baef12 100644 --- a/iBox/Sources/Utils/UserDefaultsManager.swift +++ b/iBox/Sources/Utils/UserDefaultsManager.swift @@ -10,7 +10,7 @@ import Foundation enum UserDefaultsAccessKey: String { case theme // 다크 모드 case favorite // 즐겨찾기 - case mainTab // 첫 화면 + case homeTab // 첫 화면 } final class UserDefaultsManager { @@ -22,8 +22,8 @@ final class UserDefaultsManager { key: .favorite, defaultValue: Bookmark(name: "42 Intra", url: "https://profile.intra.42.fr/") ) - static let mainTabIndex = UserDefaultValue( - key: .mainTab, + static let homeTabIndex = UserDefaultValue( + key: .homeTab, defaultValue: 0 ) } diff --git a/iBox/Sources/ViewModel/HomeTabSelectorViewModel.swift b/iBox/Sources/ViewModel/HomeTabSelectorViewModel.swift new file mode 100644 index 0000000..1e6b63f --- /dev/null +++ b/iBox/Sources/ViewModel/HomeTabSelectorViewModel.swift @@ -0,0 +1,15 @@ +// +// HomeTabSelectorViewModel.swift +// iBox +// +// Created by jiyeon on 2/22/24. +// + +import Combine +import Foundation + +class HomeTabSelectorViewModel { + + @Published var selectedIndex: Int = UserDefaultsManager.homeTabIndex.value + +} diff --git a/iBox/Sources/ViewModel/MainTabViewModel.swift b/iBox/Sources/ViewModel/MainTabViewModel.swift deleted file mode 100644 index 76d2e6c..0000000 --- a/iBox/Sources/ViewModel/MainTabViewModel.swift +++ /dev/null @@ -1,15 +0,0 @@ -// -// MainTabViewModel.swift -// iBox -// -// Created by jiyeon on 2/22/24. -// - -import Combine -import Foundation - -class MainTabViewModel { - - @Published var selectedIndex: Int = UserDefaultsManager.mainTabIndex.value - -} From d0be16d927f46d3404e881ffc322e1df95672bb8 Mon Sep 17 00:00:00 2001 From: noeyiz Date: Thu, 22 Feb 2024 17:23:17 +0900 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20ProfileView=20description=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Presenter/MyPage/MyPageView.swift | 10 +++ .../MyPage/MyPageViewController.swift | 6 ++ iBox/Sources/ViewModel/MyPageViewModel.swift | 64 ++++++++++++++----- 3 files changed, 64 insertions(+), 16 deletions(-) diff --git a/iBox/Sources/Presenter/MyPage/MyPageView.swift b/iBox/Sources/Presenter/MyPage/MyPageView.swift index ee07b29..a066633 100644 --- a/iBox/Sources/Presenter/MyPage/MyPageView.swift +++ b/iBox/Sources/Presenter/MyPage/MyPageView.swift @@ -5,6 +5,7 @@ // Created by jiyeon on 1/3/24. // +import Combine import UIKit class MyPageView: BaseView { @@ -13,6 +14,7 @@ class MyPageView: BaseView { var delegate: MyPageViewDelegate? private var viewModel: MyPageViewModel? + private var cancellables = Set() // MARK: - UI @@ -103,6 +105,14 @@ class MyPageView: BaseView { func bindViewModel(_ viewModel: MyPageViewModel) { self.viewModel = viewModel + viewModel.transform(input: viewModel.input.eraseToAnyPublisher()) + .receive(on: RunLoop.main) + .sink { [weak self] event in + switch event { + case .updateMyPageSectionViewModels: + self?.tableView.reloadData() + } + }.store(in: &cancellables) } // MARK: - functions diff --git a/iBox/Sources/Presenter/MyPage/MyPageViewController.swift b/iBox/Sources/Presenter/MyPage/MyPageViewController.swift index ee79a6c..69349b1 100644 --- a/iBox/Sources/Presenter/MyPage/MyPageViewController.swift +++ b/iBox/Sources/Presenter/MyPage/MyPageViewController.swift @@ -25,6 +25,12 @@ class MyPageViewController: BaseNavigationBarViewController { guard let contentView = contentView as? MyPageView else { return } contentView.delegate = self contentView.bindViewModel(viewModel) + viewModel.input.send(.viewWillAppear) + } + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + viewModel.input.send(.viewWillAppear) } // MARK: - BaseNavigationBarViewControllerProtocol diff --git a/iBox/Sources/ViewModel/MyPageViewModel.swift b/iBox/Sources/ViewModel/MyPageViewModel.swift index 198a4cf..cc6e8ac 100644 --- a/iBox/Sources/ViewModel/MyPageViewModel.swift +++ b/iBox/Sources/ViewModel/MyPageViewModel.swift @@ -5,26 +5,58 @@ // Created by jiyeon on 2/22/24. // +import Combine import Foundation class MyPageViewModel { - let myPageSectionViewModels: [MyPageSectionViewModel] = [ - MyPageSectionViewModel(MyPageSection( - title: "settings", - items: [ - MyPageItem(title: "테마"), - MyPageItem(title: "첫 화면") - ] - )), - MyPageSectionViewModel(MyPageSection( - title: "help", - items: [ - MyPageItem(title: "이용 가이드"), - MyPageItem(title: "앱 피드백"), - MyPageItem(title: "개발자 정보") - ] + enum Input { + case viewWillAppear + } + + enum Output { + case updateMyPageSectionViewModels + } + + // MARK: - Properties + + let input = PassthroughSubject() + private let output = PassthroughSubject() + private var cancellables = Set() + var myPageSectionViewModels = [MyPageSectionViewModel]() + + func transform(input: AnyPublisher) -> AnyPublisher { + input.sink { [weak self] event in + switch event { + case .viewWillAppear: + self?.myPageSectionViewModels.removeAll() + self?.updateMyPageSectionViewModels() + self?.output.send(.updateMyPageSectionViewModels) + } + }.store(in: &cancellables) + return output.eraseToAnyPublisher() + } + + private func updateMyPageSectionViewModels() { + myPageSectionViewModels.append(MyPageSectionViewModel( + MyPageSection( + title: "settings", + items: [ + MyPageItem(title: "테마", description: UserDefaultsManager.theme.value.toString()), + MyPageItem(title: "홈화면", description: HomeTabType.allCases[UserDefaultsManager.homeTabIndex.value].toString()) + ] + ) )) - ] + myPageSectionViewModels.append(MyPageSectionViewModel( + MyPageSection( + title: "help", + items: [ + MyPageItem(title: "이용 가이드"), + MyPageItem(title: "앱 피드백"), + MyPageItem(title: "개발자 정보") + ] + )) + ) + } } From 2a1e8ab60efd32f70c4c05a0c2aa310dec98c21c Mon Sep 17 00:00:00 2001 From: noeyiz Date: Thu, 22 Feb 2024 17:26:36 +0900 Subject: [PATCH 4/4] =?UTF-8?q?style:=20HomeTabViewController=20=ED=83=80?= =?UTF-8?q?=EC=9D=B4=ED=8B=80=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MyPage/HomeTab/HomeTabSelectorViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iBox/Sources/Presenter/MyPage/HomeTab/HomeTabSelectorViewController.swift b/iBox/Sources/Presenter/MyPage/HomeTab/HomeTabSelectorViewController.swift index e67c207..d6c7bab 100644 --- a/iBox/Sources/Presenter/MyPage/HomeTab/HomeTabSelectorViewController.swift +++ b/iBox/Sources/Presenter/MyPage/HomeTab/HomeTabSelectorViewController.swift @@ -26,7 +26,7 @@ class HomeTabSelectorViewController: BaseNavigationBarViewController