Skip to content

Commit

Permalink
[#26] HandyNavigation 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jysuhr committed Nov 29, 2024
1 parent c38b0f9 commit 2911ac3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 31 deletions.
18 changes: 5 additions & 13 deletions Handy/Handy-Storybook/Component/NavigationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ import Handy
import SnapKit

class NavigationViewController: HandyNavigation {

let page1: UIViewController = {
let viewController = UIViewController()
viewController.view.backgroundColor = HandySemantic.bgBasicStrong
viewController.view.backgroundColor = HandySemantic.bgStatusPositive
viewController.tabBarItem = UITabBarItem(title: "Label", image: HandyIcon.icHomeFilled, selectedImage: HandyIcon.icHomeFilled)
return viewController
}()

let page2: UIViewController = {
let viewController = UIViewController()
viewController.view.backgroundColor = HandySemantic.bgStatusPositive
viewController.view.backgroundColor = HandySemantic.bgBasicBlack
viewController.tabBarItem = UITabBarItem(title: "Label", image: HandyIcon.icHomeFilled, selectedImage: HandyIcon.icHomeFilled)
return viewController
}()
Expand All @@ -40,22 +41,13 @@ class NavigationViewController: HandyNavigation {

let page5: UIViewController = {
let viewController = UIViewController()
viewController.view.backgroundColor = HandySemantic.bgBasicLight
viewController.view.backgroundColor = HandySemantic.iconBasicSecondary
viewController.tabBarItem = UITabBarItem(title: "Label", image: HandyIcon.icHomeFilled, selectedImage: HandyIcon.icHomeFilled)
return viewController
}()

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)

self.setViewControllers([page1, page2, page3, page4, page5], animated: true)
}

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

override func viewDidLoad() {
super.viewDidLoad()
setViewControllers([page1, page2, page3, page4, page5], animated: false)
}
}
42 changes: 24 additions & 18 deletions Handy/Handy/Source/Component/HandyNavigation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ open class HandyNavigation: UITabBarController {
/// 상단 탭바에 사용되는 디바이더입니다.
let divider = HandyDivider()

private let customTabBar = CustomTabBar()

open override func viewDidLoad() {
super.viewDidLoad()
setupView()
}

/// 뷰 세팅
private func setupView() {
setValue(customTabBar, forKey: "tabBar")
setProperties()
setLayouts()
}
Expand Down Expand Up @@ -81,13 +84,8 @@ extension HandyNavigation {
viewControllers?.forEach {
if $0.tabBarItem.title == nil {
// title이 없는 경우
$0.tabBarItem.imageInsets = UIEdgeInsets(top: itemImageVerticalInset,
left: 0,
bottom: -itemImageVerticalInset,
right: 0)
$0.tabBarItem.imageInsets = UIEdgeInsets(top: itemImageVerticalInset, left: 0, bottom: -itemImageVerticalInset, right: 0)
} else {
// FIXME: 레이아웃 적용 안됨
// title이 있는 경우: 이미지와 텍스트 위치 조정
tabBarItem.imageInsets = UIEdgeInsets(
top: itemImageVerticalInset,
left: 0,
Expand All @@ -99,16 +97,24 @@ extension HandyNavigation {
}
}

/**
TODO: 레이아웃 간격
- UITabBar의 높이 설정 불가
- UITabBar의 아이콘 크기 설정 불가
*/
//MARK: - 네비게이션 바 레이아웃 설정 (Safe Area 처리)
class CustomTabBar: UITabBar {
let fixedHeight: CGFloat = 56

/**
파일 변경점
1. Component폴더 생성
2. HandyNavigation.swift 생성
3. HandyIcon.swift 파일에 icHomeFilled 추가
4. Asset/HandyIcon에 이미지 추가
*/
override func layoutSubviews() {
super.layoutSubviews()

// Safe Area를 고려한 높이 설정
var newFrame = self.frame
let safeAreaInsets: CGFloat = {
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.windows.first {
return window.safeAreaInsets.bottom
}
return 0
}()
newFrame.size.height = fixedHeight + safeAreaInsets
newFrame.origin.y = UIScreen.main.bounds.height - newFrame.size.height
self.frame = newFrame
}
}

0 comments on commit 2911ac3

Please sign in to comment.