Skip to content

Commit

Permalink
[Feat] #392 - DailySoptuneCardCoordinator 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
dlwogus0128 committed Sep 28, 2024
1 parent 4c4260a commit b76e5e7
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@
import BaseFeatureDependency
import Core

public protocol DailySoptuneCardPresentable: ViewControllable { }
public protocol DailySoptuneCardViewControllable: ViewControllable { }

public protocol DailySoptuneCardCoordinatable {
var onGoToHomeButtonTapped: (() -> Void)? { get set }
var onBackButtonTapped: (() -> Void)? { get set }
}

public typealias DailySoptuneCardViewModelType = ViewModelType & DailySoptuneCardCoordinatable
public typealias DailySoptuneCardPresentable = (vc: DailySoptuneCardViewControllable, vm: any DailySoptuneCardViewModelType)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Domain
public protocol DailySoptuneResultViewControllable: ViewControllable { }

public protocol DailySoptuneResultCoordinatable {
var onNaviBackButtonTap: (() -> Void)? { get set }
var onNaviBackButtonTapped: (() -> Void)? { get set }
var onKokButtonTapped: ((PokeUserModel) -> Driver<(PokeUserModel, PokeMessageModel, isAnonymous: Bool)>)? { get set }
var onReceiveTodaysFortuneCardButtonTapped: ((DailySoptuneCardModel) -> Void)? { get set }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import Core
import Domain
@_exported import DailySoptuneFeatureInterface
import PokeFeatureInterface

public final class DailySoptuneBuilder {
@Injected public var dailySoptuneRepository: DailySoptuneRepositoryInterface
Expand All @@ -35,8 +34,10 @@ extension DailySoptuneBuilder: DailySoptuneFeatureBuildable {
}

public func makeDailySoptuneCardVC(cardModel: DailySoptuneCardModel) -> DailySoptuneCardPresentable {
let dailySoptuneCardVC = DailySoptuneCardVC(cardModel: cardModel)
return dailySoptuneCardVC
let useCase = DefaultDailySoptuneUseCase(repository: dailySoptuneRepository)
let viewModel = DailySoptuneCardViewModel(useCase: useCase)
let dailySoptuneCardVC = DailySoptuneCardVC(cardModel: cardModel, viewModel: viewModel)
return (dailySoptuneCardVC, viewModel)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// DailySoptuneCardCoordinator.swift
// DailySoptuneFeature
//
// Created by Jae Hyun Lee on 9/28/24.
// Copyright © 2024 SOPT-iOS. All rights reserved.
//

import UIKit
import Combine

import Core
import BaseFeatureDependency
import DailySoptuneFeatureInterface
import Domain

public final class DailySoptuneCardCoordinator: DefaultCoordinator {

public var finishFlow: (() -> Void)?

private let factory: DailySoptuneFeatureBuildable
private let router: Router

private let cardModel: DailySoptuneCardModel

private weak var rootController: UINavigationController?

public init(router: Router, factory: DailySoptuneFeatureBuildable, cardModel: DailySoptuneCardModel) {
self.router = router
self.factory = factory
self.cardModel = cardModel
}

public override func start() {
showDailySoptuneCard()
}

private func showDailySoptuneCard() {
var dailySoptuneCard = factory.makeDailySoptuneCardVC(cardModel: cardModel)

dailySoptuneCard.vm.onBackButtonTapped = { [weak self] in
self?.router.dismissModule(animated: true)
self?.finishFlow?()
}

self.rootController = dailySoptuneCard.vc.asNavigationController
self.router.present(self.rootController, animated: true, modalPresentationSytle: .overFullScreen)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public final class DailySoptuneResultCoordinator: DefaultCoordinator {
private let factory: DailySoptuneFeatureBuildable
private let pokeFactory: PokeFeatureBuildable
private let router: Router

private weak var rootController: UINavigationController?

public init(router: Router, factory: DailySoptuneFeatureBuildable, pokeFactory: PokeFeatureBuildable) {
self.router = router
self.factory = factory
Expand All @@ -35,7 +36,7 @@ public final class DailySoptuneResultCoordinator: DefaultCoordinator {
private func showDailySoptuneResult() {
var dailySoptuneResult = factory.makeDailySoptuneResultVC()

dailySoptuneResult.vm.onNaviBackButtonTap = { [weak self] in
dailySoptuneResult.vm.onNaviBackButtonTapped = { [weak self] in
self?.router.dismissModule(animated: true)
self?.finishFlow?()
}
Expand All @@ -47,14 +48,30 @@ public final class DailySoptuneResultCoordinator: DefaultCoordinator {

dailySoptuneResult.vm.onReceiveTodaysFortuneCardButtonTapped = { [weak self] cardModel in
guard let self else { return }
let dailySoptuneCardVC = self.factory.makeDailySoptuneCardVC(cardModel: cardModel).viewController
dailySoptuneCardVC.modalPresentationStyle = .overFullScreen
dailySoptuneResult.vc.viewController.present(dailySoptuneCardVC, animated: false)
self.runDailySoptuneCardFlow(cardModel: cardModel)
}

router.push(dailySoptuneResult.vc)
rootController = dailySoptuneResult.vc.asNavigationController
router.present(rootController, animated: false, modalPresentationSytle: .overFullScreen)
}

internal func runDailySoptuneCardFlow(cardModel: DailySoptuneCardModel) {
let dailySoptuneCardCoordinator = DailySoptuneCardCoordinator(
router: Router(
rootController: rootController ?? self.router.asNavigationController
), factory: factory
, cardModel: cardModel
)

dailySoptuneCardCoordinator.finishFlow = { [weak self, weak dailySoptuneCardCoordinator] in
dailySoptuneCardCoordinator?.childCoordinators = []
self?.removeDependency(dailySoptuneCardCoordinator)
}

addDependency(dailySoptuneCardCoordinator)
dailySoptuneCardCoordinator.start()
}

private func showMessageBottomSheet(userModel: PokeUserModel, on view: UIViewController?) -> AnyPublisher<(PokeUserModel, PokeMessageModel, isAnonymous: Bool), Never> {
let messageType: PokeMessageType = userModel.isFirstMeet ? .pokeSomeone : .pokeFriend

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@
//

import UIKit
import Combine

import Core
import DSKit
import Domain

import BaseFeatureDependency

public final class DailySoptuneCardVC: UIViewController, DailySoptuneCardPresentable {
public final class DailySoptuneCardVC: UIViewController, DailySoptuneCardViewControllable {

// MARK: - Properties

public var viewModel: DailySoptuneCardViewModel
private let cardModel: DailySoptuneCardModel
private var cancelBag = CancelBag()

// MARK: - UI Components

Expand All @@ -44,8 +47,9 @@ public final class DailySoptuneCardVC: UIViewController, DailySoptuneCardPresent

// MARK: - initialization

init(cardModel: DailySoptuneCardModel) {
init(cardModel: DailySoptuneCardModel, viewModel: DailySoptuneCardViewModel) {
self.cardModel = cardModel
self.viewModel = viewModel
super.init(nibName: nil, bundle: nil)
}

Expand All @@ -60,6 +64,7 @@ public final class DailySoptuneCardVC: UIViewController, DailySoptuneCardPresent
setUI()
setLayout()
setData()
bindViewModels()
}
}

Expand Down Expand Up @@ -114,4 +119,13 @@ private extension DailySoptuneCardVC {
self.cardLabel.partColorChange(targetString: "\(cardModel.name)", textColor: UIColor(hex: "\(cardModel.imageColorCode)"))
self.cardImage.setImage(with: cardModel.imageURL)
}

private func bindViewModels() {
let input = DailySoptuneCardViewModel.Input(
goToHomeButtonTap: self.goToHomeButton.publisher(for: .touchUpInside).mapVoid().asDriver(),
backButtonTap: self.backButton.publisher(for: .touchUpInside).mapVoid().asDriver()
)

let output = self.viewModel.transform(from: input, cancelBag: self.cancelBag)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// DailySoptuneCardViewModel.swift
// DailySoptuneFeature
//
// Created by Jae Hyun Lee on 9/28/24.
// Copyright © 2024 SOPT-iOS. All rights reserved.
//

import Foundation
import Combine

import Core
import Domain

import DailySoptuneFeatureInterface

public final class DailySoptuneCardViewModel: DailySoptuneCardViewModelType {

public var onGoToHomeButtonTapped: (() -> Void)?
public var onBackButtonTapped: (() -> Void)?

// MARK: - Properties

private let useCase: DailySoptuneUseCase
private var cancelBag = CancelBag()

// MARK: - Inputs

public struct Input {
let goToHomeButtonTap: Driver<Void>
let backButtonTap: Driver<Void>
}

// MARK: - Outpust

public struct Output {

}

// MARK: - initialization

public init(useCase: DailySoptuneUseCase) {
self.useCase = useCase
}
}

extension DailySoptuneCardViewModel {

public func transform(from input: Input, cancelBag: CancelBag) -> Output {
let output = Output()

input.goToHomeButtonTap
.withUnretained(self)
.sink { _ in
self.onGoToHomeButtonTapped?()
}.store(in: cancelBag)

input.backButtonTap
.withUnretained(self)
.sink { _ in
self.onBackButtonTapped?()
}.store(in: cancelBag)

return output
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import Domain

import DailySoptuneFeatureInterface

public class DailySoptuneResultViewModel: DailySoptuneResultViewModelType {
public final class DailySoptuneResultViewModel: DailySoptuneResultViewModelType {

public var onNaviBackButtonTap: (() -> Void)?
public var onReceiveTodaysFortuneCardTap: ((DailySoptuneCardModel) -> Void)?
public var onNaviBackButtonTapped: (() -> Void)?
public var onReceiveTodaysFortuneCardTap: ((DailySoptuneCardModel) -> Void)?
public var onKokButtonTapped: ((Domain.PokeUserModel) -> Core.Driver<(Domain.PokeUserModel, Domain.PokeMessageModel, isAnonymous: Bool)>)?
public var onReceiveTodaysFortuneCardButtonTapped: ((Domain.DailySoptuneCardModel) -> Void)?

Expand Down Expand Up @@ -65,7 +65,7 @@ extension DailySoptuneResultViewModel {
input.naviBackButtonTap
.withUnretained(self)
.sink { _ in
self.onNaviBackButtonTap?()
self.onNaviBackButtonTapped?()
}.store(in: cancelBag)

input.receiveTodaysFortuneCardTap
Expand Down

0 comments on commit b76e5e7

Please sign in to comment.