From 9f6df26a856dc2f0b6f49a4028a637ca6153164e Mon Sep 17 00:00:00 2001 From: yungu0010 Date: Fri, 15 Mar 2024 01:44:17 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]=20#243=20-=20fifthOnboardingView=20MVVM?= =?UTF-8?q?=20+=20Combine=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Factory/ViewControllerFactory.swift | 3 ++- .../FifthOnboardingViewController.swift | 23 +++++++++++++++---- .../ViewModel/FifthOnboardingViewModel.swift | 10 +++++++- .../FifthOnboardingViewModelImpl.swift | 22 +++++++++++++++++- 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/iOS-NOTTODO/iOS-NOTTODO/Coordinator/Factory/ViewControllerFactory.swift b/iOS-NOTTODO/iOS-NOTTODO/Coordinator/Factory/ViewControllerFactory.swift index b6aec976..e5537800 100644 --- a/iOS-NOTTODO/iOS-NOTTODO/Coordinator/Factory/ViewControllerFactory.swift +++ b/iOS-NOTTODO/iOS-NOTTODO/Coordinator/Factory/ViewControllerFactory.swift @@ -89,7 +89,8 @@ extension ViewControllerFactoryImpl { return viewController } func makeFifthOnboardingViewController(coordinator: AuthCoordinator) -> FifthOnboardingViewController { - let viewController = FifthOnboardingViewController(coordinator: coordinator) + let viewModel = FifthOnboardingViewModelImpl(coordinator: coordinator) + let viewController = FifthOnboardingViewController(viewModel: viewModel) return viewController } } diff --git a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/FifthOnboardingViewController.swift b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/FifthOnboardingViewController.swift index 6ebe5913..bccf6571 100644 --- a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/FifthOnboardingViewController.swift +++ b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/FifthOnboardingViewController.swift @@ -7,6 +7,7 @@ import UIKit +import Combine import SnapKit import Then @@ -22,7 +23,11 @@ final class FifthOnboardingViewController: UIViewController { var fiveOnboardingModel: [FifthOnboardingModel] = FifthOnboardingModel.titles private var dataSource: UICollectionViewDiffableDataSource! = nil private lazy var safeArea = self.view.safeAreaLayoutGuide - private weak var coordinator: AuthCoordinator? + + private let viewModel: any FifthOnboardingViewModel + private var cancelBag = Set() + + private let loginButtonDidTapped = PassthroughSubject() // MARK: - UI Components @@ -32,8 +37,8 @@ final class FifthOnboardingViewController: UIViewController { private let gradientView = GradientView(color: .clear, color1: .ntdBlack!) // MARK: - init - init(coordinator: AuthCoordinator) { - self.coordinator = coordinator + init(viewModel: some FifthOnboardingViewModel) { + self.viewModel = viewModel super.init(nibName: nil, bundle: nil) } @@ -51,6 +56,7 @@ final class FifthOnboardingViewController: UIViewController { setLayout() setupDataSource() reloadData() + setBindings() } } @@ -71,6 +77,7 @@ extension FifthOnboardingViewController { $0.bounces = false $0.isScrollEnabled = false } + nextButton.do { var configuration = UIButton.Configuration.plain() configuration.image = .kakaoAppleIcon @@ -83,6 +90,7 @@ extension FifthOnboardingViewController { $0.configuration = configuration $0.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside) } + arrowImage.do { $0.image = .splashBack } @@ -187,6 +195,13 @@ extension FifthOnboardingViewController { section.contentInsets = NSDirectionalEdgeInsets(top: 11, leading: 0, bottom: 0, trailing: 0) return section } + + private func setBindings() { + let input = FifthOnboardingViewModelInput( + loginButtonDidTapped: loginButtonDidTapped + ) + _ = viewModel.transform(input: input) + } } extension FifthOnboardingViewController { @@ -194,6 +209,6 @@ extension FifthOnboardingViewController { private func buttonTapped() { AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.OnboardingClick.clickOnboardingNext5) - self.coordinator?.showSignUpViewController() + self.loginButtonDidTapped.send() } } diff --git a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/FifthOnboardingViewModel.swift b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/FifthOnboardingViewModel.swift index b6c724d1..bbc67d59 100644 --- a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/FifthOnboardingViewModel.swift +++ b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/FifthOnboardingViewModel.swift @@ -5,4 +5,12 @@ // Created by 강윤서 on 3/14/24. // -import Foundation +import Combine + +protocol FifthOnboardingViewModel: ViewModel where Input == FifthOnboardingViewModelInput, Output == FifthOnboardingViewModelOutput {} + +struct FifthOnboardingViewModelInput { + let loginButtonDidTapped: PassthroughSubject +} + +struct FifthOnboardingViewModelOutput {} diff --git a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/FifthOnboardingViewModelImpl.swift b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/FifthOnboardingViewModelImpl.swift index 47b89506..e47fffe4 100644 --- a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/FifthOnboardingViewModelImpl.swift +++ b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/FifthOnboardingViewModelImpl.swift @@ -5,4 +5,24 @@ // Created by 강윤서 on 3/14/24. // -import Foundation +import Combine + +final class FifthOnboardingViewModelImpl: FifthOnboardingViewModel { + + private weak var coordinator: AuthCoordinator? + private var cancelBag = Set() + + init(coordinator: AuthCoordinator) { + self.coordinator = coordinator + } + + func transform(input: FifthOnboardingViewModelInput) -> FifthOnboardingViewModelOutput { + input.loginButtonDidTapped + .sink { [weak self] _ in + guard let self else { return } + self.coordinator?.showSignUpViewController() + } + .store(in: &cancelBag) + return FifthOnboardingViewModelOutput() + } +}