Fix albums in asset picker not being sorted by name
This commit is contained in:
parent
88cfbfb1f3
commit
bab5226f2a
|
@ -52,11 +52,13 @@ class AssetCollectionsListViewController: UITableViewController {
|
|||
let smartAlbums = PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .any, options: nil)
|
||||
var smartAlbumItems = [Item]()
|
||||
smartAlbums.enumerateObjects { (collection, _, _) in
|
||||
guard collection.assetCollectionSubtype != .smartAlbumAllHidden && collection.assetCollectionSubtype != .smartAlbumRecentlyAdded else {
|
||||
guard collection.assetCollectionSubtype != .smartAlbumAllHidden else {
|
||||
return
|
||||
}
|
||||
smartAlbumItems.append(.album(collection))
|
||||
}
|
||||
// sort these manually, using PHFetchOptions.sortDescriptors seems like it just doesn't work with fetchAssetCollections
|
||||
smartAlbumItems.sort(by: { $0.title < $1.title })
|
||||
snapshot.appendItems(smartAlbumItems, toSection: .smartAlbums)
|
||||
|
||||
let albums = PHAssetCollection.fetchAssetCollections(with: .album, subtype: .any, options: nil)
|
||||
|
@ -71,11 +73,12 @@ class AssetCollectionsListViewController: UITableViewController {
|
|||
}
|
||||
}
|
||||
}
|
||||
albumItems.sort(by: { $0.title < $1.title })
|
||||
sharedItems.sort(by: { $0.title < $1.title })
|
||||
snapshot.appendItems(albumItems, toSection: .albums)
|
||||
snapshot.appendItems(sharedItems, toSection: .sharedAlbums)
|
||||
|
||||
dataSource.apply(snapshot, animatingDifferences: false)
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Table view delegate
|
||||
|
@ -125,6 +128,15 @@ extension AssetCollectionsListViewController {
|
|||
hasher.combine(collection.localIdentifier)
|
||||
}
|
||||
}
|
||||
|
||||
var title: String {
|
||||
switch self {
|
||||
case .cameraRoll:
|
||||
return "All Photos"
|
||||
case .album(let collection):
|
||||
return collection.localizedTitle ?? ""
|
||||
}
|
||||
}
|
||||
}
|
||||
class DataSource: UITableViewDiffableDataSource<Section, Item> {
|
||||
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
||||
|
|
Loading…
Reference in New Issue