         super.viewWillTransition(to: size, with: coordinator)
         coordinator.animate(alongsideTransition: { _ in
             self.collectionView.collectionViewLayout.invalidateLayout()
-            self.updateLayout()
+            self.calculateSizes()
         })
     }
 
-    private func updateLayout(countOfColumns: Int = 4) {
-        flowLayout.scrollDirection = .horizontal
-        flowLayout.minimumInteritemSpacing = 0
-        flowLayout.sectionInset = .zero
-        flowLayout.minimumLineSpacing = 0
-        let countOfColumns = CGFloat(countOfColumns)
+    private var countOfColumns: CGFloat = 4 {
+        didSet {
+            calculateSizes()
+        }
+    }
+
+    private var columnWidth: CGFloat {
         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.itemSize = CGSize(width: dimension, height: collectionViewHeightConstraint.constant)
+        return floor(availableWidth / countOfColumns)
     }
 
     private var flowLayout: UICollectionViewFlowLayout {
         return collectionView.collectionViewLayout as! UICollectionViewFlowLayout
+    }
+
+    private lazy var placeholderCell = PageHistoryFilterCountCollectionViewCell.wmf_viewFromClassNib()!
+
+    private func calculateSizes() {
+        var height = collectionViewHeightConstraint.constant
+        for (index, count) in counts.enumerated() {
+            let size = placeholderCell.sizeWith(width: columnWidth, title: count.title, image: count.image, imageText: displayCount(count.count), isRightSeparatorHidden: index == counts.count - 1)
+            height = max(height, size.height)
+        }
+        collectionViewHeightConstraint.constant = height
+        flowLayout.itemSize = CGSize(width: columnWidth, height: height)
     }
 }
 

        super.viewDidLoad()
        collectionView.dataSource = self
        collectionView.register(UINib(nibName: "PageHistoryFilterCountCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: PageHistoryFilterCountCollectionViewCell.identifier)

        collectionViewHeightConstraint.isActive = true

        view.wmf_addSubviewWithConstraintsToEdges(collectionView)
        addActivityIndicator()
        activityIndicator.style = theme.isDark ? .white : .gray
        activityIndicator.startAnimating()
        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: "m")!, count: minorEdits))
            }
            countOfColumns = CGFloat(counts.count)
            delegate?.didDetermineFilterCountsAvailability(!counts.isEmpty, viewController: self)
        }
    }
