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

Feature/external configuration #40

Merged
merged 6 commits into from
Oct 5, 2015
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 6 additions & 6 deletions Source/BottomView/BottomContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}()
Expand All @@ -74,7 +74,7 @@ class BottomContainerView: UIView {
view.translatesAutoresizingMaskIntoConstraints = false
}

backgroundColor = configuration.backgroundColor
backgroundColor = pickerConfiguration.configuration.backgroundColor
stackView.addGestureRecognizer(tapGestureRecognizer)

setupConstraints()
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions Source/BottomView/ButtonPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}()
Expand Down
6 changes: 3 additions & 3 deletions Source/CameraView/CameraView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ protocol CameraViewDelegate: class {

class CameraView: UIViewController {

lazy var configuration: PickerConfiguration = {
lazy var pickerConfiguration: PickerConfiguration = {
let configuration = PickerConfiguration()
return configuration
}()
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions Source/ImageGallery/ImageGalleryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions Source/ImagePickerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}

Expand Down
7 changes: 7 additions & 0 deletions Source/PickerConfiguration.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import UIKit

public class PickerConfiguration {
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess it could be just Configuration with var imagePicker?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, but I don't want to conflict with Lightbox and stuff like that, what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

But you can use it like ImagePicker.Configuration, with module name, and also - do we have something else except ImagePickerConfiguration, I mean why do we need 2 classes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes just thought about it, changing it!

var configuration = ImagePickerConfiguration()
static let sharedInstance = PickerConfiguration()
}

public struct ImagePickerConfiguration {

public init() { }

// MARK: Colors

Expand Down
4 changes: 2 additions & 2 deletions Source/TopView/TopView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -37,7 +37,7 @@ class TopView: UIView {
return button
}()

lazy var configuration: PickerConfiguration = {
lazy var pickerConfiguration: PickerConfiguration = {
let configuration = PickerConfiguration()
return configuration
}()
Expand Down