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 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
15 changes: 6 additions & 9 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.cancelButtonTitle, forState: .Normal)
button.titleLabel?.font = self.pickerConfiguration.doneButton
button.addTarget(self, action: "doneButtonDidPress:", forControlEvents: .TouchUpInside)

return button
Expand All @@ -42,14 +42,11 @@ class BottomContainerView: UIView {
return view
}()

lazy var configuration: PickerConfiguration = {
let configuration = PickerConfiguration()
return configuration
}()
lazy var pickerConfiguration: Configuration = Configuration.sharedInstance

lazy var topSeparator: UIView = { [unowned self] in
let view = UIView()
view.backgroundColor = self.configuration.backgroundColor
view.backgroundColor = self.pickerConfiguration.backgroundColor

return view
}()
Expand All @@ -74,7 +71,7 @@ class BottomContainerView: UIView {
view.translatesAutoresizingMaskIntoConstraints = false
}

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

setupConstraints()
Expand All @@ -87,7 +84,7 @@ class BottomContainerView: UIView {
// MARK: - Action methods

func doneButtonDidPress(button: UIButton) {
if button.currentTitle == configuration.cancelButtonTitle {
if button.currentTitle == pickerConfiguration.cancelButtonTitle {
delegate?.cancelButtonDidPress()
} else {
delegate?.doneButtonDidPress()
Expand Down
7 changes: 2 additions & 5 deletions Source/BottomView/ButtonPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +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.numberLabelFont

return label
}()

lazy var configuration: PickerConfiguration = {
let configuration = PickerConfiguration()
return configuration
}()
lazy var pickerConfiguration: Configuration = Configuration.sharedInstance

weak var delegate: ButtonPickerDelegate?

Expand Down
9 changes: 3 additions & 6 deletions Source/CameraView/CameraView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ protocol CameraViewDelegate: class {

class CameraView: UIViewController {

lazy var configuration: PickerConfiguration = {
let configuration = PickerConfiguration()
return configuration
}()
lazy var pickerConfiguration: Configuration = Configuration.sharedInstance

lazy var blurView: UIVisualEffectView = { [unowned self] in
let effect = UIBlurEffect(style: .Dark)
Expand Down Expand Up @@ -64,8 +61,8 @@ class CameraView: UIViewController {

initializeCamera()

view.backgroundColor = self.configuration.mainColor
previewLayer?.backgroundColor = self.configuration.mainColor.CGColor
view.backgroundColor = self.pickerConfiguration.mainColor
previewLayer?.backgroundColor = self.pickerConfiguration.mainColor.CGColor
}

// MARK: - Initialize camera
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import UIKit

public class PickerConfiguration {
public struct Configuration {

static let sharedInstance = Configuration()

public init() { }

// MARK: Colors

Expand Down
15 changes: 6 additions & 9 deletions Source/ImageGallery/ImageGalleryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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.mainColor
collectionView.showsHorizontalScrollIndicator = false
collectionView.layer.anchorPoint = CGPointMake(0.5, 0.5)

Expand All @@ -35,7 +35,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.cellSpacing
layout.minimumLineSpacing = 2
layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0)

Expand Down Expand Up @@ -71,16 +71,13 @@ public class ImageGalleryView: UIView {

lazy var assets = [PHAsset]()

lazy var configuration: PickerConfiguration = {
let configuration = PickerConfiguration()
return configuration
}()
lazy var pickerConfiguration: Configuration = Configuration.sharedInstance

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.noImagesFont
label.textColor = self.pickerConfiguration.noImagesColor
label.text = self.pickerConfiguration.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: Configuration = Configuration.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.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.assets.isEmpty ?
configuration.doneButtonTitle : configuration.cancelButtonTitle
pickerConfiguration.doneButtonTitle : pickerConfiguration.cancelButtonTitle
bottomContainer.doneButton.setTitle(title, forState: .Normal)
}

Expand Down
7 changes: 2 additions & 5 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.flashButton
button.addTarget(self, action: "flashButtonDidPress:", forControlEvents: .TouchUpInside)
button.contentHorizontalAlignment = .Left

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

lazy var configuration: PickerConfiguration = {
let configuration = PickerConfiguration()
return configuration
}()
lazy var pickerConfiguration: Configuration = Configuration.sharedInstance

weak var delegate: TopViewDelegate?

Expand Down