Skip to content

Commit

Permalink
[Feat] #273 - implemented newfilter view
Browse files Browse the repository at this point in the history
  • Loading branch information
seongmin221 committed Jul 14, 2024
1 parent 84d4f43 commit 442a15a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ final class NewFilterCollectionViewCell: UICollectionViewCell {
let label = UILabel()
label.font = .subHead
label.textColor = .gbbGray300
label.numberOfLines = 2
label.textAlignment = .center
return label
}()
private let content: UIView = UIView()

// MARK: - life cycle

Expand All @@ -47,17 +50,23 @@ final class NewFilterCollectionViewCell: UICollectionViewCell {
}

private func setLayout() {
contentView.addSubview(titleLabel)
content.addSubview(titleLabel)
titleLabel.snp.makeConstraints {
$0.centerX.equalToSuperview()
$0.top.equalToSuperview().inset(25)
}

contentView.addSubview(descriptionLabel)
content.addSubview(descriptionLabel)
descriptionLabel.snp.makeConstraints {
$0.centerX.equalToSuperview()
$0.top.equalTo(titleLabel.snp.bottom).offset(10)
$0.bottom.equalToSuperview().inset(25)
}

contentView.addSubview(content)
content.snp.makeConstraints {
$0.center.equalToSuperview()
}
}
}

Expand Down
10 changes: 6 additions & 4 deletions GEON-PPANG-iOS/Presentation/Scene/Filter/NewFilterType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ extension NewFilterType {
return UICollectionViewCompositionalLayout { _, _ in
let itemSize = NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1),
heightDimension: .absolute(106)
heightDimension: .absolute(100)
)
let item = NSCollectionLayoutItem(layoutSize: itemSize)

let groupSize = NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1),
heightDimension: .absolute(106)
heightDimension: .absolute(100)
)
let group = NSCollectionLayoutGroup.vertical(layoutSize: groupSize, subitems: [item])

Expand All @@ -79,18 +79,20 @@ extension NewFilterType {
case .breadType:
return UICollectionViewCompositionalLayout { _, _ in
let itemSize = NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1),
widthDimension: .fractionalWidth(0.45),
heightDimension: .absolute(161)
)
let item = NSCollectionLayoutItem(layoutSize: itemSize)

let groupSize = NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1),
heightDimension: .absolute(161)
)
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item])
let itemSpacing = NSCollectionLayoutSpacing.flexible(20)
group.interItemSpacing = itemSpacing

let section = NSCollectionLayoutSection(group: group)
section.interGroupSpacing = itemSpacing.spacing
return section
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class NewFilterViewController: UIViewController {
// MARK: - properties

private let isInitial: Bool
private var filterType: NewFilterType = .purpose
private var filterType: NewFilterType = .breadType

// MARK: - ui properties

Expand Down Expand Up @@ -54,7 +54,7 @@ final class NewFilterViewController: UIViewController {
return label
}()
private let filterCollectionView: UICollectionView = {
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: .init())
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())
collectionView.backgroundColor = .clear
collectionView.isScrollEnabled = false
collectionView.register(cell: NewFilterCollectionViewCell.self)
Expand Down Expand Up @@ -155,7 +155,7 @@ final class NewFilterViewController: UIViewController {
filterCollectionView.snp.makeConstraints {
$0.top.equalTo(navigationBar.snp.bottom).offset(124)
$0.horizontalEdges.equalToSuperview().inset(24)
$0.bottom.equalTo(nextButton.snp.top).offset(100)
$0.bottom.equalTo(nextButton.snp.top).offset(-50)
}

if isInitial {
Expand All @@ -178,12 +178,34 @@ final class NewFilterViewController: UIViewController {
if let description = filterType.description {
descriptionLabel.text = description
}

filterCollectionView.collectionViewLayout = filterType.layout
}
}

extension NewFilterViewController: UICollectionViewDelegate {}
extension NewFilterViewController: UICollectionViewDelegate {
// func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
// <#code#>
// }
}

extension NewFilterViewController: UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

let size = collectionView.bounds.size
switch filterType {
case .purpose, .ingredient:
let cellHeight = size.width/3.5
return .init(width: size.width, height: cellHeight)
case .breadType:
let cellWidth = size.width/2 - 10
let cellHeight = min(size.height/2 - 10, 160)
return .init(width: cellWidth, height: cellHeight)
}
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 20
}
}

extension NewFilterViewController: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
Expand Down

0 comments on commit 442a15a

Please sign in to comment.