Skip to content

Commit

Permalink
[Feat] #243 - ValueOnboardingView MVVM + Combine 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
yungu0010 committed Mar 14, 2024
1 parent 46e9041 commit 7d287ba
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ extension ViewControllerFactoryImpl {
// onboarding
extension ViewControllerFactoryImpl {
func makeValueOnboardingViewController(coordinator: AuthCoordinator) -> ValueOnboardingViewController {
let viewController = ValueOnboardingViewController(coordinator: coordinator)
let viewModel = ValueOnboardingViewModelImpl(coordinator: coordinator)
let viewController = ValueOnboardingViewController(viewModel: viewModel)
return viewController
}
func makeLogoOnboardingViewController(coordinator: AuthCoordinator) -> LogoOnboardingViewController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,26 @@

import UIKit

import Combine
import Lottie

final class ValueOnboardingViewController: UIViewController {

// MARK: - Properties

private weak var coordinator: AuthCoordinator?
private let viewModel: any ValueOnboardingViewModel
private var cancelBag = Set<AnyCancellable>()

private let endAnimationSubject = PassthroughSubject<Void, Never>()

// MARK: - UI Properties

let animationView = LottieAnimationView()

// MARK: - init

init(coordinator: AuthCoordinator) {
self.coordinator = coordinator
init(viewModel: some ValueOnboardingViewModel) {
self.viewModel = viewModel
super.init(nibName: nil, bundle: nil)
}

Expand All @@ -35,8 +39,9 @@ final class ValueOnboardingViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
playAnimation(named: "value") { [weak self] in
self?.pushToNextViewController()
self?.endAnimationSubject.send()
}
setBindings()
}

deinit {
Expand All @@ -49,7 +54,7 @@ final class ValueOnboardingViewController: UIViewController {

extension ValueOnboardingViewController {

func playAnimation(named name: String, completion: @escaping () -> Void) {
private func playAnimation(named name: String, completion: @escaping () -> Void) {
let animation = LottieAnimation.named(name)

animationView.animation = animation
Expand All @@ -65,7 +70,9 @@ extension ValueOnboardingViewController {
}
}

func pushToNextViewController() {
coordinator?.showLogoOnboardingViewController()
private func setBindings() {
let input = ValueOnboardingViewModelInput(
endAnimationSubject: endAnimationSubject)
_ = viewModel.transform(input: input)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,12 @@
// Created by 강윤서 on 3/14/24.
//

import Foundation
import Combine

protocol ValueOnboardingViewModel: ViewModel where Input == ValueOnboardingViewModelInput, Output == ValueOnboardingViewModelOutput {}

struct ValueOnboardingViewModelInput {
let endAnimationSubject: PassthroughSubject<Void, Never>
}

struct ValueOnboardingViewModelOutput { }
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,25 @@
// Created by 강윤서 on 3/14/24.
//

import Foundation
import Combine

final class ValueOnboardingViewModelImpl: ValueOnboardingViewModel {

private weak var coordinator: AuthCoordinator?
private var cancelBag = Set<AnyCancellable>()

init(coordinator: AuthCoordinator) {
self.coordinator = coordinator
}

func transform(input: ValueOnboardingViewModelInput) -> ValueOnboardingViewModelOutput {
input.endAnimationSubject
.sink { [weak self] _ in
self?.coordinator?.showLogoOnboardingViewController()
}
.store(in: &cancelBag)

return ValueOnboardingViewModelOutput()
}

}

0 comments on commit 7d287ba

Please sign in to comment.