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

Add optional customizable cancelBarButtonItem and doneBarButtonItem #11

Merged
merged 2 commits into from
Jul 18, 2017
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Add a configuration for the photo albums navigation bar shadow color [#9](https://github.com/carousell/pickle/pull/9)
* Fix the photo albums layout after device rotation [#9](https://github.com/carousell/pickle/pull/9)
* UI tests [#10](https://github.com/carousell/pickle/pull/10)
* Add customizable cancelBarButonItem and doneBarButtonItem [#11](https://github.com/carousell/pickle/pull/11)

## v1.0.0

Expand Down
4 changes: 4 additions & 0 deletions Example/Pickle/CarousellImagePickerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ internal class CarousellImagePickerController: ImagePickerController {

private struct CarousellTheme: ImagePickerConfigurable {

let cancelBarButtonItem: UIBarButtonItem? = UIBarButtonItem(barButtonSystemItem: .stop, target: nil, action: nil)

let doneBarButtonItem: UIBarButtonItem? = UIBarButtonItem(title: "Next", style: .plain, target: nil, action: nil)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be better to use NSLocalizedString like imagePicker.button.camera? so we can later update the translation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just noticed that it's for the example app. It should be alright. 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍


// MARK: - Navigation Bar

let navigationBarStyle: UIBarStyle? = .blackTranslucent
Expand Down
8 changes: 8 additions & 0 deletions Pickle/Classes/ImagePickerConfigurable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ import UIKit
/// The ImagePickerConfigurable protocol defines the customizable properties of ImagePickerController.
public protocol ImagePickerConfigurable {

// MARK: - UINavigationItem

/// A custom bar button item displayed on the left (or leading) edge of the navigation bar when the receiver is the top navigation item.
var cancelBarButtonItem: UIBarButtonItem? { get }

/// A custom bar button item displayed on the right (or trailing) edge of the navigation bar when the receiver is the top navigation item.
var doneBarButtonItem: UIBarButtonItem? { get }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Documented++


// MARK: - Navigation Bar

/// The navigation bar style that specifies its appearance.
Expand Down
12 changes: 12 additions & 0 deletions Pickle/Classes/ImagePickerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ open class ImagePickerController: UINavigationController {

super.init(nibName: nil, bundle: nil)

if let cancelBarButtonItem = configuration?.cancelBarButtonItem {
cancelBarButtonItem.target = self
cancelBarButtonItem.action = #selector(cancel(_:))
self.cancelBarButton = cancelBarButtonItem
}

if let doneBarButtonItem = configuration?.doneBarButtonItem {
doneBarButtonItem.target = self
doneBarButtonItem.action = #selector(done(_:))
self.doneBarButton = doneBarButtonItem
}

camera = { [weak self] in
let camera = initializer()
camera.sourceType = .camera
Expand Down