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