From b941b0d7b66d14746b392553bc7b6d77d8547e3e Mon Sep 17 00:00:00 2001 From: MaraMincho <103064352+MaraMincho@users.noreply.github.com> Date: Tue, 9 Jan 2024 23:51:51 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20ProfileFeature=EC=99=80=20=EC=97=B0?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Coordinator/Sources/CoordinatorFlow.swift | 1 + iOS/Projects/Features/Profile/Project.swift | 2 +- .../Coordinator/ProfileCoordinator.swift | 19 ++++++++++++++++++- .../ContainerViewController.swift | 14 +++++--------- .../ContainerViewModel.swift | 9 +-------- .../Coordinator/WriteBoardCoordinator.swift | 12 ++++++++---- .../WorkoutHistorySelectViewController.swift | 2 +- 7 files changed, 35 insertions(+), 24 deletions(-) diff --git a/iOS/Projects/Core/Coordinator/Sources/CoordinatorFlow.swift b/iOS/Projects/Core/Coordinator/Sources/CoordinatorFlow.swift index 181cc528..5050e909 100644 --- a/iOS/Projects/Core/Coordinator/Sources/CoordinatorFlow.swift +++ b/iOS/Projects/Core/Coordinator/Sources/CoordinatorFlow.swift @@ -20,4 +20,5 @@ public enum CoordinatorFlow { case onboarding case profile case home + case writeBoard } diff --git a/iOS/Projects/Features/Profile/Project.swift b/iOS/Projects/Features/Profile/Project.swift index 88a5e6a4..cbe04024 100644 --- a/iOS/Projects/Features/Profile/Project.swift +++ b/iOS/Projects/Features/Profile/Project.swift @@ -17,7 +17,7 @@ let project = Project.makeModule( .commonNetworkingKeyManager, .keychain, .userInformationManager, - .feature(.writeBoard) + .feature(.writeBoard), ], testDependencies: [], resources: "Resources/**" diff --git a/iOS/Projects/Features/Profile/Sources/Presentation/Coordinator/ProfileCoordinator.swift b/iOS/Projects/Features/Profile/Sources/Presentation/Coordinator/ProfileCoordinator.swift index 60e67874..b480bf2b 100644 --- a/iOS/Projects/Features/Profile/Sources/Presentation/Coordinator/ProfileCoordinator.swift +++ b/iOS/Projects/Features/Profile/Sources/Presentation/Coordinator/ProfileCoordinator.swift @@ -11,6 +11,7 @@ import Keychain import Log import Trinet import UIKit +import WriteBoardFeature // MARK: - ProfileFinishFinishDelegate @@ -91,5 +92,21 @@ extension ProfileCoordinator: ProfileCoordinating { navigationController.pushViewController(viewController, animated: true) } - public func presentWriteBoard() {} + public func presentWriteBoard() { + let writeBoardCoordinator = WriteBoardCoordinator( + navigationController: navigationController, + delegate: self + ) + childCoordinators.append(writeBoardCoordinator) + writeBoardCoordinator.start() + } +} + +// MARK: CoordinatorFinishDelegate + +extension ProfileCoordinator: CoordinatorFinishDelegate { + public func flowDidFinished(childCoordinator: Coordinating) { + childCoordinators = childCoordinators.filter { $0.flow != childCoordinator.flow } + childCoordinator.childCoordinators.removeAll() + } } diff --git a/iOS/Projects/Features/WriteBoard/Sources/Presentation/Common/ContainerViewController/ContainerViewController.swift b/iOS/Projects/Features/WriteBoard/Sources/Presentation/Common/ContainerViewController/ContainerViewController.swift index dcb2d690..47247513 100644 --- a/iOS/Projects/Features/WriteBoard/Sources/Presentation/Common/ContainerViewController/ContainerViewController.swift +++ b/iOS/Projects/Features/WriteBoard/Sources/Presentation/Common/ContainerViewController/ContainerViewController.swift @@ -20,7 +20,6 @@ final class ContainerViewController: UINavigationController { private var subscriptions: Set = [] private var cancelWriteBoardPublisher: PassthroughSubject = .init() - private var dismissAlertPublisher: PassthroughSubject = .init() private var confirmAlertPublisher: PassthroughSubject = .init() // MARK: Initializations @@ -56,6 +55,7 @@ private extension ContainerViewController { func setup() { setupStyles() bind() + presentationController?.delegate = self } func setupStyles() { @@ -66,7 +66,6 @@ private extension ContainerViewController { let output = viewModel.transform( input: .init( showAlertPublisher: cancelWriteBoardPublisher.eraseToAnyPublisher(), - dismissAlertPublisher: dismissAlertPublisher.eraseToAnyPublisher(), dismissWriteBoardPublisher: confirmAlertPublisher.eraseToAnyPublisher() ) ) @@ -75,9 +74,6 @@ private extension ContainerViewController { case .showAlert: self?.showFinishAlert() - case .dismissAlert: - self?.dismissAlertPublisher.send() - case .idle: break } @@ -90,7 +86,8 @@ private extension ContainerViewController { extension ContainerViewController: UIAdaptivePresentationControllerDelegate { func presentationControllerShouldDismiss(_: UIPresentationController) -> Bool { - return true + showFinishAlert() + return false } private func showFinishAlert() { @@ -100,9 +97,7 @@ extension ContainerViewController: UIAdaptivePresentationControllerDelegate { preferredStyle: .alert ) - let cancelHandler: (UIAlertAction) -> Void = { [weak self] _ in - self?.dismissAlertPublisher.send() - } + let cancelHandler: (UIAlertAction) -> Void = { _ in return } let confirmHandler: (UIAlertAction) -> Void = { [weak self] _ in self?.confirmAlertPublisher.send() @@ -113,5 +108,6 @@ extension ContainerViewController: UIAdaptivePresentationControllerDelegate { alertController.addAction(cancelAction) alertController.addAction(confirmAction) + present(alertController, animated: true) } } diff --git a/iOS/Projects/Features/WriteBoard/Sources/Presentation/Common/ContainerViewController/ContainerViewModel.swift b/iOS/Projects/Features/WriteBoard/Sources/Presentation/Common/ContainerViewController/ContainerViewModel.swift index 40cff003..dd55f003 100644 --- a/iOS/Projects/Features/WriteBoard/Sources/Presentation/Common/ContainerViewController/ContainerViewModel.swift +++ b/iOS/Projects/Features/WriteBoard/Sources/Presentation/Common/ContainerViewController/ContainerViewModel.swift @@ -13,7 +13,6 @@ import Foundation public struct ContainerViewModelInput { let showAlertPublisher: AnyPublisher - let dismissAlertPublisher: AnyPublisher let dismissWriteBoardPublisher: AnyPublisher } @@ -24,7 +23,6 @@ public typealias ContainerViewModelOutput = AnyPublisher public enum ContainerState { case idle case showAlert - case dismissAlert } // MARK: - ContainerViewModelRepresentable @@ -58,11 +56,6 @@ extension ContainerViewModel: ContainerViewModelRepresentable { .map { _ in ContainerState.showAlert } .eraseToAnyPublisher() - let dismissAlert: ContainerViewModelOutput = input - .dismissAlertPublisher - .map { _ in ContainerState.dismissAlert } - .eraseToAnyPublisher() - input.dismissWriteBoardPublisher .sink { [weak self] _ in self?.coordinator?.cancelWriteBoard() @@ -71,6 +64,6 @@ extension ContainerViewModel: ContainerViewModelRepresentable { let initialState: ContainerViewModelOutput = Just(.idle).eraseToAnyPublisher() - return initialState.merge(with: showAlert, dismissAlert).eraseToAnyPublisher() + return initialState.merge(with: showAlert).eraseToAnyPublisher() } } diff --git a/iOS/Projects/Features/WriteBoard/Sources/Presentation/Common/Coordinator/WriteBoardCoordinator.swift b/iOS/Projects/Features/WriteBoard/Sources/Presentation/Common/Coordinator/WriteBoardCoordinator.swift index 8a8a9c5e..d133f964 100644 --- a/iOS/Projects/Features/WriteBoard/Sources/Presentation/Common/Coordinator/WriteBoardCoordinator.swift +++ b/iOS/Projects/Features/WriteBoard/Sources/Presentation/Common/Coordinator/WriteBoardCoordinator.swift @@ -37,7 +37,7 @@ public final class WriteBoardCoordinator: WriteBoardFeatureCoordinating { public init( navigationController: UINavigationController, - delegate: CoordinatorFinishDelegate + delegate: CoordinatorFinishDelegate? ) { self.navigationController = navigationController finishDelegate = delegate @@ -52,7 +52,7 @@ public final class WriteBoardCoordinator: WriteBoardFeatureCoordinating { let vc = ContainerViewController(viewModel: viewModel) containerViewController = vc - vc.modalPresentationStyle = .fullScreen + vc.modalPresentationStyle = .automatic navigationController.present(vc, animated: true) pushWorkoutHistorySelectScene() } @@ -61,12 +61,16 @@ public final class WriteBoardCoordinator: WriteBoardFeatureCoordinating { let viewModel = WorkoutHistorySelectViewModel() let viewController = WorkoutHistorySelectViewController(viewModel: viewModel) - containerViewController?.setViewControllers([viewController], animated: true) + containerViewController?.pushViewController(viewController, animated: false) } public func pushWriteBoardScene() {} public func didFinishWriteBoard() {} - public func cancelWriteBoard() {} + public func cancelWriteBoard() { + childCoordinators.removeAll() + navigationController.dismiss(animated: true) + finishDelegate?.flowDidFinished(childCoordinator: self) + } } diff --git a/iOS/Projects/Features/WriteBoard/Sources/Presentation/WorkoutHistorySelectScene/View/WorkoutHistorySelectViewController.swift b/iOS/Projects/Features/WriteBoard/Sources/Presentation/WorkoutHistorySelectScene/View/WorkoutHistorySelectViewController.swift index 687dd7aa..868bbe82 100644 --- a/iOS/Projects/Features/WriteBoard/Sources/Presentation/WorkoutHistorySelectScene/View/WorkoutHistorySelectViewController.swift +++ b/iOS/Projects/Features/WriteBoard/Sources/Presentation/WorkoutHistorySelectScene/View/WorkoutHistorySelectViewController.swift @@ -60,7 +60,7 @@ private extension WorkoutHistorySelectViewController { } func setupStyles() { - view.backgroundColor = DesignSystemColor.primaryBackground + view.backgroundColor = DesignSystemColor.main03 } func bind() {