Skip to content

Commit

Permalink
✨ Feat: #24 - progress+pager (#25)
Browse files Browse the repository at this point in the history
* ✨ Feat: #24 - progress+pager

* 💄 UI: #17 - CMCPager 테스트용 UI연결
  • Loading branch information
usa4060 authored Oct 28, 2023
1 parent 3375d40 commit dd68f4d
Show file tree
Hide file tree
Showing 3 changed files with 262 additions and 9 deletions.
16 changes: 7 additions & 9 deletions CMC/Sources/Presenter/Auth/Coordinators/AuthCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,19 @@ class AuthCoordinator: CoordinatorType {
self.pushViewController(viewController: mainAuthViewController)
}
case .signUp:
print("111111")
CMCToastManager.shared.addToast(message: "🍎 여기는 아직이지롱~ 😀")
// let emailSignUpViewController = EmailSignUpViewController(
let signUpViewController = SignUpViewController(
// viewModel: EmailSignUpViewModel(
// coordinator: self,
// userSignUpUsecase: DefaultUserSignUpUsecase(
// userRepository: DefaultUserRepository()
// )
// )
// )
// if self.navigationController.viewControllers.contains(where: {$0 is EmailSignUpViewController}) {
// self.navigationController.popViewController(animated: true)
// }else {
// self.pushViewController(viewController: emailSignUpViewController)
// }
)
if self.navigationController.viewControllers.contains(where: {$0 is SignUpViewController}) {
self.navigationController.popViewController(animated: true)
}else {
self.pushViewController(viewController: signUpViewController)
}
case .signIn:
let signInViewController = SignInViewController(
viewModel: SignInViewModel(
Expand Down
119 changes: 119 additions & 0 deletions CMC/Sources/Presenter/Auth/SignUp/SignUpViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,122 @@
//

import Foundation

import RxCocoa
import RxSwift

import DesignSystem
import SnapKit

import UIKit

class SignUpViewController: BaseViewController {

// MARK: - UI

private lazy var navigationBar: CMCNavigationBar = {
let navigationBar = CMCNavigationBar(
accessoryLabelHidden: false
)
navigationBar.accessoryLabel.text = ""
return navigationBar
}()

private lazy var termsAndConditionsView: UIView = {
let view = UIView()
view.backgroundColor = .blue
return view
}()

private lazy var emailCheckView: UIView = {
let view = UIView()
view.backgroundColor = .red
return view
}()

private lazy var completeSignUpView: UIView = {
let view = UIView()
view.backgroundColor = .yellow
return view
}()

private lazy var cmcPager: CMCProgressPager = {
let progressPager = CMCProgressPager(pages: [
termsAndConditionsView,
emailCheckView,
completeSignUpView
])
return progressPager
}()

private lazy var nextButton: CMCButton = {
let button = CMCButton(
isRound: false,
iconTitle: nil,
type: .login(.inactive),
title: "다음"
)
return button
}()

// MARK: - Properties

// MARK: - Initializers

// MARK: - LifeCycle

// MARK: - Methods


override func setAddSubView() {
self.view.addSubview(navigationBar)
self.view.addSubview(cmcPager)
self.view.addSubview(nextButton)
}

override func setConstraint() {
navigationBar.snp.makeConstraints{ navigationBar in
navigationBar.top.equalTo(self.view.safeAreaLayoutGuide)
navigationBar.leading.trailing.equalToSuperview()
navigationBar.height.equalTo(68)
}

cmcPager.snp.makeConstraints{ cmcPager in
cmcPager.top.equalTo(navigationBar.snp.bottom)
cmcPager.leading.trailing.equalToSuperview()
cmcPager.bottom.equalToSuperview()
}

nextButton.snp.makeConstraints { make in
make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom).offset(-20)
make.leading.equalToSuperview().offset(24)
make.trailing.equalToSuperview().offset(-24)
make.height.equalTo(56)
}
}

override func bind() {
nextButton.rx.tap
.withUnretained(self)
.subscribe(onNext: { owner, _ in
owner.cmcPager.nextPage()
})
.disposed(by: disposeBag)

cmcPager.getCurrentPage()
.observe(on: MainScheduler.instance)
.withUnretained(self)
.subscribe(onNext: { owner, page in
owner.navigationBar.accessoryLabel.text = "\(page)/\(owner.cmcPager.totalPages())"
})
.disposed(by: disposeBag)

navigationBar.backButton.rx.tapped()
.withUnretained(self)
.subscribe(onNext: { owner, _ in
owner.cmcPager.previousPage()
})
.disposed(by: disposeBag)
}

}
136 changes: 136 additions & 0 deletions DesignSystem/Sources/CMCProgressPager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
//
// CMCProgressPager.swift
// DesignSystem
//
// Created by Siri on 10/28/23.
// Copyright © 2023 com.centralMakeusChallenge. All rights reserved.
//

import Foundation

import RxCocoa
import RxSwift

import SnapKit

import UIKit

public final class CMCProgressPager: UIView {
// MARK: - UI

private lazy var progressView: UIProgressView = {
let progressView = UIProgressView()
progressView.progressTintColor = DesignSystemAsset.main1.color
progressView.trackTintColor = DesignSystemAsset.background.color
progressView.progress = 0.00
return progressView
}()

private lazy var pagerScrollView: UIScrollView = {
let scrollView = UIScrollView()
scrollView.isPagingEnabled = true
scrollView.isScrollEnabled = false
scrollView.showsHorizontalScrollIndicator = false

return scrollView
}()

// MARK: - Properties

private let disposeBag = DisposeBag()
private let currentPage = BehaviorRelay(value: 1)

private var pages: [UIView] = []
private var pagesCount: Int

// MARK: - Initializers
public init(
pages: [UIView]
) {
self.pages = pages
self.pagesCount = pages.count

super.init(frame: .zero)
setAddSubView()
setConstraint()
bind()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// MARK: - LifeCycle

// MARK: - Methods
public override func layoutSubviews() {
super.layoutSubviews()

for (index, page) in pages.enumerated() {
pagerScrollView.addSubview(page)
page.snp.makeConstraints { make in
make.top.equalTo(progressView.snp.bottom)
make.bottom.equalTo(self.snp.bottom)
make.width.equalTo(self.frame.size.width)
make.leading.equalToSuperview().offset(CGFloat(index) * self.frame.size.width)
}
}
pagerScrollView.contentSize = CGSize(
width: self.frame.size.width * CGFloat(pages.count),
height: self.frame.size.height
)
}

private func setAddSubView() {
self.addSubview(progressView)
self.addSubview(pagerScrollView)
}

private func setConstraint() {

self.progressView.snp.makeConstraints{ progressView in
progressView.top.equalTo(self)
progressView.height.equalTo(2)
progressView.leading.trailing.equalTo(self)
}

self.pagerScrollView.snp.makeConstraints { scrollView in
scrollView.top.equalTo(progressView.snp.bottom)
scrollView.leading.trailing.bottom.equalTo(self)
}
}

private func bind() {
currentPage.asObservable()
.map { Float($0) / Float(self.pagesCount) }
.withUnretained(self)
.subscribe(onNext: { owner, progress in
owner.progressView.setProgress(progress, animated: true)
})
.disposed(by: disposeBag)

currentPage.asObservable()
.subscribe(onNext: { [weak self] page in
guard let self = self else { return }
let xOffset = CGFloat(page) * self.frame.size.width
self.pagerScrollView.setContentOffset(CGPoint(x: xOffset, y: 0), animated: true)
})
.disposed(by: disposeBag)

}

public func nextPage() {
currentPage.accept(currentPage.value + 1)
}

public func previousPage() {
currentPage.accept(currentPage.value - 1)
}

public func getCurrentPage() -> Observable<Int> {
return currentPage.asObservable()
}

public func totalPages() -> Int {
return pagesCount
}
}

0 comments on commit dd68f4d

Please sign in to comment.