Skip to content

Commit

Permalink
[Feat] #243 - fifthOnboardingView MVVM + Combine 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
yungu0010 committed Mar 14, 2024
1 parent b6f026e commit 9f6df26
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 @@ -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
}
}
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 @@ -22,7 +23,11 @@ final class FifthOnboardingViewController: UIViewController {
var fiveOnboardingModel: [FifthOnboardingModel] = FifthOnboardingModel.titles
private var dataSource: UICollectionViewDiffableDataSource<Sections, AnyHashable>! = nil
private lazy var safeArea = self.view.safeAreaLayoutGuide
private weak var coordinator: AuthCoordinator?

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

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

// MARK: - UI Components

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

Expand All @@ -51,6 +56,7 @@ final class FifthOnboardingViewController: UIViewController {
setLayout()
setupDataSource()
reloadData()
setBindings()
}
}

Expand All @@ -71,6 +77,7 @@ extension FifthOnboardingViewController {
$0.bounces = false
$0.isScrollEnabled = false
}

nextButton.do {
var configuration = UIButton.Configuration.plain()
configuration.image = .kakaoAppleIcon
Expand All @@ -83,6 +90,7 @@ extension FifthOnboardingViewController {
$0.configuration = configuration
$0.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
}

arrowImage.do {
$0.image = .splashBack
}
Expand Down Expand Up @@ -187,13 +195,20 @@ 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 {
@objc
private func buttonTapped() {
AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.OnboardingClick.clickOnboardingNext5)

self.coordinator?.showSignUpViewController()
self.loginButtonDidTapped.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 FifthOnboardingViewModel: ViewModel where Input == FifthOnboardingViewModelInput, Output == FifthOnboardingViewModelOutput {}

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

struct FifthOnboardingViewModelOutput {}
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 FifthOnboardingViewModelImpl: FifthOnboardingViewModel {

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

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()
}
}

0 comments on commit 9f6df26

Please sign in to comment.