Skip to content

Commit

Permalink
Bug/grid view constraints (#292)
Browse files Browse the repository at this point in the history
* fixes grid view bug, replace constraint constants with content insets

* update item size

* remove commented line
  • Loading branch information
shredlocker authored Jun 25, 2019
1 parent 1d0a62e commit db86753
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 0 additions & 1 deletion Sources/Charcoal/CharcoalViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ extension CharcoalViewController: FilterViewControllerDelegate {
guard !filter.subfilters.isEmpty else { break }

let gridViewController = GridFilterViewController(filter: filter, selectionStore: selectionStore)
gridViewController.showBottomButton(viewController.isShowingBottomButton, animated: false)

pushViewController(gridViewController)
case let .range(lowValueFilter, highValueFilter, filterConfig):
Expand Down
15 changes: 12 additions & 3 deletions Sources/Charcoal/Filters/Grid/GridFilterViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ final class GridFilterViewController: FilterViewController {
collectionView.allowsMultipleSelection = true
collectionView.dataSource = self
collectionView.delegate = self
collectionView.contentInset = UIEdgeInsets(top: .mediumLargeSpacing, left: edgeInset, bottom: 0, right: edgeInset)
collectionView.register(GridFilterCell.self)
return collectionView
}()

private let edgeInset: CGFloat = 27
private let filter: Filter

// MARK: - Init
Expand All @@ -34,6 +36,7 @@ final class GridFilterViewController: FilterViewController {
override func viewDidLoad() {
super.viewDidLoad()
bottomButton.buttonTitle = "applyButton".localized()
showBottomButton(false, animated: false)
setup()
}

Expand All @@ -49,8 +52,14 @@ final class GridFilterViewController: FilterViewController {
// MARK: - Setup

private func setup() {
view.addSubview(collectionView)
collectionView.fillInSuperview(insets: UIEdgeInsets(top: .mediumLargeSpacing, left: 27, bottom: 0, right: -27))
view.insertSubview(collectionView, belowSubview: bottomButton)

NSLayoutConstraint.activate([
collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
collectionView.topAnchor.constraint(equalTo: view.topAnchor),
collectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
collectionView.bottomAnchor.constraint(equalTo: bottomButton.topAnchor),
])
}
}

Expand All @@ -76,7 +85,7 @@ extension GridFilterViewController: UICollectionViewDelegateFlowLayout {
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAt indexPath: IndexPath) -> CGSize {
let numberOfItemsPerRow: CGFloat = 5
let side = (collectionView.frame.width / numberOfItemsPerRow) - .mediumSpacing
let side = ((collectionView.frame.width - edgeInset * 2) / numberOfItemsPerRow) - .mediumSpacing

return CGSize(width: side, height: side)
}
Expand Down

0 comments on commit db86753

Please sign in to comment.