Skip to content

Commit

Permalink
Merge pull request #369 from OMZigak/fix/#368-navigationbar-border
Browse files Browse the repository at this point in the history
[fix] 네비게이션바 경계선 로직 수정
  • Loading branch information
JinUng41 authored Sep 7, 2024
2 parents 11dd261 + f8ffc78 commit 3414f5a
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 56 deletions.
2 changes: 1 addition & 1 deletion KkuMulKum/Application/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
let mainTabBarController = MainTabBarController()
let navigationController = UINavigationController(
rootViewController: mainTabBarController,
isBorderNeeded: true
isBorderNeeded: false
)
navigationController.isNavigationBarHidden = true

Expand Down
38 changes: 32 additions & 6 deletions KkuMulKum/Resource/Base/BaseViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,9 @@ extension BaseViewController {
.font: UIFont.pretendard(.body03)
]

isBorderHidden ? navigationController?.hideBorder() : navigationController?.showBorder()

let barAppearance = UINavigationBarAppearance()
barAppearance.backgroundColor = .white
navigationItem.standardAppearance = barAppearance
navigationItem.scrollEdgeAppearance = barAppearance
if !isBorderHidden {
addBorder()
}
}

/// 네비게이션 바 BackButton 구성
Expand All @@ -67,15 +64,44 @@ extension BaseViewController {
}
}


// MARK: - UIGestureRecognizerDelegate

extension BaseViewController: UIGestureRecognizerDelegate {
func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
return navigationController?.viewControllers.count ?? 0 > 1
}
}


// MARK: - Private Method

private extension BaseViewController {
@objc
func backButtonDidTap() {
navigationController?.popViewController(animated: true)
}

func addBorder() {
let identifier = "border"
guard view.subviews.first(where: { $0.accessibilityIdentifier == identifier }) == nil else { return }

let safeArea = view.safeAreaLayoutGuide
let border = UIView(backgroundColor: .gray2).then {
$0.accessibilityIdentifier = identifier
}

view.addSubview(border)

border.snp.makeConstraints {
$0.top.equalTo(safeArea)
$0.horizontalEdges.equalToSuperview()
$0.height.equalTo(1)
}

view.bringSubviewToFront(border)

view.setNeedsLayout()
view.layoutIfNeeded()
}
}
44 changes: 5 additions & 39 deletions KkuMulKum/Resource/Extension/UINavigationController+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,11 @@ extension UINavigationController {
convenience init(rootViewController: UIViewController, isBorderNeeded: Bool) {
self.init(rootViewController: rootViewController)

if isBorderNeeded {
addBorder()
}
}

func showBorder() {
let border = findBottomBorder()
border?.isHidden = false
}

func hideBorder() {
let border = findBottomBorder()
border?.isHidden = true
}
}

private extension UINavigationController {
enum Constants {
static let bottomBorderName = "BottomBorder"
static let bottomBorderWidth: CGFloat = Screen.height(1)
}

func addBorder() {
guard findBottomBorder() == nil else { return }
let barAppearance = UINavigationBarAppearance()
barAppearance.backgroundColor = .white
barAppearance.shadowColor = isBorderNeeded ? .gray2 : nil

let border = CALayer()
border.name = Constants.bottomBorderName
border.backgroundColor = UIColor.gray2.cgColor
border.frame = CGRect(
x: 0,
y: navigationBar.frame.height - Constants.bottomBorderWidth,
width: navigationBar.frame.width,
height: Constants.bottomBorderWidth
)

navigationBar.layer.addSublayer(border)
}

func findBottomBorder() -> CALayer? {
return navigationBar.layer.sublayers?.first(where: { $0.name == Constants.bottomBorderName })
navigationBar.standardAppearance = barAppearance
navigationBar.scrollEdgeAppearance = barAppearance
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class AddPromiseCompleteViewController: BaseViewController {
override func viewDidLoad() {
super.viewDidLoad()

setupNavigationBarTitle(with: "내 모임 추가하기")
setupNavigationBarTitle(with: "내 모임 추가하기", isBorderHidden: true)
navigationItem.hidesBackButton = true
}

Expand All @@ -63,7 +63,6 @@ final class AddPromiseCompleteViewController: BaseViewController {
animated: false
)
rootViewController.navigationController?.pushViewController(

PromiseViewController(
viewModel: PromiseViewModel(
promiseID: owner.promiseID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ final class AddPromiseViewController: BaseViewController {
override func viewDidLoad() {
super.viewDidLoad()

setupNavigationBarTitle(with: "약속 추가하기")
setupNavigationBarTitle(with: "약속 추가하기", isBorderHidden: true)
setupNavigationBarBackButton()

bindViewModel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ final class SelectMemberViewController: BaseViewController {
override func viewDidLoad() {
super.viewDidLoad()

setupNavigationBarTitle(with: "약속 추가하기")
setupNavigationBarTitle(with: "약속 추가하기", isBorderHidden: true)
setupNavigationBarBackButton()

bindViewModel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class SelectPenaltyViewController: BaseViewController {
override func viewDidLoad() {
super.viewDidLoad()

setupNavigationBarTitle(with: "약속 추가하기")
setupNavigationBarTitle(with: "약속 추가하기", isBorderHidden: true)
setupNavigationBarBackButton()

bindViewModel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private extension MeetingInfoViewController {
output.info
.drive(with: self) { owner, meetingInfo in
guard let info = meetingInfo else { return }
owner.title = info.name
owner.setupNavigationBarTitle(with: info.name)
owner.rootView.configureInfo(
createdAt: info.createdAt,
metCount: info.metCount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class LoginViewController: BaseViewController {
let mainTabBarController = MainTabBarController()
let navigationController = UINavigationController(
rootViewController: mainTabBarController,
isBorderNeeded: true
isBorderNeeded: false
)
navigationController.isNavigationBarHidden = true
navigationController.modalPresentationStyle = .fullScreen
Expand All @@ -102,7 +102,7 @@ class LoginViewController: BaseViewController {
} else {
let navigationController = UINavigationController(
rootViewController: nicknameViewController,
isBorderNeeded: true
isBorderNeeded: false
)
navigationController.modalPresentationStyle = .fullScreen
navigationController.modalTransitionStyle = .crossDissolve
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class WelcomeViewController: BaseViewController {

let navigationController = UINavigationController(
rootViewController: mainTabBarController,
isBorderNeeded: true
isBorderNeeded: false
)

navigationController.isNavigationBarHidden = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class PromiseViewController: BaseViewController {
private extension PromiseViewController {
func setupBindings() {
viewModel.promiseInfo.bindOnMain(with: self) { owner, info in
owner.setupNavigationBarTitle(with: info?.promiseName ?? "", isBorderHidden: false)
owner.setupNavigationBarTitle(with: info?.promiseName ?? "", isBorderHidden: true)

owner.promiseInfoViewController.rootView.editButton.isHidden = !(info?.isParticipant ?? false)
owner.setupPromiseEditButton(isHidden: !(info?.isParticipant ?? false))
Expand Down

0 comments on commit 3414f5a

Please sign in to comment.