Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
tilltue committed Nov 6, 2017
1 parent bcabce0 commit da71ba1
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions TLPhotoPicker/Classes/TLPhotosPickerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public struct TLPhotosPickerConfigure {
public var videoIcon = TLBundle.podBundleImage(named: "video")
public var placeholderIcon = TLBundle.podBundleImage(named: "insertPhotoMaterial")
public var nibSet: (nibName: String, bundle:Bundle)? = nil
public var cameraCellNibSet: (nibName: String, bundle:Bundle)? = nil
public init() {

}
Expand All @@ -56,7 +57,7 @@ public struct TLPhotosPickerConfigure {

public struct Platform {

static var isSimulator: Bool {
public static var isSimulator: Bool {
return TARGET_OS_SIMULATOR != 0 // Use this line in Xcode 7 or newer
}

Expand Down Expand Up @@ -222,6 +223,9 @@ extension TLPhotosPickerViewController {
if let nibSet = self.configure.nibSet {
registerNib(nibName: nibSet.nibName, bundle: nibSet.bundle)
}
if let nibSet = self.configure.cameraCellNibSet {
registerNib(nibName: nibSet.nibName, bundle: nibSet.bundle)
}
self.indicator.startAnimating()
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(titleTap))
self.titleView.addGestureRecognizer(tapGesture)
Expand Down Expand Up @@ -615,17 +619,21 @@ extension TLPhotosPickerViewController: UICollectionViewDelegate,UICollectionVie

//Delegate
open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
guard let collection = self.focusedCollection else { return }
guard let collection = self.focusedCollection, let cell = self.collectionView.cellForItem(at: indexPath) as? TLPhotoCollectionViewCell else { return }
if collection.useCameraButton && indexPath.row == 0 {
if Platform.isSimulator {
print("not supported by the simulator.")
return
}else {
showCamera()
if let nibName = self.configure.cameraCellNibSet?.nibName {
cell.selectedCell()
}else {
showCamera()
}
return
}
}
guard var asset = collection.getTLAsset(at: indexPath.row), let cell = self.collectionView.cellForItem(at: indexPath) as? TLPhotoCollectionViewCell else { return }
guard var asset = collection.getTLAsset(at: indexPath.row) else { return }
cell.popScaleAnim()
if let index = self.selectedAssets.index(where: { $0.phAsset == asset.phAsset }) {
//deselect
Expand Down Expand Up @@ -656,9 +664,12 @@ extension TLPhotosPickerViewController: UICollectionViewDelegate,UICollectionVie
}

open func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
if indexPath == self.playRequestId?.indexPath, let cell = cell as? TLPhotoCollectionViewCell {
self.playRequestId = nil
cell.stopPlay()
if let cell = cell as? TLPhotoCollectionViewCell {
cell.endDisplayingCell()
if indexPath == self.playRequestId?.indexPath {
self.playRequestId = nil
cell.stopPlay()
}
}
guard let requestId = self.requestIds[indexPath] else { return }
self.requestIds.removeValue(forKey: indexPath)
Expand All @@ -667,14 +678,23 @@ extension TLPhotosPickerViewController: UICollectionViewDelegate,UICollectionVie

//Datasource
open func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
func makeCell(nibName: String) -> TLPhotoCollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: nibName, for: indexPath) as! TLPhotoCollectionViewCell
cell.configure = self.configure
cell.imageView?.image = self.placeholderThumbnail
return cell
}
let nibName = self.configure.nibSet?.nibName ?? "TLPhotoCollectionViewCell"
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: nibName, for: indexPath) as! TLPhotoCollectionViewCell
cell.configure = self.configure
cell.imageView?.image = self.placeholderThumbnail
var cell = makeCell(nibName: nibName)
guard let collection = self.focusedCollection else { return cell }
cell.isCameraCell = collection.useCameraButton && indexPath.row == 0
if cell.isCameraCell {
cell.imageView?.image = self.cameraImage
if let nibName = self.configure.cameraCellNibSet?.nibName {
cell = makeCell(nibName: nibName)
}else{
cell.imageView?.image = self.cameraImage
}
cell.willDisplayCell()
return cell
}
guard let asset = collection.getTLAsset(at: indexPath.row) else { return cell }
Expand Down

0 comments on commit da71ba1

Please sign in to comment.