Skip to content

Commit

Permalink
Merge pull request #150 from nohana/hotfix_out_of_index_after_added_s…
Browse files Browse the repository at this point in the history
…election_photos

Fixed an `out of index issue` after adding selection photos.
  • Loading branch information
Noodlekim authored Aug 18, 2022
2 parents a3b693c + 40289ad commit b3e0281
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo
}

private let nohanaImagePickerController: NohanaImagePickerController
let photoKitAssetList: PhotoKitAssetList
private var photoKitAssetList: PhotoKitAssetList
var dateSectionList: [AssetDateSection] = []

var cellSize: CGSize {
Expand Down Expand Up @@ -299,10 +299,11 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo
assetListDetailCurrentRow += dateSectionList[section].assetResult.count
}
}

if assetListDetailCurrentRow >= photoKitAssetList.count {
assetListDetailCurrentRow = photoKitAssetList.count - 1
}

let assetListDetailViewController = segue.destination as! AssetDetailListViewController
assetListDetailViewController.currentIndexPath = IndexPath(item: assetListDetailCurrentRow, section: 0)
}
Expand Down Expand Up @@ -377,6 +378,7 @@ extension AssetListSelectableDateSectionController: PHPhotoLibraryChangeObserver
func photoLibraryDidChange(_ changeInstance: PHChange) {
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
self.photoKitAssetList = PhotoKitAssetList(album: self.photoKitAssetList.assetList, mediaType: self.photoKitAssetList.mediaType, ascending: false)
self.dateSectionList = AssetDateSectionCreater().createSections(assetList: self.photoKitAssetList.assetList, options: PhotoKitAssetList.fetchOptions(self.photoKitAssetList.mediaType, ascending: false))
self.isLoading = false
self.collectionView?.reloadData()
Expand Down

0 comments on commit b3e0281

Please sign in to comment.