Commit 1185c534 by Daniel Dahan

development: fixed TextField placeholder animation and updated general code style

parent 8e4bfc89
...@@ -133,7 +133,7 @@ open class Button: UIButton { ...@@ -133,7 +133,7 @@ open class Button: UIButton {
*/ */
public convenience init(image: UIImage?) { public convenience init(image: UIImage?) {
self.init() self.init()
prepareWith(image: image, tintColor: nil) prepare(with: image, tintColor: nil)
} }
/** /**
...@@ -143,7 +143,7 @@ open class Button: UIButton { ...@@ -143,7 +143,7 @@ open class Button: UIButton {
*/ */
public convenience init(image: UIImage?, tintColor: UIColor?) { public convenience init(image: UIImage?, tintColor: UIColor?) {
self.init() self.init()
prepareWith(image: image, tintColor: tintColor) prepare(with: image, tintColor: tintColor)
} }
/** /**
...@@ -152,7 +152,7 @@ open class Button: UIButton { ...@@ -152,7 +152,7 @@ open class Button: UIButton {
*/ */
public convenience init(title: String?) { public convenience init(title: String?) {
self.init() self.init()
prepareWith(title: title, titleColor: nil) prepare(with: title, titleColor: nil)
} }
/** /**
...@@ -162,7 +162,7 @@ open class Button: UIButton { ...@@ -162,7 +162,7 @@ open class Button: UIButton {
*/ */
public convenience init(title: String?, titleColor: UIColor?) { public convenience init(title: String?, titleColor: UIColor?) {
self.init() self.init()
prepareWith(title: title, titleColor: titleColor) prepare(with: title, titleColor: titleColor)
} }
open override func layoutSublayers(of layer: CALayer) { open override func layoutSublayers(of layer: CALayer) {
...@@ -259,7 +259,7 @@ open class Button: UIButton { ...@@ -259,7 +259,7 @@ open class Button: UIButton {
- Parameter image: A UIImage. - Parameter image: A UIImage.
- Parameter tintColor: A UIColor. - Parameter tintColor: A UIColor.
*/ */
private func prepareWith(image: UIImage?, tintColor: UIColor?) { private func prepare(with image: UIImage?, tintColor: UIColor?) {
self.image = image self.image = image
self.tintColor = tintColor self.tintColor = tintColor
} }
...@@ -269,7 +269,7 @@ open class Button: UIButton { ...@@ -269,7 +269,7 @@ open class Button: UIButton {
- Parameter title: A String. - Parameter title: A String.
- Parameter titleColor: A UIColor. - Parameter titleColor: A UIColor.
*/ */
private func prepareWith(title: String?, titleColor: UIColor?) { private func prepare(with title: String?, titleColor: UIColor?) {
self.title = title self.title = title
self.titleColor = titleColor self.titleColor = titleColor
} }
......
...@@ -147,7 +147,7 @@ open class MaterialCollectionReusableView: UICollectionReusableView { ...@@ -147,7 +147,7 @@ open class MaterialCollectionReusableView: UICollectionReusableView {
} }
/// A preset wrapper around interimSpace. /// A preset wrapper around interimSpace.
open var interimSpacePreset: InterimSpacePreset = .none { open var interimSpacePreset = InterimSpacePreset.none {
didSet { didSet {
interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset) interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset)
} }
......
...@@ -62,7 +62,7 @@ open class CollectionView: UICollectionView { ...@@ -62,7 +62,7 @@ open class CollectionView: UICollectionView {
} }
/// A preset wrapper around interimSpace. /// A preset wrapper around interimSpace.
open var interimSpacePreset: InterimSpacePreset = .none { open var interimSpacePreset = InterimSpacePreset.none {
didSet { didSet {
interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset) interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset)
} }
......
...@@ -155,7 +155,7 @@ open class CollectionViewCell: UICollectionViewCell { ...@@ -155,7 +155,7 @@ open class CollectionViewCell: UICollectionViewCell {
} }
/// A preset wrapper around interimSpace. /// A preset wrapper around interimSpace.
open var interimSpacePreset: InterimSpacePreset = .none { open var interimSpacePreset = InterimSpacePreset.none {
didSet { didSet {
interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset) interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset)
} }
......
...@@ -60,7 +60,7 @@ open class CollectionViewLayout: UICollectionViewLayout { ...@@ -60,7 +60,7 @@ open class CollectionViewLayout: UICollectionViewLayout {
open var scrollDirection: UICollectionViewScrollDirection = .vertical open var scrollDirection: UICollectionViewScrollDirection = .vertical
/// A preset wrapper around interimSpace. /// A preset wrapper around interimSpace.
open var interimSpacePreset: InterimSpacePreset = .none { open var interimSpacePreset = InterimSpacePreset.none {
didSet { didSet {
interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset) interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset)
} }
......
...@@ -58,7 +58,7 @@ open class ControlView: View { ...@@ -58,7 +58,7 @@ open class ControlView: View {
} }
/// A preset wrapper around interimSpace. /// A preset wrapper around interimSpace.
open var interimSpacePreset: InterimSpacePreset = .none { open var interimSpacePreset = InterimSpacePreset.none {
didSet { didSet {
interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset) interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset)
} }
......
...@@ -159,7 +159,7 @@ public class Grid { ...@@ -159,7 +159,7 @@ public class Grid {
} }
/// A preset wrapper for interim space. /// A preset wrapper for interim space.
public var interimSpacePreset: InterimSpacePreset = .none { public var interimSpacePreset = InterimSpacePreset.none {
didSet { didSet {
interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset) interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset)
} }
......
...@@ -50,7 +50,7 @@ public class Menu { ...@@ -50,7 +50,7 @@ public class Menu {
} }
/// A preset wrapper around interimSpace. /// A preset wrapper around interimSpace.
public var interimSpacePreset: InterimSpacePreset = .none { public var interimSpacePreset = InterimSpacePreset.none {
didSet { didSet {
interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset) interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset)
} }
......
...@@ -41,7 +41,7 @@ open class TabBar: View { ...@@ -41,7 +41,7 @@ open class TabBar: View {
open internal(set) var line: UIView! open internal(set) var line: UIView!
/// A value for the line alignment. /// A value for the line alignment.
open var lineAlignment: TabBarLineAlignment = .bottom { open var lineAlignment = TabBarLineAlignment.bottom {
didSet { didSet {
layoutSubviews() layoutSubviews()
} }
...@@ -74,7 +74,7 @@ open class TabBar: View { ...@@ -74,7 +74,7 @@ open class TabBar: View {
} }
/// A preset wrapper around interimSpace. /// A preset wrapper around interimSpace.
open var interimSpacePreset: InterimSpacePreset = .none { open var interimSpacePreset = InterimSpacePreset.none {
didSet { didSet {
interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset) interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset)
} }
...@@ -96,19 +96,16 @@ open class TabBar: View { ...@@ -96,19 +96,16 @@ open class TabBar: View {
} }
/// Buttons. /// Buttons.
open var buttons: [UIButton]? { open var buttons = [UIButton]() {
didSet { didSet {
if let v: [UIButton] = oldValue { for b in oldValue {
for b in v { b.removeFromSuperview()
b.removeFromSuperview() }
}
}
if let v: [UIButton] = buttons { for b in buttons {
for b in v { addSubview(b)
addSubview(b) }
}
}
layoutSubviews() layoutSubviews()
} }
} }
...@@ -116,20 +113,18 @@ open class TabBar: View { ...@@ -116,20 +113,18 @@ open class TabBar: View {
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if willRenderView { if willRenderView {
if let v = buttons { if 0 < buttons.count {
if 0 < v.count { let columns: Int = grid.axis.columns / buttons.count
let columns: Int = grid.axis.columns / v.count for b in buttons {
for b in v { b.grid.columns = columns
b.grid.columns = columns b.contentEdgeInsets = .zero
b.contentEdgeInsets = .zero b.layer.cornerRadius = 0
b.layer.cornerRadius = 0 b.removeTarget(self, action: #selector(handleButton(button:)), for: .touchUpInside)
b.removeTarget(self, action: #selector(handleButton(button:)), for: .touchUpInside) b.addTarget(self, action: #selector(handleButton(button:)), for: .touchUpInside)
b.addTarget(self, action: #selector(handleButton(button:)), for: .touchUpInside) }
} grid.views = buttons as [UIView]
grid.views = v as [UIView] line.frame = CGRect(x: 0, y: .bottom == lineAlignment ? height - 3 : 0, width: buttons.first!.width, height: 3)
line.frame = CGRect(x: 0, y: .bottom == lineAlignment ? height - 3 : 0, width: v.first!.frame.width, height: 3) }
}
}
} }
} }
...@@ -138,8 +133,8 @@ open class TabBar: View { ...@@ -138,8 +133,8 @@ open class TabBar: View {
internal func handleButton(button: UIButton) { internal func handleButton(button: UIButton) {
UIView.animate(withDuration: 0.25, animations: { [weak self] in UIView.animate(withDuration: 0.25, animations: { [weak self] in
if let s = self { if let s = self {
s.line.frame.origin.x = button.frame.origin.x s.line.x = button.x
s.line.frame.size.width = button.frame.size.width s.line.width = button.width
} }
}) })
} }
......
...@@ -274,6 +274,17 @@ open class TextField: UITextField { ...@@ -274,6 +274,17 @@ open class TextField: UITextField {
/// A reference to the visibilityIconButton. /// A reference to the visibilityIconButton.
open private(set) var visibilityIconButton: IconButton? open private(set) var visibilityIconButton: IconButton?
/**
`layoutIfNeeded` is called within `becomeFirstResponder` to
fix an issue that when the TextField calls `becomeFirstResponder`
immediately when launching an instance, the TextField is not
calculated correctly.
*/
open override func becomeFirstResponder() -> Bool {
layoutIfNeeded()
return super.becomeFirstResponder()
}
/** /**
An initializer that initializes the object with a NSCoder object. An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance. - Parameter aDecoder: A NSCoder instance.
...@@ -314,7 +325,6 @@ open class TextField: UITextField { ...@@ -314,7 +325,6 @@ open class TextField: UITextField {
/// Handles the text editing did begin state. /// Handles the text editing did begin state.
open func handleEditingDidBegin() { open func handleEditingDidBegin() {
layoutIfNeeded()
dividerEditingDidBeginAnimation() dividerEditingDidBeginAnimation()
placeholderEditingDidBeginAnimation() placeholderEditingDidBeginAnimation()
} }
......
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