From ad50ab6d3195f92ba04448de65cf8acb73aec6c4 Mon Sep 17 00:00:00 2001 From: jeongdung-eo Date: Fri, 22 Mar 2024 02:22:37 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]=20#244=20-=20custom=20navigation=20view?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Common/NottodoNavigationView.swift | 89 +++++++++++++++++++ .../RecommendActionViewController.swift | 40 +++------ 2 files changed, 100 insertions(+), 29 deletions(-) create mode 100644 iOS-NOTTODO/iOS-NOTTODO/Presentation/Common/NottodoNavigationView.swift diff --git a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Common/NottodoNavigationView.swift b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Common/NottodoNavigationView.swift new file mode 100644 index 00000000..84dbcd3a --- /dev/null +++ b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Common/NottodoNavigationView.swift @@ -0,0 +1,89 @@ +// +// NOTTODONavigationView.swift +// iOS-NOTTODO +// +// Created by JEONGEUN KIM on 3/20/24. +// + +import UIKit + +import SnapKit +import Then + +protocol NavigationDelegate: AnyObject { + func popViewController() +} + +final class NottodoNavigationView: UIView { + + // MARK: - Property + + weak var delegate: NavigationDelegate? + + // MARK: - UI Components + + private let backButton = UIButton() + private let navigationTitle = UILabel() + private let seperateView = UIView() + + override init(frame: CGRect) { + super.init(frame: .zero) + + setUI() + setLayout() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} + +extension NottodoNavigationView { + + private func setUI() { + + seperateView.do { + $0.backgroundColor = .gray2 + } + backButton.do { + $0.setBackgroundImage(.icBack, for: .normal) + $0.addTarget(self, action: #selector(backButtonTapped), for: .touchUpInside) + } + + navigationTitle.do { + $0.font = .Pretendard(.semiBold, size: 18) + $0.textColor = .white + } + } + + private func setLayout() { + self.addSubviews(backButton, navigationTitle, seperateView) + + self.snp.makeConstraints { + $0.height.equalTo(58) + } + + backButton.snp.makeConstraints { + $0.centerY.equalToSuperview() + $0.leading.equalToSuperview().inset(15) + } + + navigationTitle.snp.makeConstraints { + $0.center.equalToSuperview() + } + + seperateView.snp.makeConstraints { + $0.bottom.horizontalEdges.equalToSuperview() + $0.height.equalTo(0.7) + } + } + + func setTitle(_ text: String) { + navigationTitle.text = text + } + + @objc + private func backButtonTapped() { + delegate?.popViewController() + } +} diff --git a/iOS-NOTTODO/iOS-NOTTODO/Presentation/RecommendAction/ViewControllers/RecommendActionViewController.swift b/iOS-NOTTODO/iOS-NOTTODO/Presentation/RecommendAction/ViewControllers/RecommendActionViewController.swift index d73e836d..85996202 100644 --- a/iOS-NOTTODO/iOS-NOTTODO/Presentation/RecommendAction/ViewControllers/RecommendActionViewController.swift +++ b/iOS-NOTTODO/iOS-NOTTODO/Presentation/RecommendAction/ViewControllers/RecommendActionViewController.swift @@ -43,9 +43,7 @@ final class RecommendActionViewController: UIViewController { // MARK: - UI Components - private let navigationView = UIView() - private let backButton = UIButton() - private let navigationTitle = UILabel() + private let navigationView = NottodoNavigationView() private let nextButton = UIButton() private var isTapped: Bool = false { didSet { @@ -111,15 +109,9 @@ private extension RecommendActionViewController { // $0.allowsMultipleSelection = true 생성뷰 이슈 해결 후 주석 해제 } - backButton.do { - $0.setBackgroundImage(.back, for: .normal) - $0.addTarget(self, action: #selector(backButtonDidTapped), for: .touchUpInside) - } - - navigationTitle.do { - $0.font = .Pretendard(.semiBold, size: 18) - $0.textColor = .white - $0.text = I18N.recommendNavTitle + navigationView.do { + $0.delegate = self + $0.setTitle(I18N.recommendNavTitle) } nextButton.do { @@ -135,23 +127,12 @@ private extension RecommendActionViewController { func setLayout() { view.addSubviews(navigationView, recommendActionCollectionView, nextButton) - navigationView.addSubviews(backButton, navigationTitle) navigationView.snp.makeConstraints { $0.top.equalTo(view.safeAreaLayoutGuide) $0.directionalHorizontalEdges.equalToSuperview() - $0.height.equalTo(58) - } - - backButton.snp.makeConstraints { - $0.centerY.equalToSuperview() - $0.leading.equalToSuperview().offset(15) } - - navigationTitle.snp.makeConstraints { - $0.center.equalToSuperview() - } - + recommendActionCollectionView.snp.makeConstraints { $0.top.equalTo(navigationView.snp.bottom) $0.leading.trailing.equalToSuperview() @@ -186,11 +167,6 @@ private extension RecommendActionViewController { recommendActionCollectionView.delegate = self recommendActionCollectionView.dataSource = self } - - @objc - func backButtonDidTapped() { - coordinator?.popViewController() - } } extension RecommendActionViewController: UICollectionViewDelegateFlowLayout { @@ -299,3 +275,9 @@ extension RecommendActionViewController { } } } + +extension RecommendActionViewController: NavigationDelegate { + func popViewController() { + coordinator?.popViewController() + } +}