Skip to content

Commit

Permalink
feat: ProfileFeature와 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
MaraMincho committed Jan 9, 2024
1 parent 3283523 commit b941b0d
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ public enum CoordinatorFlow {
case onboarding
case profile
case home
case writeBoard
}
2 changes: 1 addition & 1 deletion iOS/Projects/Features/Profile/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let project = Project.makeModule(
.commonNetworkingKeyManager,
.keychain,
.userInformationManager,
.feature(.writeBoard)
.feature(.writeBoard),
],
testDependencies: [],
resources: "Resources/**"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Keychain
import Log
import Trinet
import UIKit
import WriteBoardFeature

// MARK: - ProfileFinishFinishDelegate

Expand Down Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ final class ContainerViewController: UINavigationController {
private var subscriptions: Set<AnyCancellable> = []

private var cancelWriteBoardPublisher: PassthroughSubject<Void, Never> = .init()
private var dismissAlertPublisher: PassthroughSubject<Void, Never> = .init()
private var confirmAlertPublisher: PassthroughSubject<Void, Never> = .init()

// MARK: Initializations
Expand Down Expand Up @@ -56,6 +55,7 @@ private extension ContainerViewController {
func setup() {
setupStyles()
bind()
presentationController?.delegate = self
}

func setupStyles() {
Expand All @@ -66,7 +66,6 @@ private extension ContainerViewController {
let output = viewModel.transform(
input: .init(
showAlertPublisher: cancelWriteBoardPublisher.eraseToAnyPublisher(),
dismissAlertPublisher: dismissAlertPublisher.eraseToAnyPublisher(),
dismissWriteBoardPublisher: confirmAlertPublisher.eraseToAnyPublisher()
)
)
Expand All @@ -75,9 +74,6 @@ private extension ContainerViewController {
case .showAlert:
self?.showFinishAlert()

case .dismissAlert:
self?.dismissAlertPublisher.send()

case .idle:
break
}
Expand All @@ -90,7 +86,8 @@ private extension ContainerViewController {

extension ContainerViewController: UIAdaptivePresentationControllerDelegate {
func presentationControllerShouldDismiss(_: UIPresentationController) -> Bool {
return true
showFinishAlert()
return false
}

private func showFinishAlert() {
Expand All @@ -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()
Expand All @@ -113,5 +108,6 @@ extension ContainerViewController: UIAdaptivePresentationControllerDelegate {

alertController.addAction(cancelAction)
alertController.addAction(confirmAction)
present(alertController, animated: true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import Foundation

public struct ContainerViewModelInput {
let showAlertPublisher: AnyPublisher<Void, Never>
let dismissAlertPublisher: AnyPublisher<Void, Never>
let dismissWriteBoardPublisher: AnyPublisher<Void, Never>
}

Expand All @@ -24,7 +23,6 @@ public typealias ContainerViewModelOutput = AnyPublisher<ContainerState, Never>
public enum ContainerState {
case idle
case showAlert
case dismissAlert
}

// MARK: - ContainerViewModelRepresentable
Expand Down Expand Up @@ -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()
Expand All @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public final class WriteBoardCoordinator: WriteBoardFeatureCoordinating {

public init(
navigationController: UINavigationController,
delegate: CoordinatorFinishDelegate
delegate: CoordinatorFinishDelegate?
) {
self.navigationController = navigationController
finishDelegate = delegate
Expand All @@ -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()
}
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private extension WorkoutHistorySelectViewController {
}

func setupStyles() {
view.backgroundColor = DesignSystemColor.primaryBackground
view.backgroundColor = DesignSystemColor.main03
}

func bind() {
Expand Down

0 comments on commit b941b0d

Please sign in to comment.