Skip to content

Commit

Permalink
Bug fixed #229, #231
Browse files Browse the repository at this point in the history
  • Loading branch information
wade-hawk committed Oct 31, 2019
1 parent e1ea38e commit 0cdcae6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion TLPhotoPicker.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions TLPhotoPicker/Classes/TLAssetsCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 10 additions & 3 deletions TLPhotoPicker/Classes/TLPhotosPickerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }
Expand Down

0 comments on commit 0cdcae6

Please sign in to comment.