From 0cdcae6b9fdd1803c37f2cc91ee1caf7153bb394 Mon Sep 17 00:00:00 2001 From: wade-hawk Date: Fri, 1 Nov 2019 00:12:37 +0900 Subject: [PATCH] Bug fixed #229, #231 --- TLPhotoPicker.podspec | 2 +- TLPhotoPicker/Classes/TLAssetsCollection.swift | 12 ++++++++++++ .../Classes/TLPhotosPickerViewController.swift | 13 ++++++++++--- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/TLPhotoPicker.podspec b/TLPhotoPicker.podspec index 7dfd05a3..559107c8 100644 --- a/TLPhotoPicker.podspec +++ b/TLPhotoPicker.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'TLPhotoPicker' - s.version = '2.0.4' + s.version = '2.0.6' s.summary = 'multiple phassets picker for iOS lib. like facebook' # This description is used to generate tags and improve search results. diff --git a/TLPhotoPicker/Classes/TLAssetsCollection.swift b/TLPhotoPicker/Classes/TLAssetsCollection.swift index f856740c..efb6e72e 100644 --- a/TLPhotoPicker/Classes/TLAssetsCollection.swift +++ b/TLPhotoPicker/Classes/TLAssetsCollection.swift @@ -389,6 +389,18 @@ public struct TLAssetsCollection { } } + func findIndex(phAsset: PHAsset) -> IndexPath? { + guard let sections = self.sections else { + return nil + } + for (offset, section) in sections.enumerated() { + if let index = section.assets.firstIndex(where: { $0.phAsset == phAsset }) { + return IndexPath(row: index, section: offset) + } + } + return nil + } + mutating func reloadSection(groupedBy: PHFetchedResultGroupedBy) { var groupedSections = self.section(groupedBy: groupedBy) if self.useCameraButton { diff --git a/TLPhotoPicker/Classes/TLPhotosPickerViewController.swift b/TLPhotoPicker/Classes/TLPhotosPickerViewController.swift index d4e32ca4..94280df4 100644 --- a/TLPhotoPicker/Classes/TLPhotosPickerViewController.swift +++ b/TLPhotoPicker/Classes/TLPhotosPickerViewController.swift @@ -287,6 +287,13 @@ open class TLPhotosPickerViewController: UIViewController { } private func findIndexAndReloadCells(phAsset: PHAsset) { + if + self.configure.groupByFetch != nil, + let indexPath = self.focusedCollection?.findIndex(phAsset: phAsset) + { + self.collectionView.reloadItems(at: [indexPath]) + return + } if var index = self.focusedCollection?.fetchResult?.index(of: phAsset), index != NSNotFound @@ -732,10 +739,10 @@ extension TLPhotosPickerViewController: PHLivePhotoViewDelegate { // MARK: - PHPhotoLibraryChangeObserver extension TLPhotosPickerViewController: PHPhotoLibraryChangeObserver { public func photoLibraryDidChange(_ changeInstance: PHChange) { - guard getfocusedIndex() == 0 else { - return + var addIndex = 0 + if getfocusedIndex() == 0 { + addIndex = self.usedCameraButton ? 1 : 0 } - let addIndex = self.usedCameraButton ? 1 : 0 DispatchQueue.main.async { guard let changeFetchResult = self.focusedCollection?.fetchResult else { return } guard let changes = changeInstance.changeDetails(for: changeFetchResult) else { return }