diff --git a/CHANGELOG.md b/CHANGELOG.md index aa77942..2ce778f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Example/Pickle/CarousellImagePickerController.swift b/Example/Pickle/CarousellImagePickerController.swift index 1d9f902..f2fb4bf 100644 --- a/Example/Pickle/CarousellImagePickerController.swift +++ b/Example/Pickle/CarousellImagePickerController.swift @@ -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 diff --git a/Pickle/Classes/ImagePickerConfigurable.swift b/Pickle/Classes/ImagePickerConfigurable.swift index 06fbd84..2385626 100644 --- a/Pickle/Classes/ImagePickerConfigurable.swift +++ b/Pickle/Classes/ImagePickerConfigurable.swift @@ -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. diff --git a/Pickle/Classes/ImagePickerController.swift b/Pickle/Classes/ImagePickerController.swift index 80a96a2..36ecfda 100644 --- a/Pickle/Classes/ImagePickerController.swift +++ b/Pickle/Classes/ImagePickerController.swift @@ -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