|
| 1 | +// |
| 2 | +// InlineTagControllerConfiguration.swift |
| 3 | +// Testing |
| 4 | +// |
| 5 | +// Created by Kyle Begeman on 7/10/17. |
| 6 | +// Copyright © 2017 Kyle Begeman. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +import Foundation |
| 10 | +import UIKit |
| 11 | + |
| 12 | +internal class Config { |
| 13 | + static let instance = Config() |
| 14 | + private init() { |
| 15 | + configuration = DefaultConfiguration() |
| 16 | + } |
| 17 | + |
| 18 | + var configuration: InlineTagConfigurable |
| 19 | + func set(config: InlineTagConfigurable) { |
| 20 | + self.configuration = config |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +public typealias ColorCollection = (view: UIColor, edit: UIColor, invalid: UIColor, placeholder: UIColor?) |
| 25 | +public typealias FontCollection = (view: UIFont, edit: UIFont, invalid: UIFont, placeholder: UIFont) |
| 26 | +public typealias ValueCollection = (view: CGFloat, edit: CGFloat, invalid: CGFloat) |
| 27 | + |
| 28 | +public enum NumberOfTags { |
| 29 | + case unlimited |
| 30 | + case quantity(Int) |
| 31 | +} |
| 32 | + |
| 33 | +public class DefaultConfiguration: InlineTagConfigurable {} |
| 34 | +public let TagConfig = Config.instance.configuration |
| 35 | + |
| 36 | +public protocol InlineTagConfigurable { |
| 37 | + var backgroundColor: ColorCollection { get } |
| 38 | + var fontColor: ColorCollection { get } |
| 39 | + var font: FontCollection { get } |
| 40 | + var radius: ValueCollection { get } |
| 41 | + |
| 42 | + var cellHeight: Float { get } |
| 43 | + var inset: UIEdgeInsets { get } |
| 44 | + var interitemSpacing: CGFloat { get } |
| 45 | + var lineSpacing: CGFloat { get } |
| 46 | + var keyboardType: UIKeyboardType { get } |
| 47 | + var returnKey: UIReturnKeyType { get } |
| 48 | + var autoCapitalization: UITextAutocapitalizationType { get } |
| 49 | + var autoCorrection: UITextAutocorrectionType { get } |
| 50 | + var skipOnWhitespace: Bool { get } |
| 51 | + var skipOnReturnKey: Bool { get } |
| 52 | + var placeholderText: String { get } |
| 53 | + var numberOfTags: NumberOfTags { get } |
| 54 | + var itemValidation: Validation? { get } |
| 55 | +} |
| 56 | + |
| 57 | +extension InlineTagConfigurable { |
| 58 | + public var backgroundColor: ColorCollection { |
| 59 | + return (view: UIColor.blue, edit: UIColor.white, invalid: UIColor.red, placeholder: nil) |
| 60 | + } |
| 61 | + public var fontColor: ColorCollection { |
| 62 | + return (view: UIColor.white, edit: UIColor.darkText, invalid: UIColor.white, placeholder: UIColor.gray) |
| 63 | + } |
| 64 | + public var radius: ValueCollection { |
| 65 | + return (view: 8.0, edit: 8.0, invalid: 8.0) |
| 66 | + } |
| 67 | + public var font: FontCollection { |
| 68 | + let font = UIFont.systemFont(ofSize: 12.0, weight: UIFontWeightMedium) |
| 69 | + let phFont = UIFont.systemFont(ofSize: 12.0, weight: UIFontWeightLight) |
| 70 | + return (view: font, edit: font, invalid: font, placeholder: phFont) |
| 71 | + } |
| 72 | + |
| 73 | + public var cellHeight: Float { return 20.0 } |
| 74 | + public var inset: UIEdgeInsets { return UIEdgeInsets(top: 2, left: 4, bottom: 2, right: 4) } |
| 75 | + public var interitemSpacing: CGFloat { return 5.0 } |
| 76 | + public var lineSpacing: CGFloat { return 5.0 } |
| 77 | + public var keyboardType: UIKeyboardType { return .default } |
| 78 | + public var returnKey: UIReturnKeyType { return .done } |
| 79 | + public var autoCapitalization: UITextAutocapitalizationType { return .none } |
| 80 | + public var autoCorrection: UITextAutocorrectionType { return .no } |
| 81 | + public var skipOnWhitespace: Bool { return true } |
| 82 | + public var skipOnReturnKey: Bool { return true } |
| 83 | + public var placeholderText: String { return "Add tags..." } |
| 84 | + public var numberOfTags: NumberOfTags { return .unlimited } |
| 85 | + public var itemValidation: Validation? { return InlineTagControllerValidation.testEmptiness } |
| 86 | +} |
0 commit comments