         guard let layout = collectionViewLayout as? UICollectionViewFlowLayout else {
             return CGSize.zero
         }
-        
+
+        var collectionViewWidth = collectionView.bounds.width
+
+        if #available(iOS 11.0, *) {
+            let insets = collectionView.safeAreaInsets
+            collectionViewWidth -= (insets.left + insets.right)
+        }
+
         let sectionInsets = layout.sectionInset
         let minimumInteritemSpacing = layout.minimumInteritemSpacing
         
-        let remainingWidth = collectionView.bounds.width
+        let remainingWidth = collectionViewWidth
             - sectionInsets.left
             - CGFloat((numberOfColumns - 1)) * minimumInteritemSpacing
             - sectionInsets.right

            layout.sectionInset = UIEdgeInsets.zero
            layout.minimumInteritemSpacing = 1.0
            layout.minimumLineSpacing = 1.0
        }
    }
    

    }

    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        return collectionView.dequeueReusableCell(
            withReuseIdentifier: FlickrCameraRollCollectionViewCell.reuseIdentifier,
            for: indexPath
        )
    }

    override func collectionView(_ collectionView: UICollectionView,
                                 willDisplay cell: UICollectionViewCell,
                                 forItemAt indexPath: IndexPath) {
        configure(cell: cell as! FlickrCameraRollCollectionViewCell, at: indexPath)
    }

    // MARK: Private Helpers
