-
Notifications
You must be signed in to change notification settings - Fork 0
PopUpRegisterViewControler 분리 #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
c6f406e
29738f8
2d5909d
b8bc440
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import UIKit | ||
|
|
||
| import SnapKit | ||
|
|
||
| final class PopUpImagesCollectionView: UICollectionView { | ||
| // MARK: - Properties | ||
| enum Constant { | ||
| static let imageWidth: CGFloat = 80 | ||
| static let imageHeight: CGFloat = 120 | ||
| static let imageSpacing: CGFloat = 8 | ||
| } | ||
|
|
||
| var onImageSelected: ((Int) -> Void)? | ||
| var onMainImageToggled: ((Int) -> Void)? | ||
| var onImageDeleted: ((Int) -> Void)? | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rx가 아니라 클로저로 스트림을 연결한 이유가 따로 있을까요?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 단순이벤트라 판단되어 연산자체인에 오버헤드인지 .. 빌드에서 무한빌드가 되는케이스가 있었습니다 |
||
|
|
||
| private var images: [ExtendedImage] = [] | ||
|
|
||
| // MARK: - init | ||
| init() { | ||
| let layout = UICollectionViewFlowLayout() | ||
| layout.scrollDirection = .horizontal | ||
| layout.itemSize = CGSize(width: Constant.imageWidth, height: Constant.imageHeight) | ||
| layout.minimumLineSpacing = Constant.imageSpacing | ||
|
|
||
| super.init(frame: .zero, collectionViewLayout: layout) | ||
|
|
||
| self.addViews() | ||
| self.setupContstraints() | ||
| self.configureUI() | ||
| } | ||
|
|
||
| required init?(coder: NSCoder) { | ||
| fatalError("\(#file), \(#function) Error") | ||
| } | ||
| } | ||
|
|
||
| // MARK: - Setup | ||
| private extension PopUpImagesCollectionView { | ||
| func addViews() { } | ||
|
|
||
| func setupContstraints() { } | ||
|
|
||
| func configureUI() { | ||
| self.backgroundColor = .clear | ||
| self.register(ImageCell.self, forCellWithReuseIdentifier: ImageCell.identifier) | ||
| self.dataSource = self | ||
| self.delegate = self | ||
| self.showsHorizontalScrollIndicator = false | ||
| } | ||
| } | ||
|
|
||
| // MARK: - Public Methods | ||
| extension PopUpImagesCollectionView { | ||
| func updateImages(_ images: [ExtendedImage]) { | ||
| self.images = images | ||
| self.reloadData() | ||
| } | ||
| } | ||
|
|
||
| // MARK: - UICollectionViewDataSource | ||
| extension PopUpImagesCollectionView: UICollectionViewDataSource { | ||
| func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { | ||
| return self.images.count | ||
| } | ||
|
|
||
| func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { | ||
| guard let cell = collectionView.dequeueReusableCell( | ||
| withReuseIdentifier: ImageCell.identifier, | ||
| for: indexPath | ||
| ) as? ImageCell else { | ||
| return UICollectionViewCell() | ||
| } | ||
|
|
||
| let item = self.images[indexPath.item] | ||
| cell.configure(with: item) | ||
|
|
||
| // 대표이미지 변경 | ||
| cell.onMainCheckToggled = { [weak self] in | ||
| self?.onMainImageToggled?(indexPath.item) | ||
| } | ||
|
|
||
| // 개별 삭제 | ||
| cell.onDeleteTapped = { [weak self] in | ||
| self?.onImageDeleted?(indexPath.item) | ||
| } | ||
|
|
||
| return cell | ||
| } | ||
| } | ||
|
|
||
| // MARK: - UICollectionViewDelegate | ||
| extension PopUpImagesCollectionView: UICollectionViewDelegate { | ||
| func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { | ||
| self.onImageSelected?(indexPath.item) | ||
| } | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 분리를 했는데도 많이 아직도 많네요 🥲 이번에 리팩토링때 클린아키텍처 구조로 더 분리를 해보죠 👍🏻
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 스트림이 길어지는 부분이 있어서 제가 내용을 정확히 확인하는 것에는 조금 난이도가 있습니다 ㅎㅎ. ㅠ 해당 작업 내용은 다시 한 번 확인해 보겠습니다!! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저희가 맞추기로 하였던 상수값을 빼는 부분을 적용해 주셨군요 좋습니다 :>