Skip to content

Commit

Permalink
[Feat] #243 - FourthOnboardingView MVVM + Combine 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
yungu0010 committed Mar 14, 2024
1 parent 594ad44 commit b6f026e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ extension ViewControllerFactoryImpl {
return viewController
}
func makeFourthOnboardingViewController(coordinator: AuthCoordinator) -> FourthOnboardingViewController {
let viewController = FourthOnboardingViewController(coordinator: coordinator)
let viewModel = FourthOnboardingViewModelImpl(coordinator: coordinator)
let viewController = FourthOnboardingViewController(viewModel: viewModel)
return viewController
}
func makeFifthOnboardingViewController(coordinator: AuthCoordinator) -> FifthOnboardingViewController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import UIKit

import Combine
import SnapKit
import Then

Expand All @@ -20,7 +21,11 @@ final class FourthOnboardingViewController: UIViewController {
private let onboardingModel: [FourthOnboardingModel] = FourthOnboardingModel.items
private var dataSource: UICollectionViewDiffableDataSource<Section, FourthOnboardingModel>! = nil
private lazy var safeArea = self.view.safeAreaLayoutGuide
private weak var coordinator: AuthCoordinator?

private let viewModel: any FourthOnboardingViewModel
private var cancelBag = Set<AnyCancellable>()

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

// MARK: - UI Components

Expand All @@ -30,8 +35,8 @@ final class FourthOnboardingViewController: UIViewController {

// MARK: - init

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

Expand All @@ -49,6 +54,7 @@ final class FourthOnboardingViewController: UIViewController {
setLayout()
setupDataSource()
reloadData()
setBindings()
}
}

Expand All @@ -59,6 +65,7 @@ extension FourthOnboardingViewController {
collectionView.register(SubOnboardingCollectionViewCell.self, forCellWithReuseIdentifier: SubOnboardingCollectionViewCell.identifier)
collectionView.register(OnboardingHeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: OnboardingHeaderView.identifier)
}

private func setUI() {
view.backgroundColor = .ntdBlack

Expand All @@ -67,6 +74,7 @@ extension FourthOnboardingViewController {
$0.bounces = false
$0.isScrollEnabled = false
}

nextButton.do {
$0.configuration?.image = .splashBack
$0.configuration?.title = I18N.fourthButton
Expand Down Expand Up @@ -137,12 +145,19 @@ extension FourthOnboardingViewController {
let layout = UICollectionViewCompositionalLayout(section: section)
return layout
}

private func setBindings() {
let input = FourthOnboardingViewModelInput(
buttonDidTapped: buttonDidTapped
)
_ = viewModel.transform(input: input)
}
}
extension FourthOnboardingViewController {
@objc
private func buttonTapped() {
AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.OnboardingClick.clickOnboardingNext4)

self.coordinator?.showFifthOnboardingViewController()
self.buttonDidTapped.send()
}
}
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 FourthOnboardingViewModel: ViewModel where Input == FourthOnboardingViewModelInput, Output == FourthOnboardingViewModelOutput {}

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

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

import Foundation
import Combine

final class FourthOnboardingViewModelImpl: FourthOnboardingViewModel {

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

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

func transform(input: FourthOnboardingViewModelInput) -> FourthOnboardingViewModelOutput {
input.buttonDidTapped
.sink { [weak self] _ in
guard let self else { return }
self.coordinator?.showFifthOnboardingViewController()
}
.store(in: &cancelBag)
return FourthOnboardingViewModelOutput()
}
}

0 comments on commit b6f026e

Please sign in to comment.