Skip to content
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

[리팩토링] 홈 화면 Status Bar 접근 로직 리팩토링 #320

Merged
merged 2 commits into from
Nov 30, 2021
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
5 changes: 3 additions & 2 deletions BBus/BBus/Foreground/Home/HomeCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ final class HomeCoordinator: SearchPushable, BusRoutePushable, AlarmSettingPusha
self.navigationPresenter = presenter
}

func start() {
func start(statusBarHeight: CGFloat?) {
let apiUseCases = BBusAPIUseCases(networkService: NetworkService(),
persistenceStorage: PersistenceStorage(),
tokenManageType: TokenManager.self,
requestFactory: RequestFactory())
let apiUseCase = HomeAPIUseCase(useCases: apiUseCases)
let calculateUseCase = HomeCalculateUseCase()
let viewModel = HomeViewModel(apiUseCase: apiUseCase, calculateUseCase: calculateUseCase)
let viewController = HomeViewController(viewModel: viewModel)
let viewController = HomeViewController(viewModel: viewModel, statusBarHegiht: statusBarHeight)
viewController.coordinator = self

navigationPresenter.pushViewController(viewController, animated: false) // present
}
}
18 changes: 9 additions & 9 deletions BBus/BBus/Foreground/Home/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ final class HomeViewController: UIViewController, BaseViewControllerType {
private let viewModel: HomeViewModel?

private lazy var homeView = HomeView()

private let statusBarHeight: CGFloat?

private var cancellables: Set<AnyCancellable> = []

init(viewModel: HomeViewModel) {
init(viewModel: HomeViewModel, statusBarHegiht: CGFloat?) {
self.viewModel = viewModel
self.statusBarHeight = statusBarHegiht
super.init(nibName: nil, bundle: nil)
}

required init?(coder: NSCoder) {
self.viewModel = nil
self.statusBarHeight = nil
super.init(coder: coder)
}

Expand Down Expand Up @@ -53,20 +56,19 @@ final class HomeViewController: UIViewController, BaseViewControllerType {
// MARK: - Configuration
func configureLayout() {
self.view.addSubviews(self.homeView)

NSLayoutConstraint.activate([
self.homeView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor),
self.homeView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor),
self.homeView.leadingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.leadingAnchor),
self.homeView.trailingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.trailingAnchor)
])


self.homeView.configureLayout()
}

private func configureStatusBarLayout() {
let app = UIApplication.shared
let statusBarHeight: CGFloat = app.statusBarFrame.size.height

guard let statusBarHeight = self.statusBarHeight else { return }

let statusbarView = UIView()
statusbarView.backgroundColor = BBusColor.white //컬러 설정 부분

Expand All @@ -77,8 +79,6 @@ final class HomeViewController: UIViewController, BaseViewControllerType {
statusbarView.topAnchor.constraint(equalTo: self.view.topAnchor),
statusbarView.centerXAnchor.constraint(equalTo: self.view.centerXAnchor)
])

self.homeView.configureLayout()
}

func configureDelegate() {
Expand Down
7 changes: 5 additions & 2 deletions BBus/BBus/Global/Coordinator/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ final class AppCoordinator: NSObject, Coordinator {
var navigationPresenter: UINavigationController
var movingStatusPresenter: UIViewController?
var childCoordinators: [Coordinator]

var statusBarHeight: CGFloat? {
return self.navigationWindow.windowScene?.statusBarManager?.statusBarFrame.height
}

init(navigationWindow: UIWindow, movingStatusWindow: UIWindow) {
self.navigationWindow = navigationWindow
Expand All @@ -33,7 +37,7 @@ final class AppCoordinator: NSObject, Coordinator {
coordinator.delegate = self
coordinator.navigationPresenter = self.navigationPresenter
self.childCoordinators.append(coordinator)
coordinator.start()
coordinator.start(statusBarHeight: self.statusBarHeight)

self.navigationWindow.makeKeyAndVisible()
self.movingStatusWindow.makeKeyAndVisible()
Expand Down Expand Up @@ -191,4 +195,3 @@ extension AppCoordinator: CoordinatorFinishDelegate {
}
}
}

3 changes: 0 additions & 3 deletions BBus/BBus/Global/Coordinator/Coordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@ typealias CoordinatorDelegate = (CoordinatorFinishDelegate & CoordinatorCreateDe
protocol Coordinator: AnyObject {
var navigationPresenter: UINavigationController { get set }
var delegate: CoordinatorDelegate? { get set }
func start()
}

extension Coordinator {
func start() { }

func coordinatorDidFinish() {
self.delegate?.removeChildCoordinator(self)
}
Expand Down