From 56fc3eaccd1dd775e7253da54bf51252ac256960 Mon Sep 17 00:00:00 2001 From: Ramon Gilabert Date: Mon, 5 Oct 2015 11:03:38 +0200 Subject: [PATCH 1/5] Adds a shared instance --- Source/PickerConfiguration.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Source/PickerConfiguration.swift b/Source/PickerConfiguration.swift index ddb8ac07..0ce1ee45 100644 --- a/Source/PickerConfiguration.swift +++ b/Source/PickerConfiguration.swift @@ -1,6 +1,13 @@ import UIKit public class PickerConfiguration { + var configuration = ImagePickerConfiguration() + static let sharedInstance = PickerConfiguration() +} + +public struct ImagePickerConfiguration { + + public init() { } // MARK: Colors From 720c0eb4c388fda3bb7437b41b43a6b433768657 Mon Sep 17 00:00:00 2001 From: Ramon Gilabert Date: Mon, 5 Oct 2015 11:25:17 +0200 Subject: [PATCH 2/5] Changes to be pickerConfiguration as a struct --- Source/BottomView/BottomContainerView.swift | 12 ++++++------ Source/BottomView/ButtonPicker.swift | 4 ++-- Source/CameraView/CameraView.swift | 6 +++--- Source/ImageGallery/ImageGalleryView.swift | 12 ++++++------ Source/ImagePickerController.swift | 6 +++--- Source/TopView/TopView.swift | 4 ++-- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Source/BottomView/BottomContainerView.swift b/Source/BottomView/BottomContainerView.swift index 411cf3b8..e99cb747 100644 --- a/Source/BottomView/BottomContainerView.swift +++ b/Source/BottomView/BottomContainerView.swift @@ -30,8 +30,8 @@ class BottomContainerView: UIView { lazy var doneButton: UIButton = { [unowned self] in let button = UIButton() - button.setTitle(self.configuration.cancelButtonTitle, forState: .Normal) - button.titleLabel?.font = self.configuration.doneButton + button.setTitle(self.pickerConfiguration.configuration.cancelButtonTitle, forState: .Normal) + button.titleLabel?.font = self.pickerConfiguration.configuration.doneButton button.addTarget(self, action: "doneButtonDidPress:", forControlEvents: .TouchUpInside) return button @@ -42,14 +42,14 @@ class BottomContainerView: UIView { return view }() - lazy var configuration: PickerConfiguration = { + lazy var pickerConfiguration: PickerConfiguration = { let configuration = PickerConfiguration() return configuration }() lazy var topSeparator: UIView = { [unowned self] in let view = UIView() - view.backgroundColor = self.configuration.backgroundColor + view.backgroundColor = self.pickerConfiguration.configuration.backgroundColor return view }() @@ -74,7 +74,7 @@ class BottomContainerView: UIView { view.translatesAutoresizingMaskIntoConstraints = false } - backgroundColor = configuration.backgroundColor + backgroundColor = pickerConfiguration.configuration.backgroundColor stackView.addGestureRecognizer(tapGestureRecognizer) setupConstraints() @@ -87,7 +87,7 @@ class BottomContainerView: UIView { // MARK: - Action methods func doneButtonDidPress(button: UIButton) { - if button.currentTitle == configuration.cancelButtonTitle { + if button.currentTitle == pickerConfiguration.configuration.cancelButtonTitle { delegate?.cancelButtonDidPress() } else { delegate?.doneButtonDidPress() diff --git a/Source/BottomView/ButtonPicker.swift b/Source/BottomView/ButtonPicker.swift index e5b320dc..13ee2c7f 100644 --- a/Source/BottomView/ButtonPicker.swift +++ b/Source/BottomView/ButtonPicker.swift @@ -16,12 +16,12 @@ class ButtonPicker: UIButton { lazy var numberLabel: UILabel = { [unowned self] in let label = UILabel() label.translatesAutoresizingMaskIntoConstraints = false - label.font = self.configuration.numberLabelFont + label.font = self.pickerConfiguration.configuration.numberLabelFont return label }() - lazy var configuration: PickerConfiguration = { + lazy var pickerConfiguration: PickerConfiguration = { let configuration = PickerConfiguration() return configuration }() diff --git a/Source/CameraView/CameraView.swift b/Source/CameraView/CameraView.swift index ad9192d7..4c37adaa 100644 --- a/Source/CameraView/CameraView.swift +++ b/Source/CameraView/CameraView.swift @@ -10,7 +10,7 @@ protocol CameraViewDelegate: class { class CameraView: UIViewController { - lazy var configuration: PickerConfiguration = { + lazy var pickerConfiguration: PickerConfiguration = { let configuration = PickerConfiguration() return configuration }() @@ -64,8 +64,8 @@ class CameraView: UIViewController { initializeCamera() - view.backgroundColor = self.configuration.mainColor - previewLayer?.backgroundColor = self.configuration.mainColor.CGColor + view.backgroundColor = self.pickerConfiguration.configuration.mainColor + previewLayer?.backgroundColor = self.pickerConfiguration.configuration.mainColor.CGColor } // MARK: - Initialize camera diff --git a/Source/ImageGallery/ImageGalleryView.swift b/Source/ImageGallery/ImageGalleryView.swift index 3e05d425..a1dacebe 100644 --- a/Source/ImageGallery/ImageGalleryView.swift +++ b/Source/ImageGallery/ImageGalleryView.swift @@ -26,7 +26,7 @@ public class ImageGalleryView: UIView { let collectionView = UICollectionView(frame: CGRectMake(0, 0, 0, 0), collectionViewLayout: self.collectionViewLayout) collectionView.translatesAutoresizingMaskIntoConstraints = false - collectionView.backgroundColor = self.configuration.mainColor + collectionView.backgroundColor = self.pickerConfiguration.configuration.mainColor collectionView.showsHorizontalScrollIndicator = false collectionView.layer.anchorPoint = CGPointMake(0.5, 0.5) @@ -36,7 +36,7 @@ public class ImageGalleryView: UIView { lazy var collectionViewLayout: UICollectionViewLayout = { [unowned self] in let layout = UICollectionViewFlowLayout() layout.scrollDirection = .Horizontal - layout.minimumInteritemSpacing = self.configuration.cellSpacing + layout.minimumInteritemSpacing = self.pickerConfiguration.configuration.cellSpacing layout.minimumLineSpacing = 2 layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0) @@ -75,16 +75,16 @@ public class ImageGalleryView: UIView { return images }() - lazy var configuration: PickerConfiguration = { + lazy var pickerConfiguration: PickerConfiguration = { let configuration = PickerConfiguration() return configuration }() lazy var noImagesLabel: UILabel = { [unowned self] in let label = UILabel() - label.font = self.configuration.noImagesFont - label.textColor = self.configuration.noImagesColor - label.text = self.configuration.noImagesTitle + label.font = self.pickerConfiguration.configuration.noImagesFont + label.textColor = self.pickerConfiguration.configuration.noImagesColor + label.text = self.pickerConfiguration.configuration.noImagesTitle label.alpha = 0 label.sizeToFit() self.addSubview(label) diff --git a/Source/ImagePickerController.swift b/Source/ImagePickerController.swift index ddd7fbfa..da3b8072 100644 --- a/Source/ImagePickerController.swift +++ b/Source/ImagePickerController.swift @@ -57,7 +57,7 @@ public class ImagePickerController: UIViewController { return gesture }() - lazy var configuration: PickerConfiguration = PickerConfiguration() + lazy var pickerConfiguration: PickerConfiguration = PickerConfiguration.sharedInstance public weak var delegate: ImagePickerDelegate? public var stack = ImageStack() @@ -86,7 +86,7 @@ public class ImagePickerController: UIViewController { } view.backgroundColor = .whiteColor() - view.backgroundColor = configuration.mainColor + view.backgroundColor = pickerConfiguration.configuration.mainColor cameraController.view.addGestureRecognizer(panGestureRecognizer) subscribe() @@ -141,7 +141,7 @@ public class ImagePickerController: UIViewController { guard let sender = notification.object as? ImageStack else { return } let title = !sender.images.isEmpty ? - configuration.doneButtonTitle : configuration.cancelButtonTitle + pickerConfiguration.configuration.doneButtonTitle : pickerConfiguration.configuration.cancelButtonTitle bottomContainer.doneButton.setTitle(title, forState: .Normal) } diff --git a/Source/TopView/TopView.swift b/Source/TopView/TopView.swift index a5c6c8ea..22a47e4e 100644 --- a/Source/TopView/TopView.swift +++ b/Source/TopView/TopView.swift @@ -21,7 +21,7 @@ class TopView: UIView { button.titleEdgeInsets = UIEdgeInsetsMake(0, 4, 0, 0) button.setTitleColor(UIColor(red:0.98, green:0.98, blue:0.45, alpha:1), forState: .Normal) button.setTitleColor(UIColor(red:0.52, green:0.52, blue:0.24, alpha:1), forState: .Highlighted) - button.titleLabel?.font = self.configuration.flashButton + button.titleLabel?.font = self.pickerConfiguration.configuration.flashButton button.addTarget(self, action: "flashButtonDidPress:", forControlEvents: .TouchUpInside) button.contentHorizontalAlignment = .Left @@ -37,7 +37,7 @@ class TopView: UIView { return button }() - lazy var configuration: PickerConfiguration = { + lazy var pickerConfiguration: PickerConfiguration = { let configuration = PickerConfiguration() return configuration }() From 0f66cec598954a4fa77bb6eda50b4b1539b97547 Mon Sep 17 00:00:00 2001 From: Ramon Gilabert Date: Mon, 5 Oct 2015 13:15:19 +0200 Subject: [PATCH 3/5] Change the name to configuration --- Source/BottomView/BottomContainerView.swift | 4 ++-- Source/BottomView/ButtonPicker.swift | 4 ++-- Source/CameraView/CameraView.swift | 4 ++-- Source/{PickerConfiguration.swift => Configuration.swift} | 4 ++-- Source/ImageGallery/ImageGalleryView.swift | 4 ++-- Source/ImagePickerController.swift | 2 +- Source/TopView/TopView.swift | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) rename Source/{PickerConfiguration.swift => Configuration.swift} (91%) diff --git a/Source/BottomView/BottomContainerView.swift b/Source/BottomView/BottomContainerView.swift index e99cb747..e945006e 100644 --- a/Source/BottomView/BottomContainerView.swift +++ b/Source/BottomView/BottomContainerView.swift @@ -42,8 +42,8 @@ class BottomContainerView: UIView { return view }() - lazy var pickerConfiguration: PickerConfiguration = { - let configuration = PickerConfiguration() + lazy var pickerConfiguration: Configuration = { + let configuration = Configuration() return configuration }() diff --git a/Source/BottomView/ButtonPicker.swift b/Source/BottomView/ButtonPicker.swift index 13ee2c7f..04a3900f 100644 --- a/Source/BottomView/ButtonPicker.swift +++ b/Source/BottomView/ButtonPicker.swift @@ -21,8 +21,8 @@ class ButtonPicker: UIButton { return label }() - lazy var pickerConfiguration: PickerConfiguration = { - let configuration = PickerConfiguration() + lazy var pickerConfiguration: Configuration = { + let configuration = Configuration() return configuration }() diff --git a/Source/CameraView/CameraView.swift b/Source/CameraView/CameraView.swift index 4c37adaa..d588bf15 100644 --- a/Source/CameraView/CameraView.swift +++ b/Source/CameraView/CameraView.swift @@ -10,8 +10,8 @@ protocol CameraViewDelegate: class { class CameraView: UIViewController { - lazy var pickerConfiguration: PickerConfiguration = { - let configuration = PickerConfiguration() + lazy var pickerConfiguration: Configuration = { + let configuration = Configuration() return configuration }() diff --git a/Source/PickerConfiguration.swift b/Source/Configuration.swift similarity index 91% rename from Source/PickerConfiguration.swift rename to Source/Configuration.swift index 0ce1ee45..5fb0b75f 100644 --- a/Source/PickerConfiguration.swift +++ b/Source/Configuration.swift @@ -1,8 +1,8 @@ import UIKit -public class PickerConfiguration { +public class Configuration { var configuration = ImagePickerConfiguration() - static let sharedInstance = PickerConfiguration() + static let sharedInstance = Configuration() } public struct ImagePickerConfiguration { diff --git a/Source/ImageGallery/ImageGalleryView.swift b/Source/ImageGallery/ImageGalleryView.swift index a1dacebe..e71eea44 100644 --- a/Source/ImageGallery/ImageGalleryView.swift +++ b/Source/ImageGallery/ImageGalleryView.swift @@ -75,8 +75,8 @@ public class ImageGalleryView: UIView { return images }() - lazy var pickerConfiguration: PickerConfiguration = { - let configuration = PickerConfiguration() + lazy var pickerConfiguration: Configuration = { + let configuration = Configuration() return configuration }() diff --git a/Source/ImagePickerController.swift b/Source/ImagePickerController.swift index da3b8072..287c4dec 100644 --- a/Source/ImagePickerController.swift +++ b/Source/ImagePickerController.swift @@ -57,7 +57,7 @@ public class ImagePickerController: UIViewController { return gesture }() - lazy var pickerConfiguration: PickerConfiguration = PickerConfiguration.sharedInstance + lazy var pickerConfiguration: Configuration = Configuration.sharedInstance public weak var delegate: ImagePickerDelegate? public var stack = ImageStack() diff --git a/Source/TopView/TopView.swift b/Source/TopView/TopView.swift index 22a47e4e..91bd1b98 100644 --- a/Source/TopView/TopView.swift +++ b/Source/TopView/TopView.swift @@ -37,8 +37,8 @@ class TopView: UIView { return button }() - lazy var pickerConfiguration: PickerConfiguration = { - let configuration = PickerConfiguration() + lazy var pickerConfiguration: Configuration = { + let configuration = Configuration() return configuration }() From 2ee5fd721c5bc208454b57c696def4c86e9a1030 Mon Sep 17 00:00:00 2001 From: Ramon Gilabert Date: Mon, 5 Oct 2015 13:22:27 +0200 Subject: [PATCH 4/5] Just one struct --- Source/BottomView/BottomContainerView.swift | 15 ++++++--------- Source/BottomView/ButtonPicker.swift | 7 ++----- Source/CameraView/CameraView.swift | 9 +++------ Source/Configuration.swift | 7 ++----- Source/ImageGallery/ImageGalleryView.swift | 15 ++++++--------- Source/ImagePickerController.swift | 4 ++-- Source/TopView/TopView.swift | 7 ++----- 7 files changed, 23 insertions(+), 41 deletions(-) diff --git a/Source/BottomView/BottomContainerView.swift b/Source/BottomView/BottomContainerView.swift index e945006e..906f12d5 100644 --- a/Source/BottomView/BottomContainerView.swift +++ b/Source/BottomView/BottomContainerView.swift @@ -30,8 +30,8 @@ class BottomContainerView: UIView { lazy var doneButton: UIButton = { [unowned self] in let button = UIButton() - button.setTitle(self.pickerConfiguration.configuration.cancelButtonTitle, forState: .Normal) - button.titleLabel?.font = self.pickerConfiguration.configuration.doneButton + button.setTitle(self.pickerConfiguration.cancelButtonTitle, forState: .Normal) + button.titleLabel?.font = self.pickerConfiguration.doneButton button.addTarget(self, action: "doneButtonDidPress:", forControlEvents: .TouchUpInside) return button @@ -42,14 +42,11 @@ class BottomContainerView: UIView { return view }() - lazy var pickerConfiguration: Configuration = { - let configuration = Configuration() - return configuration - }() + lazy var pickerConfiguration: Configuration = Configuration.sharedInstance lazy var topSeparator: UIView = { [unowned self] in let view = UIView() - view.backgroundColor = self.pickerConfiguration.configuration.backgroundColor + view.backgroundColor = self.pickerConfiguration.backgroundColor return view }() @@ -74,7 +71,7 @@ class BottomContainerView: UIView { view.translatesAutoresizingMaskIntoConstraints = false } - backgroundColor = pickerConfiguration.configuration.backgroundColor + backgroundColor = pickerConfiguration.backgroundColor stackView.addGestureRecognizer(tapGestureRecognizer) setupConstraints() @@ -87,7 +84,7 @@ class BottomContainerView: UIView { // MARK: - Action methods func doneButtonDidPress(button: UIButton) { - if button.currentTitle == pickerConfiguration.configuration.cancelButtonTitle { + if button.currentTitle == pickerConfiguration.cancelButtonTitle { delegate?.cancelButtonDidPress() } else { delegate?.doneButtonDidPress() diff --git a/Source/BottomView/ButtonPicker.swift b/Source/BottomView/ButtonPicker.swift index 04a3900f..668fa2f1 100644 --- a/Source/BottomView/ButtonPicker.swift +++ b/Source/BottomView/ButtonPicker.swift @@ -16,15 +16,12 @@ class ButtonPicker: UIButton { lazy var numberLabel: UILabel = { [unowned self] in let label = UILabel() label.translatesAutoresizingMaskIntoConstraints = false - label.font = self.pickerConfiguration.configuration.numberLabelFont + label.font = self.pickerConfiguration.numberLabelFont return label }() - lazy var pickerConfiguration: Configuration = { - let configuration = Configuration() - return configuration - }() + lazy var pickerConfiguration: Configuration = Configuration.sharedInstance weak var delegate: ButtonPickerDelegate? diff --git a/Source/CameraView/CameraView.swift b/Source/CameraView/CameraView.swift index d588bf15..2aac01dc 100644 --- a/Source/CameraView/CameraView.swift +++ b/Source/CameraView/CameraView.swift @@ -10,10 +10,7 @@ protocol CameraViewDelegate: class { class CameraView: UIViewController { - lazy var pickerConfiguration: Configuration = { - let configuration = Configuration() - return configuration - }() + lazy var pickerConfiguration: Configuration = Configuration.sharedInstance lazy var blurView: UIVisualEffectView = { [unowned self] in let effect = UIBlurEffect(style: .Dark) @@ -64,8 +61,8 @@ class CameraView: UIViewController { initializeCamera() - view.backgroundColor = self.pickerConfiguration.configuration.mainColor - previewLayer?.backgroundColor = self.pickerConfiguration.configuration.mainColor.CGColor + view.backgroundColor = self.pickerConfiguration.mainColor + previewLayer?.backgroundColor = self.pickerConfiguration.mainColor.CGColor } // MARK: - Initialize camera diff --git a/Source/Configuration.swift b/Source/Configuration.swift index 5fb0b75f..f5fbc70c 100644 --- a/Source/Configuration.swift +++ b/Source/Configuration.swift @@ -1,11 +1,8 @@ import UIKit -public class Configuration { - var configuration = ImagePickerConfiguration() - static let sharedInstance = Configuration() -} +public struct Configuration { -public struct ImagePickerConfiguration { + static let sharedInstance = Configuration() public init() { } diff --git a/Source/ImageGallery/ImageGalleryView.swift b/Source/ImageGallery/ImageGalleryView.swift index e71eea44..df74cdb5 100644 --- a/Source/ImageGallery/ImageGalleryView.swift +++ b/Source/ImageGallery/ImageGalleryView.swift @@ -26,7 +26,7 @@ public class ImageGalleryView: UIView { let collectionView = UICollectionView(frame: CGRectMake(0, 0, 0, 0), collectionViewLayout: self.collectionViewLayout) collectionView.translatesAutoresizingMaskIntoConstraints = false - collectionView.backgroundColor = self.pickerConfiguration.configuration.mainColor + collectionView.backgroundColor = self.pickerConfiguration.mainColor collectionView.showsHorizontalScrollIndicator = false collectionView.layer.anchorPoint = CGPointMake(0.5, 0.5) @@ -36,7 +36,7 @@ public class ImageGalleryView: UIView { lazy var collectionViewLayout: UICollectionViewLayout = { [unowned self] in let layout = UICollectionViewFlowLayout() layout.scrollDirection = .Horizontal - layout.minimumInteritemSpacing = self.pickerConfiguration.configuration.cellSpacing + layout.minimumInteritemSpacing = self.pickerConfiguration.cellSpacing layout.minimumLineSpacing = 2 layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0) @@ -75,16 +75,13 @@ public class ImageGalleryView: UIView { return images }() - lazy var pickerConfiguration: Configuration = { - let configuration = Configuration() - return configuration - }() + lazy var pickerConfiguration: Configuration = Configuration.sharedInstance lazy var noImagesLabel: UILabel = { [unowned self] in let label = UILabel() - label.font = self.pickerConfiguration.configuration.noImagesFont - label.textColor = self.pickerConfiguration.configuration.noImagesColor - label.text = self.pickerConfiguration.configuration.noImagesTitle + label.font = self.pickerConfiguration.noImagesFont + label.textColor = self.pickerConfiguration.noImagesColor + label.text = self.pickerConfiguration.noImagesTitle label.alpha = 0 label.sizeToFit() self.addSubview(label) diff --git a/Source/ImagePickerController.swift b/Source/ImagePickerController.swift index 287c4dec..e69e678b 100644 --- a/Source/ImagePickerController.swift +++ b/Source/ImagePickerController.swift @@ -86,7 +86,7 @@ public class ImagePickerController: UIViewController { } view.backgroundColor = .whiteColor() - view.backgroundColor = pickerConfiguration.configuration.mainColor + view.backgroundColor = pickerConfiguration.mainColor cameraController.view.addGestureRecognizer(panGestureRecognizer) subscribe() @@ -141,7 +141,7 @@ public class ImagePickerController: UIViewController { guard let sender = notification.object as? ImageStack else { return } let title = !sender.images.isEmpty ? - pickerConfiguration.configuration.doneButtonTitle : pickerConfiguration.configuration.cancelButtonTitle + pickerConfiguration.doneButtonTitle : pickerConfiguration.cancelButtonTitle bottomContainer.doneButton.setTitle(title, forState: .Normal) } diff --git a/Source/TopView/TopView.swift b/Source/TopView/TopView.swift index 91bd1b98..804a2cfb 100644 --- a/Source/TopView/TopView.swift +++ b/Source/TopView/TopView.swift @@ -21,7 +21,7 @@ class TopView: UIView { button.titleEdgeInsets = UIEdgeInsetsMake(0, 4, 0, 0) button.setTitleColor(UIColor(red:0.98, green:0.98, blue:0.45, alpha:1), forState: .Normal) button.setTitleColor(UIColor(red:0.52, green:0.52, blue:0.24, alpha:1), forState: .Highlighted) - button.titleLabel?.font = self.pickerConfiguration.configuration.flashButton + button.titleLabel?.font = self.pickerConfiguration.flashButton button.addTarget(self, action: "flashButtonDidPress:", forControlEvents: .TouchUpInside) button.contentHorizontalAlignment = .Left @@ -37,10 +37,7 @@ class TopView: UIView { return button }() - lazy var pickerConfiguration: Configuration = { - let configuration = Configuration() - return configuration - }() + lazy var pickerConfiguration: Configuration = Configuration.sharedInstance weak var delegate: TopViewDelegate? From 08d6610474afca2fe6f462a67b0054cc292bfcf3 Mon Sep 17 00:00:00 2001 From: Ramon Gilabert Date: Mon, 5 Oct 2015 13:24:55 +0200 Subject: [PATCH 5/5] Fix merge conflicts --- Source/ImagePickerController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/ImagePickerController.swift b/Source/ImagePickerController.swift index 75eaa7b5..a529441a 100644 --- a/Source/ImagePickerController.swift +++ b/Source/ImagePickerController.swift @@ -140,7 +140,7 @@ public class ImagePickerController: UIViewController { func adjustButtonTitle(notification: NSNotification) { guard let sender = notification.object as? ImageStack else { return } - let title = !sender.images.isEmpty ? + let title = !sender.assets.isEmpty ? pickerConfiguration.doneButtonTitle : pickerConfiguration.cancelButtonTitle bottomContainer.doneButton.setTitle(title, forState: .Normal) }