Skip to content

[IDLE-120] Coordinator종류별 정의 #9

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 1 commit into from
Jun 30, 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
4 changes: 4 additions & 0 deletions project/Projects/App/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ let project = Project(
sources: ["Sources/**"],
resources: ["Resources/**"],
dependencies: [

// Presentation
D.Presentation.PresentationCore,

// Domain
D.Domain.ConcreteUseCase,

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// RootCoordinator+Extension.swift
// Idle-iOS
//
// Created by choijunios on 6/30/24.
//

import Foundation

extension RootCoordinator {

func auth() {

}
}
98 changes: 98 additions & 0 deletions project/Projects/App/Sources/RootCoordinator/RootCoordinator.swift
Original file line number Diff line number Diff line change
@@ -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),
])
}
}
14 changes: 12 additions & 2 deletions project/Projects/App/Sources/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
30 changes: 10 additions & 20 deletions project/Projects/Data/ConcretesTests/ConcretesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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()
}

Original file line number Diff line number Diff line change
@@ -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