-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[REFACTOR] Coordinator
- Loading branch information
Showing
43 changed files
with
1,239 additions
and
402 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// AppCoordinator.swift | ||
// Makgulli | ||
// | ||
// Created by kyuchul on 11/22/24. | ||
// | ||
|
||
import UIKit | ||
|
||
import Combine | ||
|
||
enum AppFlow { | ||
case main | ||
case login | ||
} | ||
|
||
final class AppCoordinator: Coordinator { | ||
weak var parentCoordinator: (any Coordinator)? | ||
var childCoordinators: [any Coordinator] = [] | ||
var navigationController: UINavigationController | ||
let flow = PassthroughSubject<AppFlow, Never>() | ||
private var cancellable = Set<AnyCancellable>() | ||
|
||
init(navigationController: UINavigationController) { | ||
self.navigationController = navigationController | ||
bindState() | ||
} | ||
|
||
func bindState() { | ||
flow | ||
.sink { [weak self] flow in | ||
switch flow { | ||
case .main: | ||
self?.startTabBar() | ||
case .login: | ||
break | ||
} | ||
} | ||
.store(in: &cancellable) | ||
} | ||
|
||
func start() { | ||
startSplash() | ||
} | ||
} | ||
|
||
extension AppCoordinator { | ||
private func startSplash() { | ||
let splashViewController = SplashViewController(coordinator: self) | ||
navigationController.setNavigationBarHidden(true, animated: false) | ||
setViewController(viewController: splashViewController, animated: false) | ||
} | ||
|
||
private func startTabBar() { | ||
let tabBarCoordinator = TabBarCoordinator(navigationController: navigationController) | ||
tabBarCoordinator.parentCoordinator = self | ||
tabBarCoordinator.start() | ||
|
||
self.addDependency(tabBarCoordinator) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// | ||
// Coordinator.swift | ||
// Makgulli | ||
// | ||
// Created by kyuchul on 11/22/24. | ||
// | ||
|
||
import UIKit | ||
|
||
protocol Coordinatable { | ||
associatedtype CoordinatorType: Coordinator | ||
|
||
var coordinator: CoordinatorType? { get } | ||
} | ||
|
||
protocol Coordinator: AnyObject { | ||
// 부모 코디네이터 | ||
var parentCoordinator: Coordinator? { get set } | ||
// 모든 코디네이터는 자신의 자식 코디네이터를 관리 | ||
var childCoordinators: [Coordinator] { get set } | ||
// 뷰컨트롤러를 보여줄 때 사용될 내비게이션 컨트롤러를 저장 | ||
var navigationController: UINavigationController { get set } | ||
// 해당 코디네이터가 제어권을 갖도록 하는 메서드. 완전히 만들고 준비되었을 때만 코디네이터를 활성화 | ||
func start() | ||
} | ||
|
||
extension Coordinator { | ||
func addDependency(_ coordinator: Coordinator) { | ||
for element in childCoordinators { | ||
if element === coordinator { return } | ||
} | ||
childCoordinators.append(coordinator) | ||
} | ||
|
||
func removeDependency(_ coordinator: Coordinator?) { | ||
for (index, element) in childCoordinators.enumerated() where element === coordinator { | ||
childCoordinators.remove(at: index) | ||
break | ||
} | ||
} | ||
|
||
func printStack() { | ||
let viewControllers = navigationController.viewControllers | ||
for (index, viewController) in viewControllers.enumerated() { | ||
print("\(index): \(Swift.type(of: viewController))") | ||
} | ||
} | ||
} | ||
|
||
extension Coordinator { | ||
func push(viewController: UIViewController, navibarHidden: Bool = true, swipe: Bool = true, animated: Bool = true) { | ||
navigationController.setNavigationBarHidden(navibarHidden, animated: true) | ||
|
||
if swipe { | ||
self.navigationController.interactivePopGestureRecognizer?.isEnabled = swipe | ||
self.navigationController.interactivePopGestureRecognizer?.delegate = nil | ||
} | ||
|
||
navigationController.pushViewController(viewController, animated: animated) | ||
} | ||
|
||
func present(_ viewController: UIViewController, style: UIModalPresentationStyle) { | ||
viewController.modalPresentationStyle = style | ||
navigationController.present(viewController, animated: true) | ||
} | ||
|
||
func pop() { | ||
navigationController.popViewController(animated: true) | ||
} | ||
|
||
func dismiss(animated: Bool = true,completion: (() -> Void)? = nil) { | ||
navigationController.dismiss(animated: animated, completion: completion) | ||
} | ||
|
||
func setViewController(viewController: UIViewController, animated: Bool = true) { | ||
navigationController.setViewControllers([viewController], animated: animated) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// SettingDIContainer.swift | ||
// Makgulli | ||
// | ||
// Created by kyuchul on 11/25/24. | ||
// | ||
|
||
import Foundation | ||
|
||
final class AppInfoDIContainer { | ||
// MARK: - ViewModel | ||
func makeAppInfoViewModel() -> AppInfoViewModel { | ||
AppInfoViewModel() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// UIApplication+.swift | ||
// Makgulli | ||
// | ||
// Created by kyuchul on 11/25/24. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UIApplication { | ||
var keyWindowInConnectedScenes: UIWindow? { | ||
return connectedScenes | ||
.compactMap { $0 as? UIWindowScene } | ||
.flatMap { $0.windows } | ||
.first { $0.isKeyWindow } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
Makgulli/Common/UIComponent/NavigationBar/JumakNavigationBar.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// | ||
// JumakNavigationBar.swift | ||
// Makgulli | ||
// | ||
// Created by kyuchul on 11/25/24. | ||
// | ||
|
||
import UIKit | ||
|
||
import RxSwift | ||
import RxCocoa | ||
|
||
final class JumakNavigationBar: BaseView { | ||
|
||
private let containerView = UIView() | ||
private let backButton: UIButton = { | ||
let button = UIButton() | ||
button.setImage(ImageLiteral.back, for: .normal) | ||
button.tintColor = .black | ||
return button | ||
}() | ||
|
||
private let titleLabel: UILabel = { | ||
let label = UILabel() | ||
label.textColor = .black | ||
label.font = UIFont.boldLineSeed(size: ._16) | ||
label.textAlignment = .center | ||
return label | ||
}() | ||
|
||
private var rightItems: [UIView] = [] | ||
private let rightStackView: UIStackView = { | ||
let stackView = UIStackView() | ||
stackView.axis = .horizontal | ||
stackView.spacing = 8 | ||
stackView.alignment = .center | ||
return stackView | ||
}() | ||
|
||
init(rightItems: [UIView] = []) { | ||
self.rightItems = rightItems | ||
super.init(frame: .zero) | ||
configureRightItems() | ||
} | ||
|
||
override func setHierarchy() { | ||
addSubview(containerView) | ||
|
||
[backButton, titleLabel, rightStackView] | ||
.forEach { | ||
containerView.addSubview($0) | ||
} | ||
} | ||
|
||
override func setConstraints() { | ||
self.snp.makeConstraints { make in | ||
make.height.equalTo(52) | ||
} | ||
|
||
containerView.snp.makeConstraints { make in | ||
make.edges.equalToSuperview() | ||
} | ||
|
||
backButton.snp.makeConstraints { make in | ||
make.leading.equalToSuperview().offset(12) | ||
make.centerY.equalToSuperview() | ||
make.size.equalTo(26) | ||
} | ||
|
||
titleLabel.snp.makeConstraints { make in | ||
make.center.equalToSuperview() | ||
} | ||
|
||
rightStackView.snp.makeConstraints { make in | ||
make.trailing.equalToSuperview().inset(12) | ||
make.centerY.equalToSuperview() | ||
} | ||
} | ||
|
||
override func setLayout() { | ||
self.backgroundColor = .white | ||
} | ||
} | ||
|
||
private extension JumakNavigationBar { | ||
func configureRightItems() { | ||
rightItems.forEach { | ||
$0.snp.makeConstraints { make in | ||
make.size.equalTo(26) | ||
} | ||
} | ||
|
||
rightItems.forEach { rightStackView.addArrangedSubview($0) } | ||
} | ||
} | ||
|
||
extension JumakNavigationBar { | ||
func setTitle(_ title: String) { | ||
titleLabel.text = title | ||
} | ||
|
||
func hideBackButton() { | ||
backButton.isHidden = true | ||
} | ||
|
||
func backButtonAction() -> Observable<Void> { | ||
return backButton.rx.tap.asObservable() | ||
} | ||
} |
Oops, something went wrong.