         return NumberFormatter.localizedThousandsStringFromNumber(NSNumber(value: count))
     }
 
+    private lazy var collectionViewHeightConstraint = collectionView.heightAnchor.constraint(equalToConstant: 60)
+
     override func viewDidLoad() {
         super.viewDidLoad()
-
-        // TODO: Move out into separate types
         collectionView.dataSource = self
         collectionView.register(UINib(nibName: "PageHistoryFilterCountCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: PageHistoryFilterCountCollectionViewCell.identifier)
 
-        // TODO: Adjust height for the highest cell
-        let collectionViewHeightConstraint = collectionView.heightAnchor.constraint(equalToConstant: 60)
         collectionViewHeightConstraint.isActive = true
+
         view.wmf_addSubviewWithConstraintsToEdges(collectionView)
         addActivityIndicator()
         activityIndicator.style = theme.isDark ? .white : .gray
         activityIndicator.startAnimating()
-        updateLayout(collectionViewHeightConstraint.constant)
+        updateLayout()
         apply(theme: theme)
     }
 

            if case let minorEdits?? = editCounts[.minor] {
                counts.append(Count(title: WMFLocalizedString("page-history-minor-edits", value: "minor edits", comment: "Text for view that shows many edits were marked as minor edits"), image: UIImage(named: "reverted")!, count: minorEdits))
            }
            updateLayout(60, countOfColumns: counts.count)
            delegate?.didDetermineFilterCountsAvailability(!counts.isEmpty, viewController: self)
        }
    }

    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        super.viewWillTransition(to: size, with: coordinator)
        coordinator.animate(alongsideTransition: { _ in
            self.collectionView.collectionViewLayout.invalidateLayout()
            self.updateLayout()
        })
    }

    private func updateLayout(countOfColumns: Int = 4) {
        flowLayout.scrollDirection = .horizontal
        flowLayout.minimumInteritemSpacing = 0
        flowLayout.sectionInset = .zero
        flowLayout.minimumLineSpacing = 0
        let countOfColumns = CGFloat(countOfColumns)
        let availableWidth = collectionView.bounds.width - flowLayout.minimumInteritemSpacing * (countOfColumns - 1) - collectionView.contentInset.left - collectionView.contentInset.right - flowLayout.sectionInset.left - flowLayout.sectionInset.right
        let dimension = floor(availableWidth / countOfColumns)
        flowLayout.estimatedItemSize = CGSize(width: dimension, height: collectionViewHeightConstraint.constant)
    }

    private var flowLayout: UICollectionViewFlowLayout {
        return collectionView.collectionViewLayout as! UICollectionViewFlowLayout
    }
}

