Skip to content

Commit

Permalink
Merge pull request #137 from nohana/release/0.9.9
Browse files Browse the repository at this point in the history
0.9.9
  • Loading branch information
a2444mo10 authored Feb 1, 2022
2 parents ce90ed0 + 8c5fe82 commit 4647c9a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 7 deletions.
33 changes: 33 additions & 0 deletions Demo/DemoListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class DemoListViewController: UITableViewController, NohanaImagePickerController
Cell(title: "Disable to pick assets", selector: #selector(DemoListViewController.showDisableToPickAssetsPicker)),
Cell(title: "Custom UI", selector: #selector(DemoListViewController.showCustomUIPicker)),
Cell(title: "Selectable Album Date Section", selector: #selector(DemoListViewController.showSelectableDateSectionPicker)),
Cell(title: "Specify the default album", selector: #selector(DemoListViewController.showSpecifyDefaultAlbumPicker)),
]

override func viewDidAppear(_ animated: Bool) {
Expand Down Expand Up @@ -145,6 +146,38 @@ class DemoListViewController: UITableViewController, NohanaImagePickerController
picker.delegate = self
present(picker, animated: true, completion: nil)
}

@objc func showSpecifyDefaultAlbumPicker() {
let subtypes: [PHAssetCollectionSubtype] = [
.albumRegular,
.albumSyncedEvent,
.albumSyncedFaces,
.albumSyncedAlbum,
.albumImported,
.albumMyPhotoStream,
.albumCloudShared,
.smartAlbumGeneric,
.smartAlbumFavorites,
.smartAlbumRecentlyAdded,
.smartAlbumUserLibrary
]
var albumListFetchResult: [PHFetchResult<PHAssetCollection>] = []
let assetCollectionTypes: [PHAssetCollectionType] = [.smartAlbum, .album]
assetCollectionTypes.forEach {
albumListFetchResult += [PHAssetCollection.fetchAssetCollections(with: $0, subtype: .any, options: nil)]
}
var assetCollections: [PHAssetCollection] = []
albumListFetchResult.forEach {
$0.enumerateObjects { (assetCollection, _, _) in
if subtypes.contains(assetCollection.assetCollectionSubtype) {
assetCollections.append(assetCollection)
}
}
}
let picker = NohanaImagePickerController(assetCollectionSubtypes: subtypes, mediaType: .photo, enableExpandingPhotoAnimation: false, defaultAssetCollection: assetCollections.last)
picker.delegate = self
present(picker, animated: true, completion: nil)
}

// MARK: - NohanaImagePickerControllerDelegate

Expand Down
18 changes: 13 additions & 5 deletions NohanaImagePicker/NohanaImagePickerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ open class NohanaImagePickerController: UIViewController {
let mediaType: MediaType
let enableExpandingPhotoAnimation: Bool
let assetCollectionSubtypes: [PHAssetCollectionSubtype]
let defaultAssetCollection: PHAssetCollection?

public init() {
assetCollectionSubtypes = [
Expand All @@ -86,14 +87,21 @@ open class NohanaImagePickerController: UIViewController {
mediaType = .photo
pickedAssetList = PickedAssetList()
enableExpandingPhotoAnimation = true
defaultAssetCollection = nil
super.init(nibName: nil, bundle: nil)
self.pickedAssetList.nohanaImagePickerController = self
}

public init(assetCollectionSubtypes: [PHAssetCollectionSubtype], mediaType: MediaType, enableExpandingPhotoAnimation: Bool) {
public init(assetCollectionSubtypes: [PHAssetCollectionSubtype], mediaType: MediaType, enableExpandingPhotoAnimation: Bool, defaultAssetCollection: PHAssetCollection?) {
self.assetCollectionSubtypes = assetCollectionSubtypes
self.mediaType = mediaType
self.enableExpandingPhotoAnimation = enableExpandingPhotoAnimation
self.defaultAssetCollection = defaultAssetCollection
if let assetCollection = self.defaultAssetCollection {
if !assetCollectionSubtypes.contains(assetCollection.assetCollectionSubtype) {
fatalError("defaultAssetCollection doesn't contain the specified PHAssetCollectionSubtype")
}
}
pickedAssetList = PickedAssetList()
super.init(nibName: nil, bundle: nil)
self.pickedAssetList.nohanaImagePickerController = self
Expand Down Expand Up @@ -138,10 +146,10 @@ open class NohanaImagePickerController: UIViewController {
addChild(navigationController)
view.addSubview(navigationController.view)
NSLayoutConstraint.activate([
navigationController.view.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor),
navigationController.view.leadingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.leadingAnchor),
navigationController.view.trailingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.trailingAnchor),
navigationController.view.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor),
navigationController.view.topAnchor.constraint(equalTo: view.topAnchor),
navigationController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
navigationController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor),
navigationController.view.bottomAnchor.constraint(equalTo: view.bottomAnchor),
])
navigationController.view.layoutIfNeeded()
navigationController.didMove(toParent: self)
Expand Down
16 changes: 14 additions & 2 deletions NohanaImagePicker/RootViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import UIKit
import Photos

class RootViewController: UIViewController {

Expand Down Expand Up @@ -53,7 +54,11 @@ class RootViewController: UIViewController {
// Notification
addPickPhotoKitAssetNotificationObservers()

showRecentPhotos()
if let assetCollection = nohanaImagePickerController.defaultAssetCollection {
showPhotosFromDefaultAlbum(album: assetCollection)
} else {
showRecentPhotos()
}
}

override func viewWillAppear(_ animated: Bool) {
Expand Down Expand Up @@ -117,6 +122,12 @@ class RootViewController: UIViewController {
present(navigationController, animated: true, completion: nil)
}

private func showPhotosFromDefaultAlbum(album: PHAssetCollection) {
let album = PhotoKitAssetList(album: album, mediaType: nohanaImagePickerController.mediaType, ascending: !nohanaImagePickerController.canPickDateSection)
switchChildViewController(currentChildViewController, toViewController: fetchAssetListViewController(album: album))
updateTitle(title: album.title)
}

private func showRecentPhotos() {
albumList = PhotoKitAlbumList(
assetCollectionTypes: [.smartAlbum, .album],
Expand All @@ -136,7 +147,7 @@ class RootViewController: UIViewController {
self.present(alert, animated: true, completion: nil)
return
}
self.switchChildViewController(nil, toViewController: self.fetchAssetListViewController(album: album))
self.switchChildViewController(self.currentChildViewController, toViewController: self.fetchAssetListViewController(album: album))
self.updateTitle(title: album.title)
}
})
Expand Down Expand Up @@ -186,6 +197,7 @@ class RootViewController: UIViewController {
oldViewController?.view.removeFromSuperview()
oldViewController?.removeFromParent()
newViewController.didMove(toParent: self)
currentChildViewController = newViewController
}

private func transformAnimation() {
Expand Down

0 comments on commit 4647c9a

Please sign in to comment.