Commit b630406a by Daniel Dahan

issue-27: updated naming for Views and Text

parent 756b9643
......@@ -18,7 +18,7 @@
import UIKit
public class BasicCard : MaterialCard, Comparable, Equatable {
public class BasicCardView : MaterialCardView, Comparable, Equatable {
//
// :name: layoutConstraints
//
......@@ -277,22 +277,22 @@ public class BasicCard : MaterialCard, Comparable, Equatable {
}
}
public func ==(lhs: BasicCard, rhs: BasicCard) -> Bool {
public func ==(lhs: BasicCardView, rhs: BasicCardView) -> Bool {
return lhs.tag == rhs.tag
}
public func <=(lhs: BasicCard, rhs: BasicCard) -> Bool {
public func <=(lhs: BasicCardView, rhs: BasicCardView) -> Bool {
return lhs.tag <= rhs.tag
}
public func >=(lhs: BasicCard, rhs: BasicCard) -> Bool {
public func >=(lhs: BasicCardView, rhs: BasicCardView) -> Bool {
return lhs.tag >= rhs.tag
}
public func >(lhs: BasicCard, rhs: BasicCard) -> Bool {
public func >(lhs: BasicCardView, rhs: BasicCardView) -> Bool {
return lhs.tag > rhs.tag
}
public func <(lhs: BasicCard, rhs: BasicCard) -> Bool {
public func <(lhs: BasicCardView, rhs: BasicCardView) -> Bool {
return lhs.tag < rhs.tag
}
......@@ -24,7 +24,7 @@ public class FlatButton : MaterialButton {
//
internal override func prepareView() {
super.prepareView()
setTitleColor(MaterialTheme.indigo.darken1, forState: .Normal)
setTitleColor(MaterialTheme.blue.darken1, forState: .Normal)
backgroundColor = MaterialTheme.clear.color
contentEdgeInsets = UIEdgeInsetsMake(4, 16, 4, 16)
}
......
......@@ -18,7 +18,7 @@
import UIKit
public class ImageCard : MaterialCard, Comparable, Equatable {
public class ImageCardView : MaterialCardView, Comparable, Equatable {
//
// :name: layoutConstraints
//
......@@ -351,22 +351,22 @@ public class ImageCard : MaterialCard, Comparable, Equatable {
}
}
public func ==(lhs: ImageCard, rhs: ImageCard) -> Bool {
public func ==(lhs: ImageCardView, rhs: ImageCardView) -> Bool {
return lhs.tag == rhs.tag
}
public func <=(lhs: ImageCard, rhs: ImageCard) -> Bool {
public func <=(lhs: ImageCardView, rhs: ImageCardView) -> Bool {
return lhs.tag <= rhs.tag
}
public func >=(lhs: ImageCard, rhs: ImageCard) -> Bool {
public func >=(lhs: ImageCardView, rhs: ImageCardView) -> Bool {
return lhs.tag >= rhs.tag
}
public func >(lhs: ImageCard, rhs: ImageCard) -> Bool {
public func >(lhs: ImageCardView, rhs: ImageCardView) -> Bool {
return lhs.tag > rhs.tag
}
public func <(lhs: ImageCard, rhs: ImageCard) -> Bool {
public func <(lhs: ImageCardView, rhs: ImageCardView) -> Bool {
return lhs.tag < rhs.tag
}
......@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.7.0</string>
<string>1.8.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
......
......@@ -44,7 +44,7 @@ public class MaterialButton : UIButton {
/**
:name: pulseColor
*/
public var pulseColor: UIColor? = MaterialTheme.indigo.lighten3
public var pulseColor: UIColor? = MaterialTheme.blue.lighten3
/**
:name: init
......
......@@ -18,7 +18,7 @@
import UIKit
public class MaterialCard : UIView {
public class MaterialCardView : UIView {
//
// :name: backgroundColorView
//
......@@ -49,7 +49,7 @@ public class MaterialCard : UIView {
/**
:name: pulseColor
*/
public var pulseColor: UIColor = MaterialTheme.indigo.lighten3
public var pulseColor: UIColor = MaterialTheme.blue.lighten3
/**
:name: init
......
......@@ -18,14 +18,14 @@
import UIKit
@objc(TextDelegate)
@objc(MaterialTextDelegate)
public protocol TextDelegate {
optional func textStorageWillProcessEdit(text: Text, textStorage: TextStorage, string: String, range: NSRange)
optional func textStorageDidProcessEdit(text: Text, textStorage: TextStorage, string: String, result: NSTextCheckingResult, flags: NSMatchingFlags, stop: UnsafeMutablePointer<ObjCBool>)
optional func textStorageWillProcessEdit(text: MaterialText, textStorage: MaterialTextStorage, string: String, range: NSRange)
optional func textStorageDidProcessEdit(text: MaterialText, textStorage: MaterialTextStorage, string: String, result: NSTextCheckingResult, flags: NSMatchingFlags, stop: UnsafeMutablePointer<ObjCBool>)
}
@objc(Text)
public class Text: NSObject {
@objc(MaterialText)
public class MaterialText: NSObject {
/**
:name: searchPattern
:description: A string representation of the regular expression that matches text within
......@@ -42,7 +42,7 @@ public class Text: NSObject {
:name: textStorage
:description: Reference to wrapped NSTextStorage
*/
public let textStorage: TextStorage
public let textStorage: MaterialTextStorage
/**
:name: delegate
......@@ -53,14 +53,14 @@ public class Text: NSObject {
/**
:name: init
*/
override public init() {
textStorage = TextStorage()
public override init() {
textStorage = MaterialTextStorage()
super.init()
textStorage.searchExpression = NSRegularExpression(pattern: searchPattern, options: nil, error: nil)
textStorage.textStorageWillProcessEdit = { (textStorage: TextStorage, string: String, range: NSRange) -> Void in
textStorage.textStorageWillProcessEdit = { (textStorage: MaterialTextStorage, string: String, range: NSRange) -> Void in
self.delegate?.textStorageWillProcessEdit?(self, textStorage: textStorage, string: string, range: range)
}
textStorage.textStorageDidProcessEdit = { (textStorage: TextStorage, result: NSTextCheckingResult, flags: NSMatchingFlags, stop: UnsafeMutablePointer<ObjCBool>) -> Void in
textStorage.textStorageDidProcessEdit = { (textStorage: MaterialTextStorage, result: NSTextCheckingResult, flags: NSMatchingFlags, stop: UnsafeMutablePointer<ObjCBool>) -> Void in
self.delegate?.textStorageDidProcessEdit?(self, textStorage: textStorage, string: textStorage.string, result: result, flags: flags, stop: stop)
}
}
......
......@@ -18,10 +18,10 @@
import UIKit
internal typealias TextStorageWillProcessEdit = (TextStorage, String, NSRange) -> Void
internal typealias TextStorageDidProcessEdit = (TextStorage, NSTextCheckingResult, NSMatchingFlags, UnsafeMutablePointer<ObjCBool>) -> Void
internal typealias MaterialTextStorageWillProcessEdit = (MaterialTextStorage, String, NSRange) -> Void
internal typealias MaterialTextStorageDidProcessEdit = (MaterialTextStorage, NSTextCheckingResult, NSMatchingFlags, UnsafeMutablePointer<ObjCBool>) -> Void
public class TextStorage: NSTextStorage {
public class MaterialTextStorage: NSTextStorage {
/**
:name: store
:description: Acts as the model, storing the string value.
......@@ -39,14 +39,14 @@ public class TextStorage: NSTextStorage {
:description: If set, this block callback executes when there is a change in the TextStorage
string value.
*/
internal var textStorageWillProcessEdit: TextStorageWillProcessEdit?
internal var textStorageWillProcessEdit: MaterialTextStorageWillProcessEdit?
/**
:name: textStorageDidProcessEdit
:description: If set, this block callback executes when a match is detected after a change in
the TextStorage string value.
*/
internal var textStorageDidProcessEdit: TextStorageDidProcessEdit?
internal var textStorageDidProcessEdit: MaterialTextStorageDidProcessEdit?
required public init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
......
......@@ -25,7 +25,7 @@ public class RaisedButton : MaterialButton {
internal override func prepareView() {
super.prepareView()
setTitleColor(MaterialTheme.white.color, forState: .Normal)
backgroundColor = MaterialTheme.indigo.darken1
backgroundColor = MaterialTheme.blue.darken1
contentEdgeInsets = UIEdgeInsetsMake(4, 16, 4, 16)
}
......
......@@ -20,23 +20,23 @@ import UIKit
public class TextView: UITextView {
//
// :name: label
// :description: Placeholder label.
//
private lazy var label: UILabel = UILabel()
//
// :name: labelConstraints
// :name: placeholderconstraints
// :description: Autoresize constraints for the placeholder label.
//
private var labelConstraints: Array<NSLayoutConstraint>?
private var placeholderconstraints: Array<NSLayoutConstraint>?
required public init(coder aDecoder: NSCoder) {
/**
:name: init
*/
public required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
prepareView()
}
override public init(frame: CGRect, textContainer: NSTextContainer?) {
/**
:name: init
*/
public override init(frame: CGRect, textContainer: NSTextContainer?) {
super.init(frame: frame, textContainer: textContainer)
if CGRectZero == frame {
setTranslatesAutoresizingMaskIntoConstraints(false)
......@@ -56,47 +56,23 @@ public class TextView: UITextView {
:name: placeholder
:description: The placeholder label string.
*/
public var placeholder: String = "" {
didSet {
label.text = placeholder
}
}
/**
:name: placeholderColor
:description: The placeholder color.
*/
public var placeholderColor: UIColor = MaterialTheme.indigo.lighten1 {
public var placeholderLabel: UILabel? {
didSet {
label.textColor = placeholderColor
placeholderLabel!.setTranslatesAutoresizingMaskIntoConstraints(false)
placeholderLabel!.font = font
placeholderLabel!.textAlignment = textAlignment
placeholderLabel!.numberOfLines = 0
placeholderLabel!.backgroundColor = MaterialTheme.clear.color
addSubview(placeholderLabel!)
}
}
/**
:name: font
:description: Font to use for placeholder based on UITextView font.
*/
override public var font: UIFont! {
didSet {
label.font = font
}
}
/**
:name: textAlignment
:description: Sets placeholder textAlignment based on UITextView textAlignment.
*/
override public var textAlignment: NSTextAlignment {
didSet {
label.textAlignment = textAlignment
}
}
/**
:name: text
:description: When set, updates the placeholder text.
*/
override public var text: String! {
public override var text: String! {
didSet {
textViewTextDidChange()
}
......@@ -106,7 +82,7 @@ public class TextView: UITextView {
:name: attributedText
:description: When set, updates the placeholder attributedText.
*/
override public var attributedText: NSAttributedString! {
public override var attributedText: NSAttributedString! {
didSet {
textViewTextDidChange()
}
......@@ -116,15 +92,15 @@ public class TextView: UITextView {
:name: textContainerInset
:description: When set, updates the placeholder constraints.
*/
override public var textContainerInset: UIEdgeInsets {
public override var textContainerInset: UIEdgeInsets {
didSet {
updateLabelConstraints()
}
}
override public func layoutSubviews() {
public override func layoutSubviews() {
super.layoutSubviews()
label.preferredMaxLayoutWidth = textContainer.size.width - textContainer.lineFragmentPadding * 2
placeholderLabel?.preferredMaxLayoutWidth = textContainer.size.width - textContainer.lineFragmentPadding * 2
}
//
......@@ -132,7 +108,7 @@ public class TextView: UITextView {
// :description: Updates the label visibility when text is empty or not.
//
internal func textViewTextDidChange() {
label.hidden = !text.isEmpty
placeholderLabel?.hidden = !text.isEmpty
}
//
......@@ -140,17 +116,6 @@ public class TextView: UITextView {
// :description: Sets up the common initilized values.
//
private func prepareView() {
backgroundColor = MaterialTheme.clear.color
textColor = MaterialTheme.black.color
label.font = font
label.textColor = placeholderColor
label.textAlignment = textAlignment
label.text = placeholder
label.numberOfLines = 0
label.backgroundColor = MaterialTheme.clear.color
label.setTranslatesAutoresizingMaskIntoConstraints(false)
addSubview(label)
// label needs to be added to the view
// hierarchy before setting insets
textContainerInset = UIEdgeInsetsMake(16, 16, 16, 16)
......@@ -164,15 +129,29 @@ public class TextView: UITextView {
// :description: Updates the placeholder constraints.
//
private func updateLabelConstraints() {
if nil != labelConstraints {
removeConstraints(labelConstraints!)
if nil != placeholderconstraints {
NSLayoutConstraint.deactivateConstraints(placeholderconstraints!)
}
var constraints: Array<NSLayoutConstraint> = NSLayoutConstraint.constraintsWithVisualFormat("H:|-(left)-[placeholder]-(right)-|", options: nil, metrics: ["left": textContainerInset.left + textContainer.lineFragmentPadding, "right": textContainerInset.right + textContainer.lineFragmentPadding], views: ["placeholder": label]) as! Array<NSLayoutConstraint>
constraints += NSLayoutConstraint.constraintsWithVisualFormat("V:|-(top)-[placeholder]-(>=bottom)-|", options: nil, metrics: ["top": textContainerInset.top, "bottom": textContainerInset.bottom], views: ["placeholder": label]) as! Array<NSLayoutConstraint>
placeholderconstraints = Layout.constraint("H:|-(left)-[placeholder]-(right)-|",
options: nil,
metrics: [
"left": textContainerInset.left + textContainer.lineFragmentPadding,
"right": textContainerInset.right + textContainer.lineFragmentPadding
], views: [
"placeholder": placeholderLabel!
])
placeholderconstraints += Layout.constraint("V:|-(top)-[placeholder]-(>=bottom)-|",
options: nil,
metrics: [
"top": textContainerInset.top,
"bottom": textContainerInset.bottom
],
views: [
"placeholder": placeholderLabel!
])
labelConstraints = constraints
addConstraints(constraints)
NSLayoutConstraint.activateConstraints(placeholderconstraints!)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment