Skip to content

Commit

Permalink
Merge pull request #11 from carousell/feature/custom-edit-done-barbutton
Browse files Browse the repository at this point in the history
Add optional customizable cancelBarButtonItem and doneBarButtonItem
  • Loading branch information
jianyaoang authored Jul 18, 2017
2 parents c23be50 + b7d16ae commit eeaa686
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
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)

// 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 }

// 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

0 comments on commit eeaa686

Please sign in to comment.