From 1fcfc2d40cc53b32ab5221378e856e5e7e8fcecd Mon Sep 17 00:00:00 2001 From: yungu0010 Date: Wed, 20 Mar 2024 17:19:30 +0900 Subject: [PATCH] =?UTF-8?q?[Refactor]=20#243=20-=20=EC=95=B0=ED=94=8C?= =?UTF-8?q?=EB=A6=AC=ED=8A=9C=ED=8A=B8=20viewModel=EB=A1=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=8F=99=20&=20buttonTapped=20publisher=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FifthOnboardingViewController.swift | 19 ++++++++-------- .../FourthOnboardingViewController.swift | 18 +++++++-------- .../LogoOnboardingViewController.swift | 14 ++++++------ .../SecondOnboardingViewController.swift | 7 +++--- .../ThirdOnboardingViewController.swift | 22 +++++++++---------- .../ViewModel/FifthOnboardingViewModel.swift | 1 + .../FifthOnboardingViewModelImpl.swift | 9 ++++++++ .../ViewModel/FourthOnboardingViewModel.swift | 1 + .../FourthOnboardingViewModelImpl.swift | 9 ++++++++ .../LogoOnboardingViewModelImpl.swift | 1 + .../ViewModel/SecondOnboardingViewModel.swift | 1 + .../SecondOnboardingViewModelImpl.swift | 11 +++++++++- .../ViewModel/ThirdOnboardingViewModel.swift | 3 ++- .../ThirdOnboardingViewModelImpl.swift | 10 ++++++++- 14 files changed, 83 insertions(+), 43 deletions(-) diff --git a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/FifthOnboardingViewController.swift b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/FifthOnboardingViewController.swift index 5c693b1..79c9b0d 100644 --- a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/FifthOnboardingViewController.swift +++ b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/FifthOnboardingViewController.swift @@ -27,6 +27,7 @@ final class FifthOnboardingViewController: UIViewController { private let viewModel: any FifthOnboardingViewModel private var cancelBag = Set() + private let viewDidLoadSubject = PassthroughSubject() private let loginButtonDidTapped = PassthroughSubject() // MARK: - UI Components @@ -50,7 +51,7 @@ final class FifthOnboardingViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.Onboarding.viewOnboarding5) + viewDidLoadSubject.send() setUI() register() setLayout() @@ -88,7 +89,6 @@ extension FifthOnboardingViewController { configuration.baseForegroundColor = .white configuration.contentInsets = NSDirectionalEdgeInsets.init(top: 0, leading: 0, bottom: 0, trailing: 10) $0.configuration = configuration - $0.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside) } arrowImage.do { @@ -198,17 +198,16 @@ extension FifthOnboardingViewController { private func setBindings() { let input = FifthOnboardingViewModelInput( + viewDidLoadSubject: viewDidLoadSubject, loginButtonDidTapped: loginButtonDidTapped ) _ = viewModel.transform(input: input) - } -} - -extension FifthOnboardingViewController { - @objc - private func buttonTapped() { - AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.OnboardingClick.clickOnboardingNext5) - self.loginButtonDidTapped.send() + nextButton.tapPublisher + .sink { [weak self] _ in + guard let self else { return } + self.loginButtonDidTapped.send() + } + .store(in: &cancelBag) } } diff --git a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/FourthOnboardingViewController.swift b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/FourthOnboardingViewController.swift index 26326f4..ba62137 100644 --- a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/FourthOnboardingViewController.swift +++ b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/FourthOnboardingViewController.swift @@ -25,6 +25,7 @@ final class FourthOnboardingViewController: UIViewController { private let viewModel: any FourthOnboardingViewModel private var cancelBag = Set() + private let viewDidLoadSubject = PassthroughSubject() private let buttonDidTapped = PassthroughSubject() // MARK: - UI Components @@ -48,7 +49,7 @@ final class FourthOnboardingViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.Onboarding.viewOnboarding4) + viewDidLoadSubject.send() setUI() register() setLayout() @@ -83,7 +84,6 @@ extension FourthOnboardingViewController { $0.configuration?.attributedTitle?.font = .Pretendard(.medium, size: 16) $0.configuration?.baseForegroundColor = .white $0.configuration?.contentInsets = NSDirectionalEdgeInsets.init(top: 0, leading: 0, bottom: 0, trailing: 0) - $0.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside) } } @@ -147,16 +147,16 @@ extension FourthOnboardingViewController { private func setBindings() { let input = FourthOnboardingViewModelInput( + viewDidLoadSubject: viewDidLoadSubject, buttonDidTapped: buttonDidTapped ) _ = viewModel.transform(input: input) - } -} -extension FourthOnboardingViewController { - @objc - private func buttonTapped() { - AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.OnboardingClick.clickOnboardingNext4) - self.buttonDidTapped.send() + nextButton.tapPublisher + .sink { [weak self] _ in + guard let self else { return } + self.buttonDidTapped.send() + } + .store(in: &cancelBag) } } diff --git a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/LogoOnboardingViewController.swift b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/LogoOnboardingViewController.swift index e6daa94..abe485e 100644 --- a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/LogoOnboardingViewController.swift +++ b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/LogoOnboardingViewController.swift @@ -97,7 +97,6 @@ extension LogoOnboardingViewController { $0.titleLabel?.font = .Pretendard(.semiBold, size: 16) $0.setTitleColor(.black, for: .normal) $0.setTitle(I18N.firstButton, for: .normal) - $0.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside) } } @@ -120,16 +119,17 @@ extension LogoOnboardingViewController { startButtonTappedSubject: startButtonDidTapped ) _ = viewModel.transform(input: input) + + nextButton.tapPublisher + .sink { [weak self] in + guard let self else { return } + self.startButtonDidTapped.send() + } + .store(in: &cancelBag) } @objc private func videoDidFinishPlaying(notification: NSNotification) { nextButton.isHidden = false } - - @objc - private func buttonTapped() { - AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.OnboardingClick.clickOnboardingStart) - startButtonDidTapped.send() - } } diff --git a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/SecondOnboardingViewController.swift b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/SecondOnboardingViewController.swift index 4038fb6..3c47d0d 100644 --- a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/SecondOnboardingViewController.swift +++ b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/SecondOnboardingViewController.swift @@ -25,6 +25,7 @@ final class SecondOnboardingViewController: UIViewController { private let viewModel: any SecondOnboardingViewModel private var cancelBag = Set() + private let viewDidLoadSubject = PassthroughSubject() private let onbaordingCellTapped = PassthroughSubject() // MARK: - UI Components @@ -46,7 +47,7 @@ final class SecondOnboardingViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.Onboarding.viewOnboarding2) + viewDidLoadSubject.send() setUI() register() setLayout() @@ -63,6 +64,7 @@ extension SecondOnboardingViewController { collectionView.register(OnboardingCollectionViewCell.self, forCellWithReuseIdentifier: OnboardingCollectionViewCell.identifier) collectionView.register(OnboardingHeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: OnboardingHeaderView.identifier) } + private func setUI() { view.backgroundColor = .ntdBlack @@ -122,6 +124,7 @@ extension SecondOnboardingViewController { private func setBindings() { let input = SecondOnboardingViewModelInput( + viewDidLoadSubject: viewDidLoadSubject, cellTapped: onbaordingCellTapped) _ = viewModel.transform(input: input) } @@ -129,8 +132,6 @@ extension SecondOnboardingViewController { extension SecondOnboardingViewController: UICollectionViewDelegate { func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { - AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.OnboardingClick.clickOnboardingNext2(select: SecondOnboardingModel.titles[indexPath.row].title)) - self.onbaordingCellTapped.send(indexPath) } } diff --git a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/ThirdOnboardingViewController.swift b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/ThirdOnboardingViewController.swift index 0a04a6a..acdcc7d 100644 --- a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/ThirdOnboardingViewController.swift +++ b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewControllers/ThirdOnboardingViewController.swift @@ -27,7 +27,8 @@ final class ThirdOnboardingViewController: UIViewController { private let viewModel: any ThirdOnboardingViewModel private var cancelBag = Set() - private let nextButtonDidTapped = PassthroughSubject() + private let viewDidLoadSubject = PassthroughSubject() + private let nextButtonDidTapped = PassthroughSubject<[String], Never>() // MARK: - UI Components @@ -50,7 +51,7 @@ final class ThirdOnboardingViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.Onboarding.viewOnboarding3) + viewDidLoadSubject.send() setUI() register() setLayout() @@ -86,7 +87,6 @@ extension ThirdOnboardingViewController { $0.titleLabel?.font = .Pretendard(.semiBold, size: 16) $0.setTitleColor(isTapped ? .black :.gray4, for: .normal) $0.setTitle(I18N.thirdButton, for: .normal) - $0.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside) } } @@ -153,16 +153,16 @@ extension ThirdOnboardingViewController { private func setBindings() { let input = ThirdOnboardingViewModelInput( + viewDidLoadSubject: viewDidLoadSubject, nextButtonDidTapped: nextButtonDidTapped) _ = viewModel.transform(input: input) - } -} - -extension ThirdOnboardingViewController { - @objc - private func buttonTapped() { - AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.OnboardingClick.clickOnboardingNext3(select: self.selectList)) - self.nextButtonDidTapped.send() + + nextButton.tapPublisher + .sink { [weak self] in + guard let self else { return } + self.nextButtonDidTapped.send(selectList) + } + .store(in: &cancelBag) } } diff --git a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/FifthOnboardingViewModel.swift b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/FifthOnboardingViewModel.swift index bbc67d5..663f030 100644 --- a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/FifthOnboardingViewModel.swift +++ b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/FifthOnboardingViewModel.swift @@ -10,6 +10,7 @@ import Combine protocol FifthOnboardingViewModel: ViewModel where Input == FifthOnboardingViewModelInput, Output == FifthOnboardingViewModelOutput {} struct FifthOnboardingViewModelInput { + let viewDidLoadSubject: PassthroughSubject let loginButtonDidTapped: PassthroughSubject } diff --git a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/FifthOnboardingViewModelImpl.swift b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/FifthOnboardingViewModelImpl.swift index e47fffe..0bf163c 100644 --- a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/FifthOnboardingViewModelImpl.swift +++ b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/FifthOnboardingViewModelImpl.swift @@ -20,9 +20,18 @@ final class FifthOnboardingViewModelImpl: FifthOnboardingViewModel { input.loginButtonDidTapped .sink { [weak self] _ in guard let self else { return } + AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.OnboardingClick.clickOnboardingNext5) self.coordinator?.showSignUpViewController() } .store(in: &cancelBag) + + input.viewDidLoadSubject + .sink { [weak self] _ in + guard let self else { return } + AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.Onboarding.viewOnboarding5) + } + .store(in: &cancelBag) + return FifthOnboardingViewModelOutput() } } diff --git a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/FourthOnboardingViewModel.swift b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/FourthOnboardingViewModel.swift index 4095aec..f0d7626 100644 --- a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/FourthOnboardingViewModel.swift +++ b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/FourthOnboardingViewModel.swift @@ -10,6 +10,7 @@ import Combine protocol FourthOnboardingViewModel: ViewModel where Input == FourthOnboardingViewModelInput, Output == FourthOnboardingViewModelOutput {} struct FourthOnboardingViewModelInput { + let viewDidLoadSubject: PassthroughSubject let buttonDidTapped: PassthroughSubject } diff --git a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/FourthOnboardingViewModelImpl.swift b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/FourthOnboardingViewModelImpl.swift index 4c56e66..85b5a1f 100644 --- a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/FourthOnboardingViewModelImpl.swift +++ b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/FourthOnboardingViewModelImpl.swift @@ -20,9 +20,18 @@ final class FourthOnboardingViewModelImpl: FourthOnboardingViewModel { input.buttonDidTapped .sink { [weak self] _ in guard let self else { return } + AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.OnboardingClick.clickOnboardingNext4) self.coordinator?.showFifthOnboardingViewController() } .store(in: &cancelBag) + + input.viewDidLoadSubject + .sink { [weak self] _ in + guard let self else { return } + AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.Onboarding.viewOnboarding4) + } + .store(in: &cancelBag) + return FourthOnboardingViewModelOutput() } } diff --git a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/LogoOnboardingViewModelImpl.swift b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/LogoOnboardingViewModelImpl.swift index 65c918e..e7a7c6f 100644 --- a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/LogoOnboardingViewModelImpl.swift +++ b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/LogoOnboardingViewModelImpl.swift @@ -20,6 +20,7 @@ final class LogoOnboardingViewModelImpl: LogoOnboardingViewModel { input.startButtonTappedSubject .sink { [weak self] _ in guard let self else { return } + AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.OnboardingClick.clickOnboardingStart) self.coodinator?.showSecondOnboardingViewController() } .store(in: &cancelBag) diff --git a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/SecondOnboardingViewModel.swift b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/SecondOnboardingViewModel.swift index d057fa4..b29496a 100644 --- a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/SecondOnboardingViewModel.swift +++ b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/SecondOnboardingViewModel.swift @@ -11,6 +11,7 @@ import Foundation protocol SecondOnboardingViewModel: ViewModel where Input == SecondOnboardingViewModelInput, Output == SecondOnboardingViewModelOutput { } struct SecondOnboardingViewModelInput { + let viewDidLoadSubject: PassthroughSubject let cellTapped: PassthroughSubject } diff --git a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/SecondOnboardingViewModelImpl.swift b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/SecondOnboardingViewModelImpl.swift index 4921d4d..2e409b0 100644 --- a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/SecondOnboardingViewModelImpl.swift +++ b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/SecondOnboardingViewModelImpl.swift @@ -18,11 +18,20 @@ final class SecondOnboardingViewModelImpl: SecondOnboardingViewModel { func transform(input: SecondOnboardingViewModelInput) -> SecondOnboardingViewModelOutput { input.cellTapped - .sink { [weak self] _ in + .sink { [weak self] indexPath in guard let self else { return } + AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.OnboardingClick.clickOnboardingNext2(select: SecondOnboardingModel.titles[indexPath.row].title)) self.coordinator?.showThirdOnboardingViewController() } .store(in: &cancelBag) + + input.viewDidLoadSubject + .sink { [weak self] _ in + guard let self else { return } + AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.Onboarding.viewOnboarding2) + } + .store(in: &cancelBag) + return SecondOnboardingViewModelOutput() } } diff --git a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/ThirdOnboardingViewModel.swift b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/ThirdOnboardingViewModel.swift index 4202b6a..4967bbf 100644 --- a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/ThirdOnboardingViewModel.swift +++ b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/ThirdOnboardingViewModel.swift @@ -10,7 +10,8 @@ import Combine protocol ThirdOnboardingViewModel: ViewModel where Input == ThirdOnboardingViewModelInput, Output == ThirdOnboardingViewModelOutput {} struct ThirdOnboardingViewModelInput { - let nextButtonDidTapped: PassthroughSubject + let viewDidLoadSubject: PassthroughSubject + let nextButtonDidTapped: PassthroughSubject<[String], Never> } 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 b469513..af8f4a7 100644 --- a/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/ThirdOnboardingViewModelImpl.swift +++ b/iOS-NOTTODO/iOS-NOTTODO/Presentation/Onboarding/ViewModel/ThirdOnboardingViewModelImpl.swift @@ -18,12 +18,20 @@ final class ThirdOnboardingViewModelImpl: ThirdOnboardingViewModel { func transform(input: ThirdOnboardingViewModelInput) -> ThirdOnboardingViewModelOutput { input.nextButtonDidTapped - .sink { [weak self] _ in + .sink { [weak self] selectList in guard let self else { return } + AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.OnboardingClick.clickOnboardingNext3(select: selectList)) self.coordinator?.showFourthOnboardingViewController() } .store(in: &cancelBag) + input.viewDidLoadSubject + .sink { [weak self] _ in + guard let self else { return } + AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.Onboarding.viewOnboarding3) + } + .store(in: &cancelBag) + return ThirdOnboardingViewModelOutput() } }