Fix image picker thumbnails being low resolution on first load

This commit is contained in:
Elaine 2023-12-22 12:13:27 -07:00 committed by GitHub
parent c507e53530
commit 8deab3f5ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 5 deletions

View File

@ -215,7 +215,12 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat
// Determine the size of the thumbnails to request
let scale = UIScreen.main.scale
let cellSize = collectionViewFlowLayout.itemSize
let cellSize: CGSize
if hasEverAppeared {
cellSize = collectionViewFlowLayout.itemSize
} else {
cellSize = getLayout().itemSize
}
photoMediaSize.thumbnailSize = CGSize(width: cellSize.width * scale, height: cellSize.height * scale)
reloadData()
@ -334,7 +339,9 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat
return layout
}
private func updateLayout() {
private typealias CellLayout = (itemSize: CGSize, remainingSpace: CGFloat)
private func getLayout() -> CellLayout {
let containerWidth = self.view.safeAreaLayoutGuide.layoutFrame.size.width
let minItemWidth: CGFloat = 100
@ -344,9 +351,14 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat
let availableWidth = max(0, containerWidth - interSpaceWidth)
let itemWidth = floor(availableWidth / CGFloat(itemCount))
let newItemSize = CGSize(square: itemWidth)
let itemSize = CGSize(square: itemWidth)
let remainingSpace = availableWidth - (itemCount * itemWidth)
return (itemSize, remainingSpace)
}
private func updateLayout() {
let (newItemSize, remainingSpace) = getLayout()
if newItemSize != collectionViewFlowLayout.itemSize {
collectionViewFlowLayout.itemSize = newItemSize
// Inset any remaining space around the outside edges to ensure all inter-item spacing is exactly equal, otherwise

View File

@ -89,11 +89,12 @@ class PhotoAlbumPickerViewController: OWSTableViewController, OWSNavigationChild
cell.backgroundColor = Theme.darkThemeBackgroundColor
cell.selectedBackgroundView?.backgroundColor = UIColor(white: 0.2, alpha: 1)
let scale = UIScreen.main.scale
let kImageSize: CGFloat = 80
let folderImageSpacing: CGFloat = 1
let folderImageSize = (kImageSize - folderImageSpacing) / 2
let photoMediaSize = PhotoMediaSize(thumbnailSize: CGSize(square: kImageSize))
let folderMediaSize = PhotoMediaSize(thumbnailSize: CGSize(square: folderImageSize))
let photoMediaSize = PhotoMediaSize(thumbnailSize: CGSize(square: kImageSize * scale))
let folderMediaSize = PhotoMediaSize(thumbnailSize: CGSize(square: folderImageSize * scale))
let contentCount: Int
var assetItem: PhotoPickerAssetItem?