Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for having non-square previews + make selectCameraCell open to allow for opening custom camera without needing a custom cell #335

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
44 changes: 30 additions & 14 deletions TLPhotoPicker/Classes/TLPhotosPickerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ public struct TLPhotosPickerConfigure {
public var numberOfColumn = 3
public var minimumLineSpacing: CGFloat = 5
public var minimumInteritemSpacing: CGFloat = 5
public var contentInset: UIEdgeInsets = .zero
public var singleSelectedMode = false
public var maxSelectedAssets: Int? = nil
public var cellHeightWidthAspectRatio: CGFloat = 1
public var backgroundColor: UIColor? = nil
public var collectionViewBackgroundColor: UIColor? = nil
public var fetchOption: PHFetchOptions? = nil
public var fetchCollectionOption: [FetchCollectionType: PHFetchOptions] = [:]
public var selectedColor = UIColor(red: 88/255, green: 144/255, blue: 255/255, alpha: 1.0)
Expand Down Expand Up @@ -256,6 +260,14 @@ open class TLPhotosPickerViewController: UIViewController {
self.view.backgroundColor = .white
self.collectionView.backgroundColor = .white
}
if let bgColor = self.configure.backgroundColor {
print("\n\n\n\n\n!!!!!!!!!!!!!!!!SETTING BG COLOR!!!!!!!!!!!!!!!!!!!!\n\n\n\n\n")
self.view.backgroundColor = bgColor
self.navigationBar.backgroundColor = bgColor
}
if let collectionBGColor = self.configure.collectionViewBackgroundColor {
self.view.backgroundColor = collectionBGColor
}
}
}

Expand Down Expand Up @@ -359,6 +371,19 @@ open class TLPhotosPickerViewController: UIViewController {
}
}

open func selectCameraCell(_ cell: TLPhotoCollectionViewCell) {
if Platform.isSimulator {
print("not supported by the simulator.")
} else {
if configure.cameraCellNibSet?.nibName != nil {
cell.selectedCell()
} else {
showCameraIfAuthorized()
}
logDelegate?.selectedCameraCell(picker: self)
}
}

open func maxCheck() -> Bool {
deselectWhenUsingSingleSelectedMode()
if let max = self.configure.maxSelectedAssets, max <= self.selectedAssets.count {
Expand Down Expand Up @@ -393,8 +418,10 @@ extension TLPhotosPickerViewController {
return
}
let count = CGFloat(self.configure.numberOfColumn)
let width = floor((self.view.frame.size.width - (self.configure.minimumInteritemSpacing * (count-1))) / count)
self.thumbnailSize = CGSize(width: width, height: width)
let workingWidth = self.view.frame.size.width - (self.collectionView.contentInset.left + self.collectionView.contentInset.right)
let width = floor((workingWidth - (self.configure.minimumInteritemSpacing * (count-1))) / count)
let height = self.configure.cellHeightWidthAspectRatio * width
self.thumbnailSize = CGSize(width: width, height: height)
layout.itemSize = self.thumbnailSize
layout.minimumInteritemSpacing = self.configure.minimumInteritemSpacing
layout.minimumLineSpacing = self.configure.minimumLineSpacing
Expand Down Expand Up @@ -438,6 +465,7 @@ extension TLPhotosPickerViewController {
} else {
self.allowedLivePhotos = false
}
self.collectionView.contentInset = self.configure.contentInset
self.customDataSouces?.registerSupplementView(collectionView: self.collectionView)
self.navigationBar.delegate = self
updateUserInterfaceStyle()
Expand Down Expand Up @@ -1263,18 +1291,6 @@ extension TLPhotosPickerViewController: UIViewControllerPreviewingDelegate {
}

extension TLPhotosPickerViewController {
func selectCameraCell(_ cell: TLPhotoCollectionViewCell) {
if Platform.isSimulator {
print("not supported by the simulator.")
} else {
if configure.cameraCellNibSet?.nibName != nil {
cell.selectedCell()
} else {
showCameraIfAuthorized()
}
logDelegate?.selectedCameraCell(picker: self)
}
}

func toggleSelection(for cell: TLPhotoCollectionViewCell, at indexPath: IndexPath) {
guard let collection = focusedCollection, var asset = collection.getTLAsset(at: indexPath), let phAsset = asset.phAsset else { return }
Expand Down