diff --git a/iOS-NOTTODO/iOS-NOTTODO/Coordinator/Factory/ViewControllerFactory.swift b/iOS-NOTTODO/iOS-NOTTODO/Coordinator/Factory/ViewControllerFactory.swift index 550fe2c..d37a94f 100644 --- a/iOS-NOTTODO/iOS-NOTTODO/Coordinator/Factory/ViewControllerFactory.swift +++ b/iOS-NOTTODO/iOS-NOTTODO/Coordinator/Factory/ViewControllerFactory.swift @@ -79,7 +79,8 @@ extension ViewControllerFactoryImpl { return viewController } func makeThirdOnboardingViewController(coordinator: AuthCoordinator) -> ThirdOnboardingViewController { - let viewController = ThirdOnboardingViewController(coordinator: coordinator) + let viewModel = ThirdOnboardingViewModelImpl(coordinator: coordinator) + let viewController = ThirdOnboardingViewController(viewModel: viewModel) return viewController } func makeFourthOnboardingViewController(coordinator: AuthCoordinator) -> FourthOnboardingViewController { diff --git a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/ThirdOnboardingViewController.swift b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/ThirdOnboardingViewController.swift index b798cca..36096e8 100644 --- a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/ThirdOnboardingViewController.swift +++ b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/ThirdOnboardingViewController.swift @@ -7,6 +7,7 @@ import UIKit +import Combine import SnapKit import Then @@ -22,7 +23,11 @@ final class ThirdOnboardingViewController: UIViewController { private var dataSource: UICollectionViewDiffableDataSource! = nil private lazy var safeArea = self.view.safeAreaLayoutGuide private var selectList: [String] = [] - private weak var coordinator: AuthCoordinator? + + private let viewModel: any ThirdOnboardingViewModel + private var cancelBag = Set() + + private let nextButtonDidTapped = PassthroughSubject() // MARK: - UI Components @@ -31,8 +36,9 @@ final class ThirdOnboardingViewController: UIViewController { private var isTapped: Bool = false // MARK: - init - init(coordinator: AuthCoordinator) { - self.coordinator = coordinator + + init(viewModel: some ThirdOnboardingViewModel) { + self.viewModel = viewModel super.init(nibName: nil, bundle: nil) } @@ -50,6 +56,7 @@ final class ThirdOnboardingViewController: UIViewController { setLayout() setupDataSource() reloadData() + setBindings() } } @@ -60,6 +67,7 @@ extension ThirdOnboardingViewController { collectionView.register(OnboardingCollectionViewCell.self, forCellWithReuseIdentifier: OnboardingCollectionViewCell.identifier) collectionView.register(OnboardingHeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: OnboardingHeaderView.identifier) } + private func setUI() { view.backgroundColor = .ntdBlack @@ -141,14 +149,19 @@ extension ThirdOnboardingViewController { section.boundarySupplementaryItems = [header] return UICollectionViewCompositionalLayout(section: section) } + + private func setBindings() { + let input = ThirdOnboardingViewModelInput( + nextButtonDidTapped: nextButtonDidTapped) + _ = viewModel.transform(input: input) + } } extension ThirdOnboardingViewController { @objc private func buttonTapped() { - AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.OnboardingClick.clickOnboardingNext3(select: self.selectList)) - self.coordinator?.showFourthOnboardingViewController() + self.nextButtonDidTapped.send() } } @@ -171,7 +184,6 @@ extension ThirdOnboardingViewController: UICollectionViewDelegate { } self.isTapped = false updateButton(isTapped: self.isTapped) - } } } diff --git a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/ThirdOnboardingViewModel.swift b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/ThirdOnboardingViewModel.swift index d1a9a69..4202b6a 100644 --- a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/ThirdOnboardingViewModel.swift +++ b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/ThirdOnboardingViewModel.swift @@ -5,4 +5,12 @@ // Created by 강윤서 on 3/14/24. // -import Foundation +import Combine + +protocol ThirdOnboardingViewModel: ViewModel where Input == ThirdOnboardingViewModelInput, Output == ThirdOnboardingViewModelOutput {} + +struct ThirdOnboardingViewModelInput { + let nextButtonDidTapped: PassthroughSubject +} + +struct ThirdOnboardingViewModelOutput {} diff --git a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/ThirdOnboardingViewModelImpl.swift b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/ThirdOnboardingViewModelImpl.swift index 86b92c2..b469513 100644 --- a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/ThirdOnboardingViewModelImpl.swift +++ b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/ThirdOnboardingViewModelImpl.swift @@ -5,4 +5,25 @@ // Created by 강윤서 on 3/14/24. // -import Foundation +import Combine + +final class ThirdOnboardingViewModelImpl: ThirdOnboardingViewModel { + + private weak var coordinator: AuthCoordinator? + private var cancelBag = Set() + + init(coordinator: AuthCoordinator) { + self.coordinator = coordinator + } + + func transform(input: ThirdOnboardingViewModelInput) -> ThirdOnboardingViewModelOutput { + input.nextButtonDidTapped + .sink { [weak self] _ in + guard let self else { return } + self.coordinator?.showFourthOnboardingViewController() + } + .store(in: &cancelBag) + + return ThirdOnboardingViewModelOutput() + } +}