Commit a0e2f5dc by Daniel Dahan

fixed issue-316, where placeholder update was resolving to incorrect value

parent af936563
...@@ -61,6 +61,7 @@ class AppNavigationController: NavigationController { ...@@ -61,6 +61,7 @@ class AppNavigationController: NavigationController {
/// Prepares the navigationBar /// Prepares the navigationBar
private func prepareNavigationBar() { private func prepareNavigationBar() {
navigationBar.tintColor = MaterialColor.white
navigationBar.backgroundColor = MaterialColor.blue.base navigationBar.backgroundColor = MaterialColor.blue.base
} }
} }
...@@ -39,6 +39,9 @@ import UIKit ...@@ -39,6 +39,9 @@ import UIKit
import Material import Material
class ViewController: UIViewController, TextFieldDelegate { class ViewController: UIViewController, TextFieldDelegate {
private var nameField: TextField!
private var emailField: TextField!
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
prepareView() prepareView()
...@@ -55,30 +58,30 @@ class ViewController: UIViewController, TextFieldDelegate { ...@@ -55,30 +58,30 @@ class ViewController: UIViewController, TextFieldDelegate {
private func prepareNameField() { private func prepareNameField() {
let w: CGFloat = 300 let w: CGFloat = 300
let x: CGFloat = (MaterialDevice.width - w) / 2 let x: CGFloat = (MaterialDevice.width - w) / 2
let textField: TextField = TextField(frame: CGRectMake(x, 100, w, 24)) nameField = TextField(frame: CGRectMake(x, 100, w, 24))
textField.placeholder = "First Name" nameField.placeholder = "Name"
view.addSubview(textField) view.addSubview(nameField)
} }
/// Prepares the email TextField. /// Prepares the email TextField.
private func prepareEmailField() { private func prepareEmailField() {
let w: CGFloat = 300 let w: CGFloat = 300
let x: CGFloat = (MaterialDevice.width - w) / 2 let x: CGFloat = (MaterialDevice.width - w) / 2
let textField: TextField = TextField(frame: CGRectMake(x, 200, w, 24)) emailField = TextField(frame: CGRectMake(x, 200, w, 24))
textField.placeholder = "Email" emailField.placeholder = "Email"
textField.delegate = self emailField.delegate = self
/* /*
Used to display the error message, which is displayed when Used to display the error message, which is displayed when
the user presses the 'return' key. the user presses the 'return' key.
*/ */
textField.detailLabel = UILabel() emailField.detailLabel = UILabel()
textField.detailLabel!.text = "Email is incorrect." emailField.detailLabel!.text = "Email is incorrect."
textField.detailLabel!.font = RobotoFont.regularWithSize(12) emailField.detailLabel!.font = RobotoFont.regularWithSize(12)
textField.detailLabelActiveColor = MaterialColor.red.accent3 emailField.detailLabelActiveColor = MaterialColor.red.accent3
// textField.detailLabelAutoHideEnabled = false // Uncomment this line to have manual hiding. // textField.detailLabelAutoHideEnabled = false // Uncomment this line to have manual hiding.
view.addSubview(textField) view.addSubview(emailField)
} }
/// Executed when the 'return' key is pressed when using the emailField. /// Executed when the 'return' key is pressed when using the emailField.
......
...@@ -452,9 +452,9 @@ ...@@ -452,9 +452,9 @@
96BCB8031CB40F4B00C806FE /* Button */ = { 96BCB8031CB40F4B00C806FE /* Button */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
96BCB7701CB40DC500C806FE /* MaterialButton.swift */,
96BCB75F1CB40DC500C806FE /* FabButton.swift */, 96BCB75F1CB40DC500C806FE /* FabButton.swift */,
96BCB7601CB40DC500C806FE /* FlatButton.swift */, 96BCB7601CB40DC500C806FE /* FlatButton.swift */,
96BCB7701CB40DC500C806FE /* MaterialButton.swift */,
96BCB7931CB40DC500C806FE /* RaisedButton.swift */, 96BCB7931CB40DC500C806FE /* RaisedButton.swift */,
); );
name = Button; name = Button;
......
...@@ -396,6 +396,7 @@ Add a new dimension of interactivity with CaptureView. CaptureView is a fully fu ...@@ -396,6 +396,7 @@ Add a new dimension of interactivity with CaptureView. CaptureView is a fully fu
* Bottom Sheets * Bottom Sheets
* Dialogs * Dialogs
* Collapsing Toolbar * Collapsing Toolbar
* Pull to Refresh
* RTL Support * RTL Support
* Advanced Camera / Audio Toolset & Views * Advanced Camera / Audio Toolset & Views
* More Examples * More Examples
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>FMWK</string> <string>FMWK</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.40.0</string> <string>1.39.14</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
......
...@@ -439,13 +439,13 @@ public class MaterialButton : UIButton { ...@@ -439,13 +439,13 @@ public class MaterialButton : UIButton {
public override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { public override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesBegan(touches, withEvent: event) super.touchesBegan(touches, withEvent: event)
let duration: NSTimeInterval = MaterialAnimation.pulseDuration(width) let duration: NSTimeInterval = MaterialAnimation.pulseDuration(width)
let point: CGPoint = pulseCenter ? CGPointMake(CGFloat(width / 2), CGFloat(height / 2)) : layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer)
if pulseFocus { if pulseFocus {
pulseLayer = CAShapeLayer() pulseLayer = CAShapeLayer()
} }
if let v: UIColor = pulseColor { if let v: UIColor = pulseColor {
let point: CGPoint = pulseCenter ? CGPointMake(CGFloat(width / 2), CGFloat(height / 2)) : layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer)
MaterialAnimation.pulseAnimation(layer, visualLayer: visualLayer, color: v.colorWithAlphaComponent(pulseOpacity), point: point, width: width, height: height, duration: duration, pulseLayer: pulseLayer) MaterialAnimation.pulseAnimation(layer, visualLayer: visualLayer, color: v.colorWithAlphaComponent(pulseOpacity), point: point, width: width, height: height, duration: duration, pulseLayer: pulseLayer)
} }
......
...@@ -61,6 +61,9 @@ public class MaterialCollectionViewCell : UICollectionViewCell { ...@@ -61,6 +61,9 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
/// The color of the pulse effect. /// The color of the pulse effect.
@IBInspectable public var pulseColor: UIColor? @IBInspectable public var pulseColor: UIColor?
/// Sets a pulse animation to always radiate from the center
@IBInspectable public var pulseCenter: Bool = false
/** /**
A property that manages an image for the visualLayer's contents A property that manages an image for the visualLayer's contents
property. Images should not be set to the backing layer's contents property. Images should not be set to the backing layer's contents
...@@ -547,7 +550,8 @@ public class MaterialCollectionViewCell : UICollectionViewCell { ...@@ -547,7 +550,8 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
} }
if let v: UIColor = pulseColor { if let v: UIColor = pulseColor {
MaterialAnimation.pulseAnimation(layer, visualLayer: visualLayer, color: v.colorWithAlphaComponent(pulseOpacity), point: layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer), width: width, height: height, duration: duration, pulseLayer: pulseLayer) let point: CGPoint = pulseCenter ? CGPointMake(CGFloat(width / 2), CGFloat(height / 2)) : layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer)
MaterialAnimation.pulseAnimation(layer, visualLayer: visualLayer, color: v.colorWithAlphaComponent(pulseOpacity), point: point, width: width, height: height, duration: duration, pulseLayer: pulseLayer)
} }
if pulseScale { if pulseScale {
......
...@@ -46,6 +46,9 @@ public class MaterialPulseView : MaterialView { ...@@ -46,6 +46,9 @@ public class MaterialPulseView : MaterialView {
/// The color of the pulse effect. /// The color of the pulse effect.
@IBInspectable public var pulseColor: UIColor? @IBInspectable public var pulseColor: UIColor?
/// Sets a pulse animation to always radiate from the center
@IBInspectable public var pulseCenter: Bool = false
/** /**
Triggers the pulse animation. Triggers the pulse animation.
- Parameter point: A Optional point to pulse from, otherwise pulses - Parameter point: A Optional point to pulse from, otherwise pulses
...@@ -86,7 +89,8 @@ public class MaterialPulseView : MaterialView { ...@@ -86,7 +89,8 @@ public class MaterialPulseView : MaterialView {
} }
if let v: UIColor = pulseColor { if let v: UIColor = pulseColor {
MaterialAnimation.pulseAnimation(layer, visualLayer: visualLayer, color: v.colorWithAlphaComponent(pulseOpacity), point: layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer), width: width, height: height, duration: duration, pulseLayer: pulseLayer) let point: CGPoint = pulseCenter ? CGPointMake(CGFloat(width / 2), CGFloat(height / 2)) : layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer)
MaterialAnimation.pulseAnimation(layer, visualLayer: visualLayer, color: v.colorWithAlphaComponent(pulseOpacity), point: point, width: width, height: height, duration: duration, pulseLayer: pulseLayer)
} }
if pulseScale { if pulseScale {
......
...@@ -60,6 +60,9 @@ public class MaterialTableViewCell : UITableViewCell { ...@@ -60,6 +60,9 @@ public class MaterialTableViewCell : UITableViewCell {
/// The color of the pulse effect. /// The color of the pulse effect.
@IBInspectable public var pulseColor: UIColor? @IBInspectable public var pulseColor: UIColor?
/// Sets a pulse animation to always radiate from the center
@IBInspectable public var pulseCenter: Bool = false
/** /**
This property is the same as clipsToBounds. It crops any of the view's This property is the same as clipsToBounds. It crops any of the view's
contents from bleeding past the view's frame. If an image is set using contents from bleeding past the view's frame. If an image is set using
...@@ -397,7 +400,8 @@ public class MaterialTableViewCell : UITableViewCell { ...@@ -397,7 +400,8 @@ public class MaterialTableViewCell : UITableViewCell {
} }
if let v: UIColor = pulseColor { if let v: UIColor = pulseColor {
MaterialAnimation.pulseAnimation(layer, visualLayer: visualLayer, color: v.colorWithAlphaComponent(pulseOpacity), point: layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer), width: width, height: height, duration: duration, pulseLayer: pulseLayer) let point: CGPoint = pulseCenter ? CGPointMake(CGFloat(width / 2), CGFloat(height / 2)) : layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer)
MaterialAnimation.pulseAnimation(layer, visualLayer: visualLayer, color: v.colorWithAlphaComponent(pulseOpacity), point: point, width: width, height: height, duration: duration, pulseLayer: pulseLayer)
} }
if pulseScale { if pulseScale {
......
...@@ -314,13 +314,6 @@ public class TextField : UITextField { ...@@ -314,13 +314,6 @@ public class TextField : UITextField {
*/ */
@IBInspectable public var titleLabelAnimationDistance: CGFloat = 4 @IBInspectable public var titleLabelAnimationDistance: CGFloat = 4
/// An override to the text property.
@IBInspectable public override var text: String? {
didSet {
textFieldDidChange()
}
}
/** /**
The detail UILabel that is displayed when the detailLabelHidden property The detail UILabel that is displayed when the detailLabelHidden property
is set to false. is set to false.
...@@ -373,13 +366,31 @@ public class TextField : UITextField { ...@@ -373,13 +366,31 @@ public class TextField : UITextField {
} }
} }
/// An override to the text property.
@IBInspectable public override var text: String? {
didSet {
textFieldDidChange()
}
}
/// Sets the placeholder value. /// Sets the placeholder value.
@IBInspectable public override var placeholder: String? { @IBInspectable public override var placeholder: String? {
didSet { get {
if let v: String = placeholder { return editing ? nil : placeholderText
}
set(value) {
if let v: String = value {
placeholderText = v
attributedPlaceholder = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderTextColor]) attributedPlaceholder = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderTextColor])
} else {
super.placeholder = nil
if !editing {
placeholderText = nil
}
}
if 0 < text?.utf16.count {
titleLabel.text = placeholderText
} }
placeholderText = placeholder
} }
} }
...@@ -505,6 +516,11 @@ public class TextField : UITextField { ...@@ -505,6 +516,11 @@ public class TextField : UITextField {
addTarget(self, action: #selector(textFieldValueChanged), forControlEvents: .ValueChanged) addTarget(self, action: #selector(textFieldValueChanged), forControlEvents: .ValueChanged)
} }
/// Handler for text changed.
internal func textFieldDidChange() {
sendActionsForControlEvents(.ValueChanged)
}
/// Clears the textField text. /// Clears the textField text.
internal func handleClearButton() { internal func handleClearButton() {
if false == delegate?.textFieldShouldClear?(self) { if false == delegate?.textFieldShouldClear?(self) {
...@@ -524,21 +540,15 @@ public class TextField : UITextField { ...@@ -524,21 +540,15 @@ public class TextField : UITextField {
/// Handler for text editing began. /// Handler for text editing began.
internal func textFieldDidBegin() { internal func textFieldDidBegin() {
showTitleLabel() showTitleLabel()
placeholder = nil
titleLabel.textColor = titleLabelActiveColor titleLabel.textColor = titleLabelActiveColor
lineLayer.frame.size.height = lineLayerActiveThickness lineLayer.frame.size.height = lineLayerActiveThickness
lineLayer.backgroundColor = (detailLabelHidden ? nil == lineLayerActiveColor ? titleLabelActiveColor : lineLayerActiveColor : nil == lineLayerDetailActiveColor ? detailLabelActiveColor : lineLayerDetailActiveColor)?.CGColor lineLayer.backgroundColor = (detailLabelHidden ? nil == lineLayerActiveColor ? titleLabelActiveColor : lineLayerActiveColor : nil == lineLayerDetailActiveColor ? detailLabelActiveColor : lineLayerDetailActiveColor)?.CGColor
} }
/// Handler for text changed.
internal func textFieldDidChange() {
sendActionsForControlEvents(.ValueChanged)
}
/// Handler for text editing ended. /// Handler for text editing ended.
internal func textFieldDidEnd() { internal func textFieldDidEnd() {
if 0 < text?.utf16.count { if 0 == text?.utf16.count {
showTitleLabel()
} else if 0 == text?.utf16.count {
hideTitleLabel() hideTitleLabel()
} }
titleLabel.textColor = titleLabelColor titleLabel.textColor = titleLabelColor
...@@ -628,14 +638,10 @@ public class TextField : UITextField { ...@@ -628,14 +638,10 @@ public class TextField : UITextField {
/// Shows and animates the titleLabel property. /// Shows and animates the titleLabel property.
private func showTitleLabel() { private func showTitleLabel() {
if titleLabel.hidden { if titleLabel.hidden {
if let v: String = placeholder {
titleLabel.text = v
placeholderText = v
placeholder = nil
}
let h: CGFloat = ceil(titleLabel.font.lineHeight) let h: CGFloat = ceil(titleLabel.font.lineHeight)
titleLabel.frame = bounds titleLabel.frame = bounds
titleLabel.font = font titleLabel.font = font
titleLabel.text = placeholderText
titleLabel.hidden = false titleLabel.hidden = false
UIView.animateWithDuration(0.15, animations: { [weak self] in UIView.animateWithDuration(0.15, animations: { [weak self] in
if let v: TextField = self { if let v: TextField = self {
...@@ -656,8 +662,8 @@ public class TextField : UITextField { ...@@ -656,8 +662,8 @@ public class TextField : UITextField {
} }
}) { [weak self] _ in }) { [weak self] _ in
if let v: TextField = self { if let v: TextField = self {
v.placeholder = v.placeholderText
v.titleLabel.hidden = true v.titleLabel.hidden = true
v.placeholder = v.placeholderText
} }
} }
} }
......
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