From d099a56e15d0ad18b1fa8820cfa8f49cf9b84b7a Mon Sep 17 00:00:00 2001 From: J0onYEong Date: Sun, 30 Jun 2024 16:03:57 +0900 Subject: [PATCH] =?UTF-8?q?[IDLE-120]=20Coordinator=EC=A2=85=EB=A5=98?= =?UTF-8?q?=EB=B3=84=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project/Projects/App/Project.swift | 4 + .../RootCoordinator+Extension.swift | 15 +++ .../RootCoordinator/RootCoordinator.swift | 98 +++++++++++++++++++ .../Projects/App/Sources/SceneDelegate.swift | 14 ++- .../Data/ConcretesTests/ConcretesTests.swift | 30 ++---- .../Sources/Coordinator.swift | 12 --- .../ScreenCoordinating/Coordinator.swift | 46 +++++++++ .../DisposableViewController.swift | 15 +++ 8 files changed, 200 insertions(+), 34 deletions(-) create mode 100644 project/Projects/App/Sources/RootCoordinator/RootCoordinator+Extension.swift create mode 100644 project/Projects/App/Sources/RootCoordinator/RootCoordinator.swift delete mode 100644 project/Projects/Presentation/PresentationCore/Sources/Coordinator.swift create mode 100644 project/Projects/Presentation/PresentationCore/Sources/ScreenCoordinating/Coordinator.swift create mode 100644 project/Projects/Presentation/PresentationCore/Sources/ScreenCoordinating/DisposableViewController.swift diff --git a/project/Projects/App/Project.swift b/project/Projects/App/Project.swift index 75aa2266..bb0749ca 100644 --- a/project/Projects/App/Project.swift +++ b/project/Projects/App/Project.swift @@ -27,6 +27,10 @@ let project = Project( sources: ["Sources/**"], resources: ["Resources/**"], dependencies: [ + + // Presentation + D.Presentation.PresentationCore, + // Domain D.Domain.ConcreteUseCase, diff --git a/project/Projects/App/Sources/RootCoordinator/RootCoordinator+Extension.swift b/project/Projects/App/Sources/RootCoordinator/RootCoordinator+Extension.swift new file mode 100644 index 00000000..9addf432 --- /dev/null +++ b/project/Projects/App/Sources/RootCoordinator/RootCoordinator+Extension.swift @@ -0,0 +1,15 @@ +// +// RootCoordinator+Extension.swift +// Idle-iOS +// +// Created by choijunios on 6/30/24. +// + +import Foundation + +extension RootCoordinator { + + func auth() { + + } +} diff --git a/project/Projects/App/Sources/RootCoordinator/RootCoordinator.swift b/project/Projects/App/Sources/RootCoordinator/RootCoordinator.swift new file mode 100644 index 00000000..3286aa6d --- /dev/null +++ b/project/Projects/App/Sources/RootCoordinator/RootCoordinator.swift @@ -0,0 +1,98 @@ +// +// AppCoordinator.swift +// Idle-iOS +// +// Created by choijunios on 6/28/24. +// + +import UIKit +import PresentationCore + +class RootCoordinator: ParentCoordinator { + + var childCoordinators: [Coordinator] = [] + + var navigationController: UINavigationController + + init(navigationController: UINavigationController) { + self.navigationController = navigationController + } + + func start() { + + let coordinator = TestMainTabBarCoodinator( + navigationController: navigationController + ) + + coordinator.parent = self + addChildCoordinator(coordinator) + + coordinator.start() + } + + func popViewController() { + navigationController.popViewController(animated: false) + } +} + + +// MARK: Test MainTabBar +class TestMainTabBarCoodinator: ChildCoordinator { + + var navigationController: UINavigationController + + var parent: RootCoordinator? + + weak var viewControllerRef: DisposableViewController? + + init(navigationController: UINavigationController) { + self.navigationController = navigationController + } + + func start() { + + let viewController = TestMainTabBarController() + viewController.coordinator = self + + self.viewControllerRef = viewController + + navigationController.pushViewController(viewController, animated: false) + } + + func popViewController() { + + navigationController.popViewController(animated: true) + } + + func coordinatorDidFinish() { + + parent?.removeChildCoordinator(self) + } +} + +public class TestMainTabBarController: DisposableViewController { + + var coordinator: TestMainTabBarCoodinator? + + public func cleanUp() { + + coordinator?.coordinatorDidFinish() + } + + public override func viewDidLoad() { + + let initialLabel = UILabel() + + initialLabel.text = "테스트용 메인 탭바 화면입니다." + + view.backgroundColor = .white + + view.addSubview(initialLabel) + initialLabel.translatesAutoresizingMaskIntoConstraints = false + + NSLayoutConstraint.activate([ + initialLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor), + initialLabel.centerYAnchor.constraint(equalTo: view.centerYAnchor), + ]) + } +} diff --git a/project/Projects/App/Sources/SceneDelegate.swift b/project/Projects/App/Sources/SceneDelegate.swift index 015452b5..2c08c6aa 100644 --- a/project/Projects/App/Sources/SceneDelegate.swift +++ b/project/Projects/App/Sources/SceneDelegate.swift @@ -11,13 +11,23 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { var window: UIWindow? + var rootCoordinator: RootCoordinator? + func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { guard let windowScene = scene as? UIWindowScene else { return } - window = UIWindow(windowScene: windowScene) - window?.rootViewController = ViewController() + + let rootNavigationController = UINavigationController() + + rootCoordinator = RootCoordinator( + navigationController: rootNavigationController + ) + + rootCoordinator?.start() + + window?.rootViewController = rootNavigationController window?.makeKeyAndVisible() } } diff --git a/project/Projects/Data/ConcretesTests/ConcretesTests.swift b/project/Projects/Data/ConcretesTests/ConcretesTests.swift index bd6b92f7..807b1341 100644 --- a/project/Projects/Data/ConcretesTests/ConcretesTests.swift +++ b/project/Projects/Data/ConcretesTests/ConcretesTests.swift @@ -12,27 +12,17 @@ import XCTest final class ConcretesTests: XCTestCase { func testFunction() { - - let expectation = expectation(description: "Test function") - - let testStore = TestKeyValueStore() - - let testService = DefaultTestService(keyValueStore: testStore) - - let single = testService.testRequest() - - let _ = single.subscribe { people in - XCTAssertGreaterThanOrEqual(people.count, 1) - - expectation.fulfill() - } onFailure: { error in - - XCTFail(error.localizedDescription) - - expectation.fulfill() - } + // TODO: 토큰 API구현이후 테스트 코드 작성 예정 - waitForExpectations(timeout: 10, handler: nil) +// let expectation = expectation(description: "Test function") +// +// let testStore = TestKeyValueStore() +// +// let testService = DefaultTestService(keyValueStore: testStore) +// +// let single = testService.testRequest() +// +// waitForExpectations(timeout: 10, handler: nil) } } diff --git a/project/Projects/Presentation/PresentationCore/Sources/Coordinator.swift b/project/Projects/Presentation/PresentationCore/Sources/Coordinator.swift deleted file mode 100644 index ba6df900..00000000 --- a/project/Projects/Presentation/PresentationCore/Sources/Coordinator.swift +++ /dev/null @@ -1,12 +0,0 @@ -// -// Coordinator.swift -// FeatureManifests -// -// Created by 최준영 on 6/21/24. -// - -import Foundation - -public protocol Coordinator { - func start() -} diff --git a/project/Projects/Presentation/PresentationCore/Sources/ScreenCoordinating/Coordinator.swift b/project/Projects/Presentation/PresentationCore/Sources/ScreenCoordinating/Coordinator.swift new file mode 100644 index 00000000..1f30101a --- /dev/null +++ b/project/Projects/Presentation/PresentationCore/Sources/ScreenCoordinating/Coordinator.swift @@ -0,0 +1,46 @@ +// +// Coordinator.swift +// PresentationCore +// +// Created by 최준영 on 6/21/24. +// + +import UIKit + +// MARK: Coordinator +public protocol Coordinator: AnyObject { + + var navigationController: UINavigationController { get } + + func start() + func popViewController() +} + +// MARK: ParentCoordinator +public protocol ParentCoordinator: Coordinator { + + var childCoordinators: [Coordinator] { get set } + + func addChildCoordinator(_ coordinator: Coordinator) + func removeChildCoordinator(_ coordinator: Coordinator) +} + +public extension ParentCoordinator { + + func addChildCoordinator(_ coordinator: Coordinator) { + childCoordinators.append(coordinator) + } + + func removeChildCoordinator(_ coordinator: Coordinator) { + childCoordinators = childCoordinators.filter { $0 !== coordinator } + } +} + +// MARK: ChildCoordinator +public protocol ChildCoordinator: Coordinator { + + var viewControllerRef: DisposableViewController? { get } + + func coordinatorDidFinish() +} + diff --git a/project/Projects/Presentation/PresentationCore/Sources/ScreenCoordinating/DisposableViewController.swift b/project/Projects/Presentation/PresentationCore/Sources/ScreenCoordinating/DisposableViewController.swift new file mode 100644 index 00000000..28a60fda --- /dev/null +++ b/project/Projects/Presentation/PresentationCore/Sources/ScreenCoordinating/DisposableViewController.swift @@ -0,0 +1,15 @@ +// +// DisposableViewController.swift +// PresentationCore +// +// Created by choijunios on 6/30/24. +// + +import UIKit + +public protocol DisposableObject: AnyObject { + + func cleanUp() +} + +public typealias DisposableViewController = UIViewController & DisposableObject