diff --git a/Projects/Presentation/Sources/EmotionRegister/View/EmotionCollectionViewLayout.swift b/Projects/Presentation/Sources/EmotionRegister/View/EmotionCollectionViewLayout.swift index c397b00..6330cee 100644 --- a/Projects/Presentation/Sources/EmotionRegister/View/EmotionCollectionViewLayout.swift +++ b/Projects/Presentation/Sources/EmotionRegister/View/EmotionCollectionViewLayout.swift @@ -8,8 +8,12 @@ import UIKit final class EmotionCollectionViewLayout: UICollectionViewFlowLayout { - private let itemWidthRatio: CGFloat = 0.5 - private let lineSpacing: CGFloat = 16 + private enum Layout { + static let itemWidthRatio: CGFloat = 0.5 + static let lineSpacing: CGFloat = 16 + static let bottomSpacing: CGFloat = 100 + } + private var baseDistance: CGFloat { itemSize.width + minimumLineSpacing } override class var layoutAttributesClass: AnyClass { EmotionCollectionViewLayoutAttributes.self } @@ -19,14 +23,18 @@ final class EmotionCollectionViewLayout: UICollectionViewFlowLayout { guard let collectionView else { return } scrollDirection = .horizontal - minimumLineSpacing = lineSpacing + minimumLineSpacing = Layout.lineSpacing - let itemWidth = floor(collectionView.bounds.width * itemWidthRatio) - let itemHeight = collectionView.bounds.height + let itemWidth = floor(collectionView.bounds.width * Layout.itemWidthRatio) + let itemHeight = collectionView.bounds.height - Layout.bottomSpacing itemSize = CGSize(width: itemWidth, height: itemHeight) let insetX = (collectionView.bounds.width - itemWidth) / 2 - sectionInset = UIEdgeInsets(top: 0, left: insetX, bottom: 0, right: insetX) + sectionInset = UIEdgeInsets( + top: 0, + left: insetX, + bottom: Layout.bottomSpacing, + right: insetX) collectionView.decelerationRate = .fast } @@ -75,4 +83,14 @@ final class EmotionCollectionViewLayout: UICollectionViewFlowLayout { override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool { return true } + + func fetchcurrentIndex() -> Int? { + guard let collectionView else { return nil } + + let centerX = collectionView.contentOffset.x + (collectionView.bounds.width / 2) + let insetX = (collectionView.bounds.width - itemSize.width) / 2 + + let relativeX = centerX - insetX + return Int(round(relativeX / baseDistance)) + } } diff --git a/Projects/Presentation/Sources/EmotionRegister/View/EmotionRegistrationViewController.swift b/Projects/Presentation/Sources/EmotionRegister/View/EmotionRegistrationViewController.swift index 185f193..84c0a18 100644 --- a/Projects/Presentation/Sources/EmotionRegister/View/EmotionRegistrationViewController.swift +++ b/Projects/Presentation/Sources/EmotionRegister/View/EmotionRegistrationViewController.swift @@ -18,7 +18,7 @@ final class EmotionRegistrationViewController: BaseViewController? private var cancellables: Set + private var lastMarbleCellIndex: Int = 0 + var itemCount: Int { - return (dataSource?.snapshot().numberOfItems ?? 0) / 3 + return (dataSource?.snapshot().numberOfItems ?? 0) / itemSetCount } @@ -121,6 +127,9 @@ final class EmotionRegistrationViewController: BaseViewController() snapshot.appendSections([0]) - snapshot.appendItems(tripledEmotions) + snapshot.appendItems(multipliedEmotions) self.dataSource?.apply(snapshot, animatingDifferences: false) self.scrollToIndex(index: originalEmotionCount) @@ -350,8 +376,7 @@ final class EmotionRegistrationViewController: BaseViewController= itemCount * 2 / 3 { + if indexPath.row < itemCount / itemSetCount || indexPath.row >= itemCount * (itemSetCount / 2 + 1) / itemSetCount { scrollToIndex(index: index) } viewModel.action(input: .selectEmotion(index: index))