 import UIKit
 
+fileprivate class FlowLayout: UICollectionViewFlowLayout {
+    private var oldBoundsWidth: CGFloat = 0
+
+    override init() {
+        super.init()
+        minimumInteritemSpacing = 8
+        minimumLineSpacing = 8
+    }
+
+    required init?(coder aDecoder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+
+    override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool {
+        defer {
+            oldBoundsWidth = newBounds.width
+        }
+        return super.shouldInvalidateLayout(forBoundsChange: newBounds) || newBounds.width != oldBoundsWidth
+    }
+
+    override func invalidateLayout(with context: UICollectionViewLayoutInvalidationContext) {
+        defer {
+            super.invalidateLayout(with: context)
+        }
+
+        guard let collectionView = collectionView else {
+            return
+        }
+
+        let dimension = (collectionView.bounds.width / 3) - minimumInteritemSpacing * 2
+        itemSize = CGSize(width: dimension, height: dimension)
+    }
+}
+
 class InsertMediaSearchResultsCollectionViewController: UICollectionViewController {
-    private let flowLayout: UICollectionViewFlowLayout
+    private let flowLayout: FlowLayout
     private var theme = Theme.standard
     private let itemDimension: CGFloat = 100
 

    }

    init() {
        flowLayout = UICollectionViewFlowLayout()
        super.init(collectionViewLayout: flowLayout)
        title = CommonStrings.searchTitle
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        collectionView.register(InsertMediaSearchResultCollectionViewCell.self, forCellWithReuseIdentifier: InsertMediaSearchResultCollectionViewCell.identifier)
        // TODO: Make this VC a ViewController so that it can work with the nav bar
        collectionView.contentInset = UIEdgeInsets(top: 120, left: 12, bottom: 0, right: 12)
        apply(theme: theme)
    }

    func reload() {
