Skip to content

Commit

Permalink
[Refactor] #243 - 앰플리튜트 viewModel로 이동 & buttonTapped publisher로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
yungu0010 committed Mar 20, 2024
1 parent c0149a6 commit 1fcfc2d
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ final class FifthOnboardingViewController: UIViewController {
private let viewModel: any FifthOnboardingViewModel
private var cancelBag = Set<AnyCancellable>()

private let viewDidLoadSubject = PassthroughSubject<Void, Never>()
private let loginButtonDidTapped = PassthroughSubject<Void, Never>()

// MARK: - UI Components
Expand All @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ final class FourthOnboardingViewController: UIViewController {
private let viewModel: any FourthOnboardingViewModel
private var cancelBag = Set<AnyCancellable>()

private let viewDidLoadSubject = PassthroughSubject<Void, Never>()
private let buttonDidTapped = PassthroughSubject<Void, Never>()

// MARK: - UI Components
Expand All @@ -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()
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ final class SecondOnboardingViewController: UIViewController {
private let viewModel: any SecondOnboardingViewModel
private var cancelBag = Set<AnyCancellable>()

private let viewDidLoadSubject = PassthroughSubject<Void, Never>()
private let onbaordingCellTapped = PassthroughSubject<IndexPath, Never>()

// MARK: - UI Components
Expand All @@ -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()
Expand All @@ -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

Expand Down Expand Up @@ -122,15 +124,14 @@ extension SecondOnboardingViewController {

private func setBindings() {
let input = SecondOnboardingViewModelInput(
viewDidLoadSubject: viewDidLoadSubject,
cellTapped: onbaordingCellTapped)
_ = viewModel.transform(input: input)
}
}

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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ final class ThirdOnboardingViewController: UIViewController {
private let viewModel: any ThirdOnboardingViewModel
private var cancelBag = Set<AnyCancellable>()

private let nextButtonDidTapped = PassthroughSubject<Void, Never>()
private let viewDidLoadSubject = PassthroughSubject<Void, Never>()
private let nextButtonDidTapped = PassthroughSubject<[String], Never>()

// MARK: - UI Components

Expand All @@ -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()
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Combine
protocol FifthOnboardingViewModel: ViewModel where Input == FifthOnboardingViewModelInput, Output == FifthOnboardingViewModelOutput {}

struct FifthOnboardingViewModelInput {
let viewDidLoadSubject: PassthroughSubject<Void, Never>
let loginButtonDidTapped: PassthroughSubject<Void, Never>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Combine
protocol FourthOnboardingViewModel: ViewModel where Input == FourthOnboardingViewModelInput, Output == FourthOnboardingViewModelOutput {}

struct FourthOnboardingViewModelInput {
let viewDidLoadSubject: PassthroughSubject<Void, Never>
let buttonDidTapped: PassthroughSubject<Void, Never>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Foundation
protocol SecondOnboardingViewModel: ViewModel where Input == SecondOnboardingViewModelInput, Output == SecondOnboardingViewModelOutput { }

struct SecondOnboardingViewModelInput {
let viewDidLoadSubject: PassthroughSubject<Void, Never>
let cellTapped: PassthroughSubject<IndexPath, Never>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import Combine
protocol ThirdOnboardingViewModel: ViewModel where Input == ThirdOnboardingViewModelInput, Output == ThirdOnboardingViewModelOutput {}

struct ThirdOnboardingViewModelInput {
let nextButtonDidTapped: PassthroughSubject<Void, Never>
let viewDidLoadSubject: PassthroughSubject<Void, Never>
let nextButtonDidTapped: PassthroughSubject<[String], Never>
}

struct ThirdOnboardingViewModelOutput {}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

0 comments on commit 1fcfc2d

Please sign in to comment.