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

[GWL-49] RecordFeature Coordinator Flow 구성 #84

Merged
merged 4 commits into from
Nov 20, 2023
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 @@ -9,6 +9,8 @@
import Coordinator
import UIKit

// MARK: - AppCoordinator

final class AppCoordinator: AppCoordinating {
var navigationController: UINavigationController
var childCoordinators: [Coordinating] = []
Expand All @@ -28,11 +30,19 @@ final class AppCoordinator: AppCoordinating {
tabBarCoordinator.start()
}

func startLoginFlow() {
func showLoginFlow() {
// (LoginViewController 추가되면 로직 추가) (todo)
}

func startTabBarFlow() {
func showTabBarFlow() {
// (TabBarController 추가되면 로직 추가) (todo)
}
}

// MARK: CoordinatorFinishDelegate

extension AppCoordinator: CoordinatorFinishDelegate {
func flowDidFinished(childCoordinator: Coordinating) {
// TODO: 로그아웃 Flow, 로그인 Flow (앱 실행 도중 발생되는 분기처리)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ import Coordinator
import Foundation

protocol AppCoordinating: Coordinating {
func startLoginFlow()
func startTabBarFlow()
func showLoginFlow()
func showTabBarFlow()
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ final class TabBarCoordinator: TabBarCoordinating {
navigationController.pushViewController(tabBarController, animated: false)
}

private func makePageNavigationController(page: TabBarPage) -> UINavigationController {
let navigationController = UINavigationController()
let tabBarItem = UITabBarItem(title: page.title, image: page.image, selectedImage: page.selectedImage)
navigationController.tabBarItem = tabBarItem
startTabBarCoordinator(page: page, pageNavigationViewController: navigationController)
return navigationController
}

private func startTabBarCoordinator(page: TabBarPage, pageNavigationViewController: UINavigationController) {
switch page {
case .home:
Expand All @@ -54,14 +62,6 @@ final class TabBarCoordinator: TabBarCoordinating {
}
}

private func makePageNavigationController(page: TabBarPage) -> UINavigationController {
let navigationController = UINavigationController()
let tabBarItem = UITabBarItem(title: page.title, image: page.image, selectedImage: page.selectedImage)
navigationController.tabBarItem = tabBarItem
startTabBarCoordinator(page: page, pageNavigationViewController: navigationController)
return navigationController
}

private func makeTabBarController(
tabBarViewControllers: [UIViewController]
) -> UITabBarController {
Expand Down
2 changes: 2 additions & 0 deletions iOS/Projects/Core/Coordinator/Sources/CoordinatorFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ import Foundation
public enum CoordinatorFlow {
case login
case tabBar
case workoutSetting
case workout
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// WorkoutSettingCoordinatorFinishDelegate.swift
// RecordFeature
//
// Created by 안종표 on 2023/11/20.
// Copyright © 2023 kr.codesquad.boostcamp8. All rights reserved.
//

import Foundation

protocol WorkoutSettingCoordinatorFinishDelegate: AnyObject {
func workoutSettingCoordinatorDidFinished(workoutSetting: WorkoutSetting)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// RecordFeatureCoordinating.swift
// RecordFeature
//
// Created by 안종표 on 2023/11/20.
// Copyright © 2023 kr.codesquad.boostcamp8. All rights reserved.
//

import Coordinator
import Foundation

protocol RecordFeatureCoordinating: Coordinating {
func showSettingFlow()
func showWorkoutFlow(workoutSetting: WorkoutSetting)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// WorkoutCoordinating.swift
// RecordFeature
//
// Created by 안종표 on 2023/11/20.
// Copyright © 2023 kr.codesquad.boostcamp8. All rights reserved.
//

import Coordinator
import Foundation

protocol WorkoutCoordinating: Coordinating {
func pushWorkoutSummaryViewController()
func pushWorkoutMapViewController()
func pushWorkoutResultViewController()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// WorkoutSettingCoordinating.swift
// RecordFeature
//
// Created by 안종표 on 2023/11/20.
// Copyright © 2023 kr.codesquad.boostcamp8. All rights reserved.
//

import Coordinator
import Foundation

protocol WorkoutSettingCoordinating: Coordinating {
func pushWorkoutSelectViewController()
func pushWorkoutEnvironmentSetupViewController(workoutSetting: WorkoutSetting)
func pushOpponentSearchViewController(workoutSetting: WorkoutSetting)
func pushCountdownViewController(workoutSetting: WorkoutSetting)
func finish(workoutSetting: WorkoutSetting)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// RecordFeatureCoordinator.swift
// RecordFeature
//
// Created by 안종표 on 2023/11/20.
// Copyright © 2023 kr.codesquad.boostcamp8. All rights reserved.
//

import Coordinator
import UIKit

// MARK: - RecordFeatureCoordinator

public final class RecordFeatureCoordinator: RecordFeatureCoordinating {
public var navigationController: UINavigationController
public var childCoordinators: [Coordinating] = []
public weak var finishDelegate: CoordinatorFinishDelegate?
public var flow: CoordinatorFlow = .workoutSetting
public var recordContainerViewController: RecordContainerViewController

public init(
navigationController: UINavigationController
) {
self.navigationController = navigationController
recordContainerViewController = RecordContainerViewController()
}

public func start() {
navigationController.pushViewController(recordContainerViewController, animated: false)
}

func showSettingFlow() {
let workoutSettingCoordinator = WorkoutSettingCoordinator(navigationController: navigationController)
childCoordinators.append(workoutSettingCoordinator)
workoutSettingCoordinator.finishDelegate = self
workoutSettingCoordinator.settingDidFinishedDelegate = self
workoutSettingCoordinator.start()
}

func showWorkoutFlow(workoutSetting _: WorkoutSetting) {
let workoutCoordinator = WorkoutCoordinator(navigationController: navigationController)
childCoordinators.append(workoutCoordinator)
workoutCoordinator.finishDelegate = self
workoutCoordinator.start()
}
}

// MARK: CoordinatorFinishDelegate

extension RecordFeatureCoordinator: CoordinatorFinishDelegate {
public func flowDidFinished(childCoordinator: Coordinating) {
childCoordinators = childCoordinators.filter {
$0.flow != childCoordinator.flow
}
navigationController.popToRootViewController(animated: false)
}
}

// MARK: WorkoutSettingCoordinatorFinishDelegate

extension RecordFeatureCoordinator: WorkoutSettingCoordinatorFinishDelegate {
func workoutSettingCoordinatorDidFinished(workoutSetting: WorkoutSetting) {
showWorkoutFlow(workoutSetting: workoutSetting)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// WorkoutCoordinator.swift
// RecordFeature
//
// Created by 안종표 on 2023/11/20.
// Copyright © 2023 kr.codesquad.boostcamp8. All rights reserved.
//

import Coordinator
import UIKit

final class WorkoutCoordinator: WorkoutCoordinating {
var navigationController: UINavigationController
var childCoordinators: [Coordinating] = []
weak var finishDelegate: CoordinatorFinishDelegate?
var flow: CoordinatorFlow = .workout

init(navigationController: UINavigationController) {
self.navigationController = navigationController
}

func start() {
pushWorkoutSummaryViewController()
}

func pushWorkoutSummaryViewController() {
let workoutSummaryViewController = WorkoutSummaryViewController(
viewModel: WorkoutSummaryViewModel()
)
navigationController.pushViewController(workoutSummaryViewController, animated: false)
}

func pushWorkoutMapViewController() {
// TODO: 뷰 컨트롤러 시작 로직 작성
}

func pushWorkoutResultViewController() {
// TODO: 뷰 컨트롤러 시작 로직 작성
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// WorkoutSettingCoordinator.swift
// RecordFeature
//
// Created by 안종표 on 2023/11/20.
// Copyright © 2023 kr.codesquad.boostcamp8. All rights reserved.
//

import Coordinator
import UIKit

final class WorkoutSettingCoordinator: WorkoutSettingCoordinating {
var navigationController: UINavigationController
var childCoordinators: [Coordinating] = []
weak var finishDelegate: CoordinatorFinishDelegate?
var flow: CoordinatorFlow = .workoutSetting
weak var settingDidFinishedDelegate: WorkoutSettingCoordinatorFinishDelegate?

init(navigationController: UINavigationController) {
self.navigationController = navigationController
}

func start() {
pushWorkoutSelectViewController()
}

func pushWorkoutSelectViewController() {
let workoutSelectViewController = WorkoutSelectViewController()
navigationController.pushViewController(workoutSelectViewController, animated: false)
}

func pushWorkoutEnvironmentSetupViewController(workoutSetting _: WorkoutSetting) {
// TODO: WorkoutEnvironmentSetupViewController의 Usecase에 workoutSetting 객체를 전달해줘야한다.
let workoutEnvironmentViewController = WorkoutEnvironmentSetupViewController()
navigationController.pushViewController(workoutEnvironmentViewController, animated: false)
}

func pushOpponentSearchViewController(workoutSetting _: WorkoutSetting) {
// TODO: 뷰 컨트롤러 시작 로직 작성
}

func pushCountdownViewController(workoutSetting _: WorkoutSetting) {
// TODO: 뷰 컨트롤러 시작 로직 작성
}

func finish(workoutSetting: WorkoutSetting) {
settingDidFinishedDelegate?.workoutSettingCoordinatorDidFinished(workoutSetting: workoutSetting)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// WorkoutSetting.swift
// RecordFeature
//
// Created by 안종표 on 2023/11/20.
// Copyright © 2023 kr.codesquad.boostcamp8. All rights reserved.
//

import Foundation

// MARK: - WorkoutSetting

struct WorkoutSetting {
let mode: WorkoutMode
let environment: WorkoutEnvironment
let opponents: [Opponent]
}

// MARK: - WorkoutMode

enum WorkoutMode {
case run
case swim
case cycle
}

// MARK: - WorkoutEnvironment

enum WorkoutEnvironment {
case single
case multi
}

// MARK: - Opponent

struct Opponent {
let name: String
let distance: Int
}

This file was deleted.