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

SelectionLimitReach callback added with few important params now expo… #286

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Sources/Controller/ImagePickerController+Assets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ extension ImagePickerController: AssetsViewControllerDelegate {
imagePickerDelegate?.imagePicker(self, didDeselectAsset: first)
}
}
if settings.selection.notifyOnReachingMax && assetStore.count > settings.selection.max {
assetStore.remove(asset)
assetsViewController.unselect(asset:asset)
imagePickerDelegate?.imagePicker(self, didReachSelectionLimit: settings.selection.max)
}
updatedDoneButton()
imagePickerDelegate?.imagePicker(self, didSelectAsset: asset)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Controller/ImagePickerController+Closure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ extension ImagePickerController: ImagePickerControllerDelegate {
}

public func imagePicker(_ imagePicker: ImagePickerController, didReachSelectionLimit count: Int) {

onReachMaxSelectionLimit?(count)
}
}
2 changes: 1 addition & 1 deletion Sources/Controller/ImagePickerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import Photos
var onDeselection: ((_ asset: PHAsset) -> Void)?
var onCancel: ((_ assets: [PHAsset]) -> Void)?
var onFinish: ((_ assets: [PHAsset]) -> Void)?

var onReachMaxSelectionLimit: ((_ count: Int) -> Void)?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove what?

let assetsViewController: AssetsViewController
let albumsViewController = AlbumsViewController()
let dropdownTransitionDelegate = DropdownTransitionDelegate()
Expand Down
2 changes: 1 addition & 1 deletion Sources/Controller/ImagePickerControllerDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Foundation
import Photos

/// Delegate of the image picker
public protocol ImagePickerControllerDelegate: class {
@objc public protocol ImagePickerControllerDelegate: class {
/// An asset was selected
/// - Parameter imagePicker: The image picker that asset was selected in
/// - Parameter asset: selected asset
Expand Down
39 changes: 21 additions & 18 deletions Sources/Model/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,18 @@ import Photos
]
}

public class Selection : NSObject {
@objc public class Selection : NSObject {
/// Max number of selections allowed
public lazy var max: Int = Int.max
@objc public lazy var max: Int = Int.max

/// Min number of selections you have to make
public lazy var min: Int = 1
@objc public lazy var min: Int = 1

/// If it reaches the max limit, unselect the first selection, and allow the new selection
public lazy var unselectOnReachingMax : Bool = false
@objc public lazy var unselectOnReachingMax : Bool = false

/// If it reaches the max limit, notify
@objc public lazy var notifyOnReachingMax : Bool = false
}

public class List : NSObject {
Expand All @@ -100,10 +103,10 @@ import Photos
public lazy var enabled: Bool = true
}

public class Fetch : NSObject {
public class Album : NSObject {
@objc public class Fetch : NSObject {
@objc public class Album : NSObject {
/// Fetch options for albums/collections
public lazy var options: PHFetchOptions = {
@objc public lazy var options: PHFetchOptions = {
let fetchOptions = PHFetchOptions()
return fetchOptions
}()
Expand All @@ -115,12 +118,12 @@ import Photos
/// PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .smartAlbumSelfPortraits, options: options),
/// PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .smartAlbumPanoramas, options: options),
/// PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .smartAlbumVideos, options: options),
public lazy var fetchResults: [PHFetchResult<PHAssetCollection>] = [
@objc public lazy var fetchResults: [PHFetchResult<PHAssetCollection>] = [
PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .smartAlbumUserLibrary, options: options),
]
}

public class Assets : NSObject {
@objc public class Assets : NSObject {
/// Fetch options for assets

/// Simple wrapper around PHAssetMediaType to ensure we only expose the supported types.
Expand Down Expand Up @@ -175,13 +178,13 @@ import Photos
}

/// Album fetch settings
public lazy var album = Album()
@objc public lazy var album = Album()

/// Asset fetch settings
public lazy var assets = Assets()
@objc public lazy var assets = Assets()

/// Preview fetch settings
public lazy var preview = Preview()
@objc public lazy var preview = Preview()
}

public class Dismiss : NSObject {
Expand All @@ -193,20 +196,20 @@ import Photos
}

/// Theme settings
public lazy var theme = Theme()
@objc public lazy var theme = Theme()

/// Selection settings
public lazy var selection = Selection()
@objc public lazy var selection = Selection()

/// List settings
public lazy var list = List()
@objc public lazy var list = List()

/// Fetch settings
public lazy var fetch = Fetch()
@objc public lazy var fetch = Fetch()

/// Dismiss settings
public lazy var dismiss = Dismiss()
@objc public lazy var dismiss = Dismiss()

/// Preview options
public lazy var preview = Preview()
@objc public lazy var preview = Preview()
}
2 changes: 1 addition & 1 deletion Sources/Scene/Assets/AssetsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ extension AssetsViewController: UICollectionViewDelegate {
}

func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
guard store.count < settings.selection.max || settings.selection.unselectOnReachingMax else { return false }
guard store.count < settings.selection.max || settings.selection.unselectOnReachingMax || settings.selection.notifyOnReachingMax else { return false }
selectionFeedback.prepare()

return true
Expand Down