-
Notifications
You must be signed in to change notification settings - Fork 379
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
Changes from 2 commits
f85875f
8506475
00bed42
b9f271e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,21 +31,22 @@ class ViewController: UIViewController { | |
imagePicker.settings.selection.max = 5 | ||
imagePicker.settings.theme.selectionStyle = .numbered | ||
imagePicker.settings.fetch.assets.supportedMediaTypes = [.image, .video] | ||
imagePicker.settings.selection.unselectOnReachingMax = true | ||
|
||
// imagePicker.settings.selection.unselectOnReachingMax = true | ||
imagePicker.settings.selection.notifyReachingMaxLimit=true; | ||
let start = Date() | ||
self.presentImagePicker(imagePicker, select: { (asset) in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most of the changes here seem to be whitespace/indentation? Don't commit stuff like that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resolved |
||
print("Selected: \(asset)") | ||
}, deselect: { (asset) in | ||
print("Deselected: \(asset)") | ||
}, cancel: { (assets) in | ||
print("Canceled with selections: \(assets)") | ||
}, finish: { (assets) in | ||
print("Finished with selections: \(assets)") | ||
}, completion: { | ||
self.presentImagePicker(imagePicker, select: { (asset) in | ||
print("Selected: \(asset)") | ||
}, deselect: { (asset) in | ||
print("Deselected: \(asset)") | ||
}, cancel: { (assets) in | ||
print("Canceled with selections: \(assets)") | ||
}, finish: { (assets) in | ||
let finish = Date() | ||
print(finish.timeIntervalSince(start)) | ||
}) | ||
print(finish.timeIntervalSince(start)) | ||
},completion: { | ||
let finish = Date() | ||
print(finish.timeIntervalSince(start)) | ||
}) | ||
} | ||
|
||
@IBAction func showCustomImagePicker(_ sender: UIButton) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,11 @@ extension ImagePickerController: AssetsViewControllerDelegate { | |
imagePickerDelegate?.imagePicker(self, didDeselectAsset: first) | ||
} | ||
} | ||
else if settings.selection.notifyReachingMaxLimit && assetStore.count > settings.selection.max { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic here seems wrong. Firstly it should probably be an if instead of an else if as a user can have both notify and unselect set to true. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed else if to if. |
||
assetStore.remove(asset) | ||
assetsViewController.unselect(asset:asset) | ||
imagePickerDelegate?.imagePicker(self, didReachSelectionLimit: settings.selection.max) | ||
} | ||
updatedDoneButton() | ||
imagePickerDelegate?.imagePicker(self, didSelectAsset: asset) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,14 +37,13 @@ import Photos | |
/// - cancel: Cancel callback | ||
/// - finish: Finish callback | ||
/// - completion: Presentation completion callback | ||
public func presentImagePicker(_ imagePicker: ImagePickerController, animated: Bool = true, select: ((_ asset: PHAsset) -> Void)?, deselect: ((_ asset: PHAsset) -> Void)?, cancel: (([PHAsset]) -> Void)?, finish: (([PHAsset]) -> Void)?, completion: (() -> Void)? = nil) { | ||
public func presentImagePicker(_ imagePicker: ImagePickerController, animated: Bool = true, select: ((_ asset: PHAsset) -> Void)?, deselect: ((_ asset: PHAsset) -> Void)?, cancel: (([PHAsset]) -> Void)?, finish: (([PHAsset]) -> Void)?,completion: (() -> Void)? = nil) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't commit whitespace/indentation changes. The log will be horrible if every committer does that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resolved |
||
authorize { | ||
// Set closures | ||
imagePicker.onSelection = select | ||
imagePicker.onDeselection = deselect | ||
imagePicker.onCancel = cancel | ||
imagePicker.onFinish = finish | ||
|
||
// And since we are using the blocks api. Set ourselfs as delegate | ||
imagePicker.imagePickerDelegate = imagePicker | ||
|
||
|
@@ -64,6 +63,7 @@ import Photos | |
} | ||
} | ||
} | ||
//selectionLimitReach: ((_ count:Int) -> Void)?, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resolved |
||
|
||
extension ImagePickerController { | ||
public static var currentAuthorization : PHAuthorizationStatus { | ||
|
@@ -90,6 +90,6 @@ extension ImagePickerController: ImagePickerControllerDelegate { | |
} | ||
|
||
public func imagePicker(_ imagePicker: ImagePickerController, didReachSelectionLimit count: Int) { | ||
|
||
onReachMaxSelectionLimit?(count) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove what? |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove what? |
||
let assetsViewController: AssetsViewController | ||
let albumsViewController = AlbumsViewController() | ||
let dropdownTransitionDelegate = DropdownTransitionDelegate() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 notifyReachingMaxLimit : Bool = false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To follow the naming of the previous property...maybe change to notifyOnReachingMax There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resolved |
||
} | ||
|
||
public class List : NSObject { | ||
|
@@ -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 | ||
}() | ||
|
@@ -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. | ||
|
@@ -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 { | ||
|
@@ -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() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't comment out code. Maybe create a new example that uses the delegate instead of closures.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved