Skip to content

[IDLE-313] 요양보호사 메인화면 탭바 구현 #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CenterMainCoordinator: CenterMainCoordinatable {
)
}

let tabController = IdleTabBar()
let tabController = IdleTabBarProto()
tabController.setViewControllers(info: tabInfo)
tabController.selectedIndex = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,76 +31,61 @@ class WorkerMainCoordinator: ParentCoordinator {

func start() {

let tabInfo = WorkerMainScreen.allCases.map { tab in
let pageInfo = IdleWorkerMainPage.allCases.map { page in

TabBarInfo(
viewController: createNavForTab(tab: tab),
tabBarItem: .init(
name: tab.name
)
let navigationController = createNavForTab(page: page)

return IdleTabBar.PageTabItemInfo(
page: page,
navigationController: navigationController
)
}

let tabController = IdleTabBar()
tabController.setViewControllers(info: tabInfo)
tabController.selectedIndex = 0
let tabController = IdleTabBar(
initialPage: IdleWorkerMainPage.home,
info: pageInfo
)


navigationController.pushViewController(tabController, animated: false)
}

// #1. Tab별 네비게이션 컨트롤러 생성
func createNavForTab(tab: WorkerMainScreen) -> UINavigationController {
func createNavForTab(page: IdleWorkerMainPage) -> UINavigationController {

let tabNavController = UINavigationController()
tabNavController.setNavigationBarHidden(false, animated: false)

startTabCoordinator(
tab: tab,
page: page,
navigationController: tabNavController
)

return tabNavController
}
// #2. 생성한 컨트롤러를 각 탭별 Coordinator에 전달
func startTabCoordinator(tab: WorkerMainScreen, navigationController: UINavigationController) {
func startTabCoordinator(page: IdleWorkerMainPage, navigationController: UINavigationController) {

var coordinator: ChildCoordinator!

switch tab {
case .recruitmentBoard:
switch page {
case .home:
coordinator = RecruitmentBoardCoordinator(
navigationController: navigationController
)
case .applyManagement:
case .preferredPost:
coordinator = ApplyManagementCoordinator(
navigationController: navigationController
)
case .setting:
coordinator = SettingCoordinator(
coordinator = RecruitmentBoardCoordinator(
navigationController: navigationController
)
}

addChildCoordinator(coordinator)

// 코디네이터들을 실행
coordinator.start()
}
}

// MARK: Worker 탭의 구성요소들
enum WorkerMainScreen: Int, CaseIterable {
case recruitmentBoard = 0
case applyManagement = 1
case setting = 2

var name: String {
switch self {
case .recruitmentBoard:
"채용"
case .applyManagement:
"공고관리"
case .setting:
"설정"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ extension RootCoordinator {
/// 로그인및 회원가입을 실행합니다.
func auth() {

let authCoordinator = AuthCoordinator(
let coordinator = AuthCoordinator(
dependency: .init(
navigationController: navigationController,
injector: injector
)
)

authCoordinator.start()
coordinator.parent = self

addChildCoordinator(coordinator)

coordinator.start()
}

/// 요양보호사 메인화면을 실행합니다.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class RootCoordinator: ParentCoordinator {
func start() {
navigationController.setNavigationBarHidden(true, animated: false)

centerMain()
workerMain()
}

func popViewController() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "worker_home.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "worker_post.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "worker_setting.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// IdleTabBar.swift
// IdleTabBarProto.swift
// PresentationCore
//
// Created by choijunios on 7/25/24.
Expand All @@ -10,14 +10,14 @@ import RxSwift
import RxCocoa
import PresentationCore

public class IdleTabBar: UIViewController {
public class IdleTabBarProto: UIViewController {

// Coordinator
public weak var coordinator: ParentCoordinator?

// 탭바구성
public private(set) var viewControllers: [UIViewController] = []
private var tabBarItems: [IdleTabBarItem] = []
private var tabBarItems: [IdleTabBarItemProto] = []

// View
var tabBarItemStack: UIView!
Expand Down Expand Up @@ -151,7 +151,7 @@ public protocol IdleTabBarItemViewable: UIView {
}


public struct IdleTabBarItem {
public struct IdleTabBarItemProto {
let name: String

public init(name: String) {
Expand All @@ -161,9 +161,9 @@ public struct IdleTabBarItem {

public struct TabBarInfo {
let viewController: UIViewController
let tabBarItem: IdleTabBarItem
let tabBarItem: IdleTabBarItemProto

public init(viewController: UIViewController, tabBarItem: IdleTabBarItem) {
public init(viewController: UIViewController, tabBarItem: IdleTabBarItemProto) {
self.viewController = viewController
self.tabBarItem = tabBarItem
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//
// itemView.swift
// DSKit
//
// Created by choijunios on 8/15/24.
//

import UIKit
import RxSwift
import RxCocoa

/// 메인 화면의 탭바 아이템으로 사용됩니다.
public class IdleTabBarItem: TappableUIView {

// Init
public let index: Int

// State components
public enum State {
case idle
case accent
}

// idle
let idleIconColor: UIColor = DSColor.gray300.color


// accent
let accentIconColor: UIColor = DSColor.gray700.color

// View
let label: IdleLabel = {
let label = IdleLabel(typography: .caption)
label.attrTextColor = DSColor.gray700.color
return label
}()
let imageView: UIImageView = {
let view = UIImageView()
view.contentMode = .scaleAspectFit
return view
}()

public init(index: Int, labelText: String, image: UIImage) {
self.index = index
self.label.textString = labelText
self.imageView.image = image

super.init()

setAppearance()
setLayout()
}
public required init?(coder: NSCoder) { nil }

private func setAppearance() {
imageView.tintColor = idleIconColor
}

private func setLayout() {
let mainStack = VStack([imageView, label], spacing: 4, alignment: .center)

self.addSubview(mainStack)
mainStack.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint.activate([
imageView.widthAnchor.constraint(equalToConstant: 32),
imageView.heightAnchor.constraint(equalTo: imageView.widthAnchor),

mainStack.topAnchor.constraint(equalTo: self.topAnchor),
mainStack.leftAnchor.constraint(equalTo: self.leftAnchor),
mainStack.rightAnchor.constraint(equalTo: self.rightAnchor),
mainStack.bottomAnchor.constraint(equalTo: self.bottomAnchor),
])
}

/// 탭바 아이템의 상태를 변경합니다.
public func setState(_ state: State, duration: CGFloat = 0.2) {
UIView.animate(withDuration: duration) { [weak self] in
if state == .accent {
self?.setToAccent()
} else {
self?.setToIdle()
}
}
}

private func setToIdle() {
imageView.tintColor = idleIconColor
}

private func setToAccent() {
imageView.tintColor = accentIconColor
}
}

Loading
Loading