From 518cb3a3b2e6815c08f5a2087d24d9647eb9df2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B6=B1=EC=9D=B4?= Date: Sat, 2 Jan 2021 16:39:29 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20refactor/code=20(#21)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * :art: 코드 MarkUp , 주석 수정 * mend --- .../MessageCountBadgeView.swift | 6 +- .../Cheering Map/CheeringMapReactor.swift | 4 +- .../Discover/Cell/MessageTableViewCell.swift | 260 +++++++++--------- .../Scene/Discover/DiscoverReactor.swift | 5 + .../Discover/DiscoverViewController.swift | 187 +++++++------ .../Send Message/SendMessageReactor.swift | 3 + .../Presentation/View/CheerButton.swift | 3 +- .../View/CountrySelectController.swift | 222 +++++++-------- .../Source/Presentation/View/ErrorView.swift | 2 +- .../Presentation/View/SelectCountryView.swift | 2 +- 10 files changed, 347 insertions(+), 347 deletions(-) diff --git a/Dear-World/Dear-World.xcodeproj/MessageCountBadgeView.swift b/Dear-World/Dear-World.xcodeproj/MessageCountBadgeView.swift index 7937e27..fccbbe1 100644 --- a/Dear-World/Dear-World.xcodeproj/MessageCountBadgeView.swift +++ b/Dear-World/Dear-World.xcodeproj/MessageCountBadgeView.swift @@ -5,11 +5,11 @@ // Created by rookie.w on 2020/12/26. // -import UIKit -import SnapKit import Then +import SnapKit +import UIKit -public final class MessageCountBadgeView: UIView { +final class MessageCountBadgeView: UIView { private var totalCount: UILabel = UILabel() public var count: Int? { diff --git a/Dear-World/Dear-World/Source/Presentation/Scene/Cheering Map/CheeringMapReactor.swift b/Dear-World/Dear-World/Source/Presentation/Scene/Cheering Map/CheeringMapReactor.swift index 3f2cf5b..46cf39d 100644 --- a/Dear-World/Dear-World/Source/Presentation/Scene/Cheering Map/CheeringMapReactor.swift +++ b/Dear-World/Dear-World/Source/Presentation/Scene/Cheering Map/CheeringMapReactor.swift @@ -9,7 +9,6 @@ import Foundation import ReactorKit final class CheeringMapReactor: Reactor { - typealias API = World.API typealias Model = World.Model @@ -29,6 +28,8 @@ final class CheeringMapReactor: Reactor { } var initialState: State = State() + + // MARK: 🔫 Mutate func mutate(action: Action) -> Observable { switch action { case .viewDidLoad: @@ -42,6 +43,7 @@ final class CheeringMapReactor: Reactor { } } + // MARK: ⚡️ Reduce func reduce(state: State, mutation: Mutation) -> State { var newState = currentState switch mutation { diff --git a/Dear-World/Dear-World/Source/Presentation/Scene/Discover/Cell/MessageTableViewCell.swift b/Dear-World/Dear-World/Source/Presentation/Scene/Discover/Cell/MessageTableViewCell.swift index 8083b0b..bc268c9 100644 --- a/Dear-World/Dear-World/Source/Presentation/Scene/Discover/Cell/MessageTableViewCell.swift +++ b/Dear-World/Dear-World/Source/Presentation/Scene/Discover/Cell/MessageTableViewCell.swift @@ -8,140 +8,142 @@ import UIKit final class MessageTableViewCell: UICollectionViewCell { - let emojiLabel: UILabel = UILabel() - let nameLabel: UILabel = UILabel() - let countryLabel: UILabel = UILabel() - let detailTextView: UITextView = UITextView() - // TODO: likeView를 커스텀뷰로 만들기 - let likeView: UIImageView = UIImageView() - let likeCountLabel: UILabel = UILabel() - let shareButton: UIButton = UIButton() - - override func awakeFromNib() { - super.awakeFromNib() - // Initialization code + + // MARK: 🖼 UI + let emojiLabel: UILabel = UILabel() + let nameLabel: UILabel = UILabel() + let countryLabel: UILabel = UILabel() + let detailTextView: UITextView = UITextView() + let likeView: UIImageView = UIImageView() + let likeCountLabel: UILabel = UILabel() + let shareButton: UIButton = UIButton() + + // MARK: 🏁 Initialize + override init(frame: CGRect) { + super.init(frame: frame) + + setupUI() + bind() + } + + required init?(coder: NSCoder) { + super.init(coder: coder) + + setupUI() + bind() + } + + // MARK: 🎛 Setup + private func setupUI() { + self.do { + $0.backgroundColor = .white + $0.layer.masksToBounds = true + $0.layer.cornerRadius = 20 } - override init(frame: CGRect) { - super.init(frame: frame) - setupUI() - bind() + let emojiView: UIImageView = UIImageView().then { + $0.image = UIImage(named: "emojiBox") + } + self.addSubview(emojiView) + emojiView.snp.makeConstraints { + $0.top.leading.equalToSuperview().inset(30) + $0.height.width.equalTo(40) } - required init?(coder: NSCoder) { - super.init(coder: coder) - setupUI() - bind() + self.emojiLabel.do { + $0.text = "🎅🏻" + // FIXME : 14처럼 고정된 값 없이 최대로 꽉차게 할 수 없는가? + $0.font = .systemFont(ofSize: 14) + $0.textAlignment = .center + } + self.addSubview(self.emojiLabel) + self.emojiLabel.snp.makeConstraints { + $0.size.equalTo(20) + $0.center.equalTo(emojiView) } - private func setupUI() { - self.do { - $0.backgroundColor = .white - $0.layer.masksToBounds = true - $0.layer.cornerRadius = 20 - } - - let emojiView: UIImageView = UIImageView().then { - $0.image = UIImage(named: "emojiBox") - } - self.addSubview(emojiView) - emojiView.snp.makeConstraints { - $0.top.leading.equalToSuperview().inset(30) - $0.height.width.equalTo(40) - } - - self.emojiLabel.do { - $0.text = "🎅🏻" - // FIXME : 14처럼 고정된 값 없이 최대로 꽉차게 할 수 없는가? - $0.font = .systemFont(ofSize: 14) - $0.textAlignment = .center - } - self.addSubview(self.emojiLabel) - self.emojiLabel.snp.makeConstraints { - $0.size.equalTo(20) - $0.center.equalTo(emojiView) - } - - self.nameLabel.do { - $0.text = "Judy" - $0.font = .boldSystemFont(ofSize: 16) - $0.textColor = .warmBlue - } - self.addSubview(self.nameLabel) - self.nameLabel.snp.makeConstraints { - $0.top.equalTo(emojiView.snp.top) - $0.leading.equalTo(emojiView.snp.trailing).offset(10) - $0.trailing.greaterThanOrEqualToSuperview().inset(30) - } - - self.countryLabel.do { - $0.text = "🇰🇷 South Korea" - $0.font = .boldSystemFont(ofSize: 12) - $0.textColor = .grayWhite - } - self.addSubview(self.countryLabel) - self.countryLabel.snp.makeConstraints { - $0.bottom.equalTo(emojiView.snp.bottom) - $0.leading.equalTo(emojiView.snp.trailing).offset(10) - $0.trailing.greaterThanOrEqualToSuperview().inset(30) - } - - self.detailTextView.do { - $0.text = "Hello world, dont worry because you’re strong enough to overcome this corona blue. At the end of the day, trust yourself. more" - $0.font = .systemFont(ofSize: 12) - $0.textColor = .black - $0.textContainerInset = .zero - $0.isScrollEnabled = false - $0.isEditable = false - } - self.addSubview(self.detailTextView) - self.detailTextView.snp.makeConstraints { - $0.leading.trailing.equalToSuperview().inset(30) - $0.top.equalTo(emojiView.snp.bottom).offset(10) - $0.height.equalTo(43) - } - - self.likeView.do { - $0.image = UIImage(named: "heart") - } - self.addSubview(likeView) - self.likeView.snp.makeConstraints { - $0.leading.equalToSuperview().inset(30) - $0.bottom.equalToSuperview().inset(29) - $0.height.equalTo(17) - $0.width.equalTo(20) - } - - self.likeCountLabel.do { - $0.font = .boldSystemFont(ofSize: 12) - $0.textColor = .grayWhite - $0.text = "32" - } - self.addSubview(self.likeCountLabel) - self.likeCountLabel.snp.makeConstraints { - $0.centerY.equalTo(likeView.snp.centerY) - $0.width.equalTo(16) - $0.height.equalTo(14) - $0.leading.equalTo(likeView.snp.trailing).offset(5) - } - - self.shareButton.do { - $0.backgroundColor = .refreshingWhite - $0.layer.masksToBounds = true - $0.layer.cornerRadius = 8 - $0.setImage(UIImage(named: "share"), for: .normal) - $0.setImage(UIImage(named: "share_press"), for: .highlighted) - $0.tintColor = .warmBlue - } - self.addSubview(shareButton) - shareButton.snp.makeConstraints { - $0.trailing.equalToSuperview().inset(30) - $0.bottom.equalToSuperview().inset(25) - $0.width.equalTo(30) - $0.height.equalTo(25) - } - } - func bind() { - + self.nameLabel.do { + $0.text = "Judy" + $0.font = .boldSystemFont(ofSize: 16) + $0.textColor = .warmBlue + } + self.addSubview(self.nameLabel) + self.nameLabel.snp.makeConstraints { + $0.top.equalTo(emojiView.snp.top) + $0.leading.equalTo(emojiView.snp.trailing).offset(10) + $0.trailing.greaterThanOrEqualToSuperview().inset(30) + } + + self.countryLabel.do { + $0.text = "🇰🇷 South Korea" + $0.font = .boldSystemFont(ofSize: 12) + $0.textColor = .grayWhite + } + self.addSubview(self.countryLabel) + self.countryLabel.snp.makeConstraints { + $0.bottom.equalTo(emojiView.snp.bottom) + $0.leading.equalTo(emojiView.snp.trailing).offset(10) + $0.trailing.greaterThanOrEqualToSuperview().inset(30) + } + + self.detailTextView.do { + $0.text = "Hello world, dont worry because you’re strong enough to overcome this corona blue. At the end of the day, trust yourself. more" + $0.font = .systemFont(ofSize: 12) + $0.textColor = .black + $0.textContainerInset = .zero + $0.isScrollEnabled = false + $0.isEditable = false } + self.addSubview(self.detailTextView) + self.detailTextView.snp.makeConstraints { + $0.leading.trailing.equalToSuperview().inset(30) + $0.top.equalTo(emojiView.snp.bottom).offset(10) + $0.height.equalTo(43) + } + + self.likeView.do { + $0.image = UIImage(named: "heart") + } + self.addSubview(likeView) + self.likeView.snp.makeConstraints { + $0.leading.equalToSuperview().inset(30) + $0.bottom.equalToSuperview().inset(29) + $0.height.equalTo(17) + $0.width.equalTo(20) + } + + self.likeCountLabel.do { + $0.font = .boldSystemFont(ofSize: 12) + $0.textColor = .grayWhite + $0.text = "32" + } + self.addSubview(self.likeCountLabel) + self.likeCountLabel.snp.makeConstraints { + $0.centerY.equalTo(likeView.snp.centerY) + $0.width.equalTo(16) + $0.height.equalTo(14) + $0.leading.equalTo(likeView.snp.trailing).offset(5) + } + + self.shareButton.do { + $0.backgroundColor = .refreshingWhite + $0.layer.masksToBounds = true + $0.layer.cornerRadius = 8 + $0.setImage(UIImage(named: "share"), for: .normal) + $0.setImage(UIImage(named: "share_press"), for: .highlighted) + $0.tintColor = .warmBlue + } + self.addSubview(shareButton) + shareButton.snp.makeConstraints { + $0.trailing.equalToSuperview().inset(30) + $0.bottom.equalToSuperview().inset(25) + $0.width.equalTo(30) + $0.height.equalTo(25) + } + } + + // MARK: 🔗 Bind + func bind() { + + } } diff --git a/Dear-World/Dear-World/Source/Presentation/Scene/Discover/DiscoverReactor.swift b/Dear-World/Dear-World/Source/Presentation/Scene/Discover/DiscoverReactor.swift index fad5e31..450276a 100644 --- a/Dear-World/Dear-World/Source/Presentation/Scene/Discover/DiscoverReactor.swift +++ b/Dear-World/Dear-World/Source/Presentation/Scene/Discover/DiscoverReactor.swift @@ -36,10 +36,12 @@ final class DiscoverReactor: Reactor { var initialState: State + // MARK: 🏁 Initialize init() { self.initialState = State() } + // MARK: 🔫 Mutate func mutate(action: Action) -> Observable { switch action { case let .countryDidChanged(country): @@ -50,6 +52,7 @@ final class DiscoverReactor: Reactor { .map { .setMessages(result: $0) }, .just(.setLoading(false)) ) + case .refresh: return .concat([ .just(Mutation.setRefreshing(true)), @@ -57,6 +60,7 @@ final class DiscoverReactor: Reactor { .map { .setMessages(result: $0) }, .just(Mutation.setRefreshing(false)) ]) + case .loadMore: return Observable.concat([ APIMock().getMessages(page: 2, country: currentState.country) @@ -65,6 +69,7 @@ final class DiscoverReactor: Reactor { } } + // MARK: ⚡️ Reduce func reduce(state: State, mutation: Mutation) -> State { var newState: State = state switch mutation { diff --git a/Dear-World/Dear-World/Source/Presentation/Scene/Discover/DiscoverViewController.swift b/Dear-World/Dear-World/Source/Presentation/Scene/Discover/DiscoverViewController.swift index 9fd0026..2c059ef 100644 --- a/Dear-World/Dear-World/Source/Presentation/Scene/Discover/DiscoverViewController.swift +++ b/Dear-World/Dear-World/Source/Presentation/Scene/Discover/DiscoverViewController.swift @@ -13,31 +13,24 @@ import Then import UIKit final class DiscoverViewController: UIViewController, View { + + // MARK: 🖼 UI private let messageCountBadgeView: MessageCountBadgeView = MessageCountBadgeView() private let filterContainerView: UIView = UIView() private let countryLabel: UILabel = UILabel() private let messageCollectionView: UICollectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()) private var messages: [MessageMock] = [] - private var outerScrollView: UIScrollView = UIScrollView() + private let outerScrollView: UIScrollView = UIScrollView() private var scrollOuter: Bool = true private var scrollRecentConvertTime: Date = Date() var disposeBag: DisposeBag = DisposeBag() - init() { - super.init(nibName: nil, bundle: nil) - self.view.backgroundColor = .breathingWhite - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - override func viewDidLoad() { super.viewDidLoad() + setupUI() setupCollectionView() - self.reactor = DiscoverReactor() startInitAnimation() } @@ -55,6 +48,79 @@ final class DiscoverViewController: UIViewController, View { } } + // MARK: 🎛 Setup + private func setupUI() { + self.view.backgroundColor = .breathingWhite + + self.outerScrollView.do { + $0.isScrollEnabled = true + $0.showsVerticalScrollIndicator = false + $0.contentSize.height = self.view.frame.height + 264 + $0.delegate = self + } + + self.view.addSubview(outerScrollView) + self.outerScrollView.snp.makeConstraints { + $0.top.bottom.leading.trailing.equalToSuperview() + } + + self.outerScrollView.addSubview(self.messageCountBadgeView) + self.outerScrollView.addSubview(self.filterContainerView) + self.filterContainerView.snp.makeConstraints { + $0.centerX.equalToSuperview() + $0.top.equalTo(self.messageCountBadgeView.snp.bottom).offset(30) + $0.height.equalTo(26) + } + + countryLabel.do { + $0.font = .boldSystemFont(ofSize: 22) + $0.textColor = .warmBlue + $0.text = "Whole world" + } + + filterContainerView.addSubview(countryLabel) + countryLabel.snp.makeConstraints { + $0.centerY.equalToSuperview() + $0.leading.equalTo(filterContainerView.snp.leading) + } + + let select: UIImageView = UIImageView().then { + $0.image = UIImage(named: "select") + } + filterContainerView.addSubview(select) + select.snp.makeConstraints { + $0.centerY.equalToSuperview() + $0.width.equalTo(14) + $0.height.equalTo(8) + $0.trailing.equalTo(filterContainerView.snp.trailing) + $0.leading.equalTo(countryLabel.snp.trailing).offset(5) + } + + messageCollectionView.do { + $0.backgroundColor = .breathingWhite + $0.isScrollEnabled = false + } + self.outerScrollView.addSubview(self.messageCollectionView) + self.messageCollectionView.snp.makeConstraints { + $0.top.equalTo(filterContainerView.snp.bottom).offset(30) + $0.trailing.leading.equalTo(self.view.safeAreaLayoutGuide).inset(20) + $0.bottom.equalTo(self.outerScrollView.frameLayoutGuide.snp.bottom) + } + } + + private func setupCollectionView() { + self.messageCollectionView.do { + $0.register(MessageTableViewCell.self, forCellWithReuseIdentifier: "MessageCell") + $0.delegate = self + $0.dataSource = self + } + + if let layout: UICollectionViewFlowLayout = self.messageCollectionView.collectionViewLayout as? UICollectionViewFlowLayout { + layout.minimumLineSpacing = 20 + } + } + + // MARK: 🔗 Bind func bind(reactor: DiscoverReactor) { reactor.state .map(\.messageCount) @@ -95,15 +161,6 @@ final class DiscoverViewController: UIViewController, View { } .disposed(by: self.disposeBag) - self.countryLabel - .rx.observe(String.self, "text") - .filter { $0 != nil } - .map { $0! } - .distinctUntilChanged() - .map { Reactor.Action.countryDidChanged(country: $0) } - .bind(to: reactor.action) - .disposed(by: self.disposeBag) - self.messageCollectionView .refreshControl?.rx .controlEvent(.valueChanged) @@ -128,72 +185,6 @@ final class DiscoverViewController: UIViewController, View { .bind(to: reactor.action) .disposed(by: self.disposeBag) } - - private func setupUI() { - self.outerScrollView.do { - $0.isScrollEnabled = true - $0.showsVerticalScrollIndicator = false - $0.contentSize.height = self.view.frame.height + 264 - $0.delegate = self - } - - self.view.addSubview(outerScrollView) - self.outerScrollView.snp.makeConstraints { - $0.top.bottom.leading.trailing.equalToSuperview() - } - - self.outerScrollView.addSubview(self.messageCountBadgeView) - self.outerScrollView.addSubview(self.filterContainerView) - self.filterContainerView.snp.makeConstraints { - $0.centerX.equalToSuperview() - $0.top.equalTo(self.messageCountBadgeView.snp.bottom).offset(30) - $0.height.equalTo(26) - } - - countryLabel.do { - $0.font = .boldSystemFont(ofSize: 22) - $0.textColor = .warmBlue - $0.text = "Whole world" - } - - filterContainerView.addSubview(countryLabel) - countryLabel.snp.makeConstraints { - $0.centerY.equalToSuperview() - $0.leading.equalTo(filterContainerView.snp.leading) - } - - let select: UIImageView = UIImageView().then { - $0.image = UIImage(named: "select") - } - filterContainerView.addSubview(select) - select.snp.makeConstraints { - $0.centerY.equalToSuperview() - $0.width.equalTo(14) - $0.height.equalTo(8) - $0.trailing.equalTo(filterContainerView.snp.trailing) - $0.leading.equalTo(countryLabel.snp.trailing).offset(5) - } - - messageCollectionView.do { - $0.backgroundColor = .breathingWhite - $0.isScrollEnabled = false - } - self.outerScrollView.addSubview(self.messageCollectionView) - self.messageCollectionView.snp.makeConstraints { - $0.top.equalTo(filterContainerView.snp.bottom).offset(30) - $0.trailing.leading.equalTo(self.view.safeAreaLayoutGuide).inset(20) - $0.bottom.equalTo(self.outerScrollView.frameLayoutGuide.snp.bottom) - } - } - - private func setupCollectionView() { - self.messageCollectionView.register(MessageTableViewCell.self, forCellWithReuseIdentifier: "messageCell") - self.messageCollectionView.delegate = self - self.messageCollectionView.dataSource = self - - let layout: UICollectionViewFlowLayout = self.messageCollectionView.collectionViewLayout as! UICollectionViewFlowLayout - layout.minimumLineSpacing = 20 - } } extension DiscoverViewController: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout{ func collectionView( @@ -207,18 +198,27 @@ extension DiscoverViewController: UICollectionViewDelegate, UICollectionViewData _ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath ) -> UICollectionViewCell { - guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "messageCell", for: indexPath) as? MessageTableViewCell else {return UICollectionViewCell()} - cell.nameLabel.text = self.messages[indexPath.row].name - cell.emojiLabel.text = self.messages[indexPath.row].emoji - cell.detailTextView.text = self.messages[indexPath.row].detail - cell.likeCountLabel.text = self.messages[indexPath.row].likes.formatted - cell.countryLabel.text = self.messages[indexPath.row].countryName + guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MessageCell", for: indexPath) as? MessageTableViewCell else { return UICollectionViewCell() } + cell.do { + $0.nameLabel.text = self.messages[indexPath.row].name + $0.emojiLabel.text = self.messages[indexPath.row].emoji + $0.detailTextView.text = self.messages[indexPath.row].detail + $0.likeCountLabel.text = self.messages[indexPath.row].likes.formatted + $0.countryLabel.text = self.messages[indexPath.row].countryName + } bindShareButton(button: cell.shareButton) if reactor?.currentState.currentPage == 1 { - self.animate(view: cell, alpha: 0.3, length: 50, duration: 0.5, delay: Double(indexPath.row)) + self.animate( + view: cell, + alpha: 0.3, + length: 50, + duration: 0.5, + delay: Double(indexPath.row) + ) } return cell } + func collectionView( _ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, @@ -242,7 +242,6 @@ extension DiscoverViewController: UIScrollViewDelegate { func scrollViewDidScroll(_ scrollView: UIScrollView) { let flag = scrollView.contentOffset.y <= 225 if flag != self.scrollOuter && self.scrollRecentConvertTime.timeIntervalSinceNow < -5 { - print(flag) self.outerScrollView.isScrollEnabled = flag self.messageCollectionView.isScrollEnabled = !flag self.scrollOuter.toggle() diff --git a/Dear-World/Dear-World/Source/Presentation/Scene/Send Message/SendMessageReactor.swift b/Dear-World/Dear-World/Source/Presentation/Scene/Send Message/SendMessageReactor.swift index 36771aa..9c1eef4 100644 --- a/Dear-World/Dear-World/Source/Presentation/Scene/Send Message/SendMessageReactor.swift +++ b/Dear-World/Dear-World/Source/Presentation/Scene/Send Message/SendMessageReactor.swift @@ -59,6 +59,7 @@ final class SendMessageReactor: Reactor { let initialState: State = State() + // MARK: 🔫 Mutate func mutate(action: Action) -> Observable { switch action { case .tapClose: @@ -88,6 +89,7 @@ final class SendMessageReactor: Reactor { } } + // MARK: ⚡️ Reduce func reduce(state: State, mutation: Mutation) -> State { var newState: State switch mutation { @@ -131,6 +133,7 @@ final class SendMessageReactor: Reactor { return newState } + // MARK: 📐 Formatting private func percent(current: Int, total: Int) -> Float { return Float(current) / Float(total) } diff --git a/Dear-World/Dear-World/Source/Presentation/View/CheerButton.swift b/Dear-World/Dear-World/Source/Presentation/View/CheerButton.swift index a48c6e7..d1f5809 100644 --- a/Dear-World/Dear-World/Source/Presentation/View/CheerButton.swift +++ b/Dear-World/Dear-World/Source/Presentation/View/CheerButton.swift @@ -10,8 +10,6 @@ import RxSwift import UIKit final class CheerUpButton: UIButton { - - // MARK: 🦴 State enum Active { static let image: UIImage = UIImage(named: "heart_liked")! static let backgroundImage: UIImage = .from(color: .refreshingWhite) @@ -21,6 +19,7 @@ final class CheerUpButton: UIButton { static let backgroundImage: UIImage = .from(color: .white) } + // MARK: 🖼 UI var emitter: CAEmitterLayer? = CAEmitterLayer() weak var anchorView: UIView? private let disposeBag: DisposeBag = DisposeBag() diff --git a/Dear-World/Dear-World/Source/Presentation/View/CountrySelectController.swift b/Dear-World/Dear-World/Source/Presentation/View/CountrySelectController.swift index 72a09f5..7ec2fcb 100644 --- a/Dear-World/Dear-World/Source/Presentation/View/CountrySelectController.swift +++ b/Dear-World/Dear-World/Source/Presentation/View/CountrySelectController.swift @@ -12,130 +12,120 @@ import Then import UIKit public final class CountrySelectController: UIViewController { - private var countryTableView: UITableView = UITableView() - private let countries: [String] = ["korea", "japan", "China", "USA", "asdf", "USA", "asdf", "USA", "asdf", "USA", "asdf"] - private let exitButton: UIButton = UIButton() - private var selectedCountry: String? = nil - let disposeBag: DisposeBag = DisposeBag() - - override public func viewDidLoad() { - super.viewDidLoad() - setupUI() - setupTableView() - bind() + + // MARK: 🖼 UI + private var countryTableView: UITableView = UITableView() + private let countries: [String] = ["korea", "japan", "China", "USA", "asdf", "USA", "asdf", "USA", "asdf", "USA", "asdf"] + private let exitButton: UIButton = UIButton() + private var selectedCountry: String? = nil + let disposeBag: DisposeBag = DisposeBag() + + override public func viewDidLoad() { + super.viewDidLoad() + setupUI() + setupTableView() + bind() + } + + // MARK: 🎛 Setup + private func setupUI() { + self.view.do { + $0.backgroundColor = .white + $0.layer.masksToBounds = true + $0.layer.cornerRadius = 15 + } + self.exitButton.do { + $0.setImage(UIImage(named: "cancel"), for: .normal) + $0.tintColor = .warmBlue } - private func setupUI() { - self.view.do { - $0.backgroundColor = .white - $0.layer.masksToBounds = true - $0.layer.cornerRadius = 15 - } - self.exitButton.do { - $0.setImage(UIImage(named: "cancel"), for: .normal) - $0.tintColor = .warmBlue - } - self.view.addSubview(exitButton) - self.exitButton.snp.makeConstraints { - $0.size.equalTo(12) - $0.top.trailing.equalToSuperview().inset(20) - } - self.countryTableView.do { - $0.backgroundColor = .white - } - self.view.addSubview(self.countryTableView) - self.countryTableView.snp.makeConstraints { - $0.top.equalTo(exitButton.snp.bottom).offset(10) - $0.trailing.leading.bottom.equalToSuperview() - } + self.view.addSubview(exitButton) + self.exitButton.snp.makeConstraints { + $0.size.equalTo(12) + $0.top.trailing.equalToSuperview().inset(20) } - private func setupTableView() { - self.countryTableView.register(UITableViewCell.self, forCellReuseIdentifier: "countryCell") - self.countryTableView.rowHeight = 56 + self.countryTableView.do { + $0.backgroundColor = .white } - private func bind() { - self.exitButton - .rx.tap - .bind { _ in - self.willMove(toParent: nil) - } - .disposed(by: self.disposeBag) - - Observable.just(self.countries) - .bind(to: self.countryTableView.rx.items) {(tableView, row, item) -> UITableViewCell in - let cell = tableView.dequeueReusableCell(withIdentifier: "countryCell", for: IndexPath(row: row, section: 0)) - cell.textLabel?.text = item - cell.textLabel?.font = .systemFont(ofSize: 14) - cell.textLabel?.textColor = .warmBlue - //TODO: CheckMark 달기 - return cell - } - .disposed(by: self.disposeBag) - - self.countryTableView - .rx.itemSelected - .map{[weak self] in self?.countries[$0.row]} - .bind { [weak self] country in - self?.selectedCountry = country - self?.willMove(toParent: nil) - } - .disposed(by: self.disposeBag) + self.view.addSubview(self.countryTableView) + self.countryTableView.snp.makeConstraints { + $0.top.equalTo(exitButton.snp.bottom).offset(10) + $0.trailing.leading.bottom.equalToSuperview() } + } + private func setupTableView() { + self.countryTableView.register(UITableViewCell.self, forCellReuseIdentifier: "countryCell") + self.countryTableView.rowHeight = 56 + } + + // MARK: 🔗 Bind + private func bind() { + self.exitButton + .rx.tap + .bind { _ in + self.willMove(toParent: nil) + } + .disposed(by: self.disposeBag) + + Observable.just(self.countries) + .bind(to: self.countryTableView.rx.items) {(tableView, row, item) -> UITableViewCell in + let cell = tableView.dequeueReusableCell(withIdentifier: "countryCell", for: IndexPath(row: row, section: 0)) + cell.textLabel?.text = item + cell.textLabel?.font = .systemFont(ofSize: 14) + cell.textLabel?.textColor = .warmBlue + //TODO: CheckMark 달기 + return cell + } + .disposed(by: self.disposeBag) + + self.countryTableView + .rx.itemSelected + .map{[weak self] in self?.countries[$0.row]} + .bind { [weak self] country in + self?.selectedCountry = country + self?.willMove(toParent: nil) + } + .disposed(by: self.disposeBag) + } } // present 함수 extension CountrySelectController { - public static func selectCountry(presenting: UIViewController, disposeBag: DisposeBag) -> Observable { - return Observable.create { observer in - guard let base = presenting.tabBarController else { - observer.onError(NSError()) - return Disposables.create() - } - presenting.view.isUserInteractionEnabled = false - let presented: CountrySelectController = CountrySelectController() - presented.loadViewIfNeeded() - base.addChild(presented) - base.view.addSubview(presented.view) + public static func selectCountry(presenting: UIViewController, disposeBag: DisposeBag) -> Observable { + return Observable.create { observer in + guard let base = presenting.tabBarController else { + observer.onError(NSError()) + return Disposables.create() + } + presenting.view.isUserInteractionEnabled = false + let presented: CountrySelectController = CountrySelectController() + presented.loadViewIfNeeded() + base.addChild(presented) + base.view.addSubview(presented.view) + presented.view.frame.origin.y = base.view.frame.height + UIView.animate(withDuration: 0.3) { + presenting.view.alpha = 0.6 + presented.view.frame.origin.y = base.view.frame.height - 500 + } completion: { (_) in + presented.didMove(toParent: base) + } + + presented.rx.methodInvoked(#selector(UIViewController.willMove(toParent:))) + .bind { _ in + if let country: String = presented.selectedCountry { + observer.onNext(country) + } + UIView.animate(withDuration: 0.3) { + presenting.view.alpha = 1 presented.view.frame.origin.y = base.view.frame.height - UIView.animate(withDuration: 0.3) { - presenting.view.alpha = 0.6 - presented.view.frame.origin.y = base.view.frame.height - 500 - } completion: { (_) in - presented.didMove(toParent: base) - } - - presented.rx.methodInvoked(#selector(UIViewController.willMove(toParent:))) - .bind { _ in - if let country: String = presented.selectedCountry { - observer.onNext(country) - } - UIView.animate(withDuration: 0.3) { - presenting.view.alpha = 1 - presented.view.frame.origin.y = base.view.frame.height - } completion: { (_) in - presenting.view.isUserInteractionEnabled = true - presented.view.removeFromSuperview() - presented.removeFromParent() - observer.onCompleted() - } - }.disposed(by: disposeBag) - - return Disposables.create() - } + } completion: { (_) in + presenting.view.isUserInteractionEnabled = true + presented.view.removeFromSuperview() + presented.removeFromParent() + observer.onCompleted() + } + }.disposed(by: disposeBag) + + return Disposables.create() } + } } - -//private class CountryCell: UITableViewCell { -// override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { -// super.init(style: style, reuseIdentifier: reuseIdentifier) -// setupUI() -// } -// required init?(coder: NSCoder) { -// fatalError("init(coder:) has not been implemented") -// } -// func setupUI() { -// self.do { -// $0.frame.size.height = 100 -// $0.backgroundColor = .red -// } -// } -//} diff --git a/Dear-World/Dear-World/Source/Presentation/View/ErrorView.swift b/Dear-World/Dear-World/Source/Presentation/View/ErrorView.swift index b8ee461..de6be6c 100644 --- a/Dear-World/Dear-World/Source/Presentation/View/ErrorView.swift +++ b/Dear-World/Dear-World/Source/Presentation/View/ErrorView.swift @@ -33,7 +33,7 @@ final class ErrorView: UIView { setupUI() } - // MARK: 📍 Setup + // MARK: 🎛 Setup private func setupUI(with: ErrorReason? = nil) { backgroundColor = .breathingWhite guard let errorReason = errorReason else { return } diff --git a/Dear-World/Dear-World/Source/Presentation/View/SelectCountryView.swift b/Dear-World/Dear-World/Source/Presentation/View/SelectCountryView.swift index b8db7a7..6059938 100644 --- a/Dear-World/Dear-World/Source/Presentation/View/SelectCountryView.swift +++ b/Dear-World/Dear-World/Source/Presentation/View/SelectCountryView.swift @@ -27,7 +27,7 @@ final class SelectCountryView: UIView { setupUI() } - // MARK: 📍 Setup + // MARK: 🎛 Setup private func setupUI() { self.backgroundColor = .grayWhite self.layer.cornerRadius = 7