Skip to content

Commit

Permalink
Added Storyboard support. Some other improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
CocoaBob committed May 31, 2018
1 parent 196d575 commit 75ab30e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion TLPhotoPicker/Classes/TLAssetsCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public struct TLAssetsCollection {
func getTLAsset(at index: Int) -> TLPHAsset? {
if self.useCameraButton && index == 0 { return nil }
let index = index - (self.useCameraButton ? 1 : 0)
if let assets = self.customAssets {
if let assets = self.customAssets, index < assets.count {
return assets[index]
} else {
guard let result = self.fetchResult, index < result.count else { return nil }
Expand Down
21 changes: 19 additions & 2 deletions TLPhotoPicker/Classes/TLPhotosPickerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,18 @@ open class TLPhotosPickerViewController: UIViewController {
fileprivate var didCancel: (() -> Void)? = nil

fileprivate var collections = [TLAssetsCollection]()
fileprivate var customCollection: TLAssetsCollection? = nil
open var customCollection: TLAssetsCollection? = nil {
didSet {
if let oldValue = oldValue,
let index = collections.index(where: { $0.customAssets != nil }) {
collections.remove(at: index)
}
if let newValue = customCollection {
collections.insert(newValue, at: 0)
focusCollection(collection: newValue)
}
}
}
fileprivate var focusedCollection: TLAssetsCollection? = nil
fileprivate var requestIds = [IndexPath:PHImageRequestID]()
fileprivate var cloudRequestIds = [IndexPath:PHImageRequestID]()
Expand All @@ -149,7 +160,12 @@ open class TLPhotosPickerViewController: UIViewController {
}

required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
super.init(coder: aDecoder)
if PHPhotoLibrary.authorizationStatus() != .authorized {
PHPhotoLibrary.requestAuthorization { [weak self] status in
self?.initPhotoLibrary()
}
}
}

public init() {
Expand Down Expand Up @@ -486,6 +502,7 @@ extension TLPhotosPickerViewController: TLPhotoLibraryDelegate {
public func focusCollection(collection: TLAssetsCollection?) {
self.focusedCollection = collection
self.updateTitle()
self.reloadCollectionView()
}
}

Expand Down

0 comments on commit 75ab30e

Please sign in to comment.