Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AnimatedTextInput.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -330,7 +330,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.jobandtalent.AnimatedTextInput;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
2 changes: 1 addition & 1 deletion AnimatedTextInput/Classes/AnimatedLine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ open class AnimatedLine: UIView {
}

fileprivate func animateLine(to value: CGFloat) {
let function = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
let function = CAMediaTimingFunction(name: .easeInEaseOut)
transactionAnimation(with: animationDuration, timingFuncion: function) {
self.lineLayer.strokeEnd = value
}
Expand Down
8 changes: 4 additions & 4 deletions AnimatedTextInput/Classes/AnimatedTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final public class AnimatedTextField: UITextField {
var rightViewPadding: CGFloat
weak public var textInputDelegate: TextInputDelegate?

public var textAttributes: [NSAttributedStringKey: Any]?
public var textAttributes: [NSAttributedString.Key: Any]?
public var contentInset: UIEdgeInsets = .zero

fileprivate var disclosureButtonAction: (() -> Void)?
Expand Down Expand Up @@ -43,7 +43,7 @@ final public class AnimatedTextField: UITextField {
}

@discardableResult override public func becomeFirstResponder() -> Bool {
if let alignment = (textAttributes?[NSAttributedStringKey.paragraphStyle] as? NSMutableParagraphStyle)?.alignment {
if let alignment = (textAttributes?[.paragraphStyle] as? NSMutableParagraphStyle)?.alignment {
textAlignment = alignment
}
return super.becomeFirstResponder()
Expand Down Expand Up @@ -124,7 +124,7 @@ extension AnimatedTextField: TextInput {
return position(from: from, offset: offset)
}

public func changeClearButtonMode(with newClearButtonMode: UITextFieldViewMode) {
public func changeClearButtonMode(with newClearButtonMode: UITextField.ViewMode) {
clearButtonMode = newClearButtonMode
}

Expand All @@ -138,7 +138,7 @@ extension AnimatedTextField: TextInput {
set { self.selectedTextRange = newValue }
}

open var currentBeginningOfDocument: UITextPosition? {
public var currentBeginningOfDocument: UITextPosition? {
get { return self.beginningOfDocument }
}
}
Expand Down
48 changes: 24 additions & 24 deletions AnimatedTextInput/Classes/AnimatedTextInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ open class AnimatedTextInput: UIControl {
}
}

open var clearButtonMode: UITextFieldViewMode = .whileEditing {
open var clearButtonMode: UITextField.ViewMode = .whileEditing {
didSet {
textInput.changeClearButtonMode(with: clearButtonMode)
}
Expand All @@ -44,7 +44,7 @@ open class AnimatedTextInput: UIControl {

open var placeholderAlignment: CATextLayer.Alignment = .natural {
didSet {
placeholderLayer.alignmentMode = String(describing: placeholderAlignment)
placeholderLayer.alignmentMode = CATextLayerAlignmentMode(rawValue: String(describing: placeholderAlignment))
}
}

Expand Down Expand Up @@ -75,67 +75,67 @@ open class AnimatedTextInput: UIControl {

open var font: UIFont? {
get { return textInput.font }
set { textAttributes = [NSAttributedStringKey.font: newValue as Any] }
set { textAttributes = [.font: newValue as Any] }
}

open var textColor: UIColor? {
get { return textInput.textColor }
set { textAttributes = [NSAttributedStringKey.foregroundColor: newValue as Any] }
set { textAttributes = [.foregroundColor: newValue as Any] }
}

open var lineSpacing: CGFloat? {
get {
guard let paragraph = textAttributes?[NSAttributedStringKey.paragraphStyle] as? NSParagraphStyle else { return nil }
guard let paragraph = textAttributes?[.paragraphStyle] as? NSParagraphStyle else { return nil }
return paragraph.lineSpacing
}
set {
guard let spacing = newValue else { return }
let paragraphStyle = textAttributes?[NSAttributedStringKey.paragraphStyle] as? NSMutableParagraphStyle ?? NSMutableParagraphStyle()
let paragraphStyle = textAttributes?[.paragraphStyle] as? NSMutableParagraphStyle ?? NSMutableParagraphStyle()
paragraphStyle.lineSpacing = spacing
textAttributes = [NSAttributedStringKey.paragraphStyle: paragraphStyle]
textAttributes = [.paragraphStyle: paragraphStyle]
}
}

open var textAlignment: NSTextAlignment? {
get {
guard let paragraph = textInput.textAttributes?[NSAttributedStringKey.paragraphStyle] as? NSParagraphStyle else { return nil }
guard let paragraph = textInput.textAttributes?[.paragraphStyle] as? NSParagraphStyle else { return nil }
return paragraph.alignment
}
set {
guard let alignment = newValue else { return }
let paragraphStyle = textAttributes?[NSAttributedStringKey.paragraphStyle] as? NSMutableParagraphStyle ?? NSMutableParagraphStyle()
let paragraphStyle = textAttributes?[.paragraphStyle] as? NSMutableParagraphStyle ?? NSMutableParagraphStyle()
paragraphStyle.alignment = alignment
textAttributes = [NSAttributedStringKey.paragraphStyle: paragraphStyle]
textAttributes = [.paragraphStyle: paragraphStyle]
}
}

open var tailIndent: CGFloat? {
get {
guard let paragraph = textAttributes?[NSAttributedStringKey.paragraphStyle] as? NSParagraphStyle else { return nil }
guard let paragraph = textAttributes?[.paragraphStyle] as? NSParagraphStyle else { return nil }
return paragraph.tailIndent
}
set {
guard let indent = newValue else { return }
let paragraphStyle = textAttributes?[NSAttributedStringKey.paragraphStyle] as? NSMutableParagraphStyle ?? NSMutableParagraphStyle()
let paragraphStyle = textAttributes?[.paragraphStyle] as? NSMutableParagraphStyle ?? NSMutableParagraphStyle()
paragraphStyle.tailIndent = indent
textAttributes = [NSAttributedStringKey.paragraphStyle: paragraphStyle]
textAttributes = [.paragraphStyle: paragraphStyle]
}
}

open var headIndent: CGFloat? {
get {
guard let paragraph = textAttributes?[NSAttributedStringKey.paragraphStyle] as? NSParagraphStyle else { return nil }
guard let paragraph = textAttributes?[.paragraphStyle] as? NSParagraphStyle else { return nil }
return paragraph.headIndent
}
set {
guard let indent = newValue else { return }
let paragraphStyle = textAttributes?[NSAttributedStringKey.paragraphStyle] as? NSMutableParagraphStyle ?? NSMutableParagraphStyle()
let paragraphStyle = textAttributes?[.paragraphStyle] as? NSMutableParagraphStyle ?? NSMutableParagraphStyle()
paragraphStyle.headIndent = indent
textAttributes = [NSAttributedStringKey.paragraphStyle: paragraphStyle]
textAttributes = [.paragraphStyle: paragraphStyle]
}
}

open var textAttributes: [NSAttributedStringKey: Any]? {
open var textAttributes: [NSAttributedString.Key: Any]? {
didSet {
guard var textInputAttributes = textInput.textAttributes else {
textInput.textAttributes = textAttributes
Expand Down Expand Up @@ -214,7 +214,7 @@ open class AnimatedTextInput: UIControl {

override open var intrinsicContentSize: CGSize {
let normalHeight = textInput.view.intrinsicContentSize.height
return CGSize(width: UIViewNoIntrinsicMetric, height: normalHeight + style.topMargin + style.bottomMargin)
return CGSize(width: UIView.noIntrinsicMetric, height: normalHeight + style.topMargin + style.bottomMargin)
}

open override func updateConstraints() {
Expand Down Expand Up @@ -272,8 +272,8 @@ open class AnimatedTextInput: UIControl {
placeholderLayer.masksToBounds = false
placeholderLayer.string = placeHolderText
placeholderLayer.foregroundColor = style.placeholderInactiveColor.cgColor
placeholderLayer.fontSize = style.textInputFont.pointSize
placeholderLayer.font = style.textInputFont
placeholderLayer.fontSize = style.placeHolderFont.pointSize
placeholderLayer.font = style.placeHolderFont
placeholderLayer.contentsScale = UIScreen.main.scale
placeholderLayer.backgroundColor = UIColor.clear.cgColor
layoutPlaceholderLayer()
Expand Down Expand Up @@ -323,7 +323,7 @@ open class AnimatedTextInput: UIControl {

fileprivate func configurePlaceholderAsDefault() {
isPlaceholderAsHint = false
configurePlaceholderWith(fontSize: style.textInputFont.pointSize,
configurePlaceholderWith(fontSize: style.placeHolderFont.pointSize,
foregroundColor: style.placeholderInactiveColor.cgColor,
text: placeHolderText)
lineView.animateToInitialState()
Expand Down Expand Up @@ -363,7 +363,7 @@ open class AnimatedTextInput: UIControl {
fileprivate func styleDidChange() {
lineView.defaultColor = style.lineInactiveColor
placeholderLayer.foregroundColor = style.placeholderInactiveColor.cgColor
let fontSize = style.textInputFont.pointSize
let fontSize = style.placeHolderFont.pointSize
placeholderLayer.fontSize = fontSize
placeholderLayer.font = style.textInputFont
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review your code, you missed this one:

placeholderLayer.font = style.placeHolderFont

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

textInput.view.tintColor = style.activeColor
Expand Down Expand Up @@ -554,7 +554,7 @@ public protocol TextInput {
var currentText: String? { get set }
var font: UIFont? { get set }
var textColor: UIColor? { get set }
var textAttributes: [NSAttributedStringKey: Any]? { get set }
var textAttributes: [NSAttributedString.Key: Any]? { get set }
weak var textInputDelegate: TextInputDelegate? { get set }
var currentSelectedTextRange: UITextRange? { get set }
var currentBeginningOfDocument: UITextPosition? { get }
Expand All @@ -563,7 +563,7 @@ public protocol TextInput {
func configureInputView(newInputView: UIView)
func changeReturnKeyType(with newReturnKeyType: UIReturnKeyType)
func currentPosition(from: UITextPosition, offset: Int) -> UITextPosition?
func changeClearButtonMode(with newClearButtonMode: UITextFieldViewMode)
func changeClearButtonMode(with newClearButtonMode: UITextField.ViewMode)
}

public extension TextInput where Self: UIView {
Expand Down
2 changes: 2 additions & 0 deletions AnimatedTextInput/Classes/AnimatedTextInputStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public protocol AnimatedTextInputStyle {
var lineHeight: CGFloat { get }
var errorColor: UIColor { get }
var textInputFont: UIFont { get }
var placeHolderFont: UIFont { get }
var textInputFontColor: UIColor { get }
var placeholderMinFontSize: CGFloat { get }
var counterLabelFont: UIFont? { get }
Expand All @@ -31,6 +32,7 @@ public struct AnimatedTextInputStyleBlue: AnimatedTextInputStyle {
public let lineHeight: CGFloat = 1.0 / UIScreen.main.scale
public let errorColor = UIColor.red
public let textInputFont = UIFont.systemFont(ofSize: 14)
public let placeHolderFont = UIFont.systemFont(ofSize: 14)
public let textInputFontColor = UIColor.black
public let placeholderMinFontSize: CGFloat = 9
public let counterLabelFont: UIFont? = UIFont.systemFont(ofSize: 9)
Expand Down
10 changes: 5 additions & 5 deletions AnimatedTextInput/Classes/AnimatedTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import UIKit

final public class AnimatedTextView: UITextView {

public var textAttributes: [NSAttributedStringKey: Any]? {
public var textAttributes: [NSAttributedString.Key: Any]? {
didSet {
guard let attributes = textAttributes else { return }
typingAttributes = Dictionary(uniqueKeysWithValues: attributes.lazy.map { ($0.key.rawValue, $0.value) })
typingAttributes = Dictionary(uniqueKeysWithValues: attributes.lazy.map { ($0.key, $0.value) })
}
}

public override var font: UIFont? {
didSet {
var attributes = typingAttributes
attributes[NSAttributedStringKey.font.rawValue] = font
textAttributes = Dictionary(uniqueKeysWithValues: attributes.lazy.map { (NSAttributedStringKey($0.key), $0.value)})
attributes[.font] = font
textAttributes = Dictionary(uniqueKeysWithValues: attributes.lazy.map { ($0.key, $0.value)})
}
}

Expand Down Expand Up @@ -68,7 +68,7 @@ extension AnimatedTextView: TextInput {
return position(from: from, offset: offset)
}

public func changeClearButtonMode(with newClearButtonMode: UITextFieldViewMode) {}
public func changeClearButtonMode(with newClearButtonMode: UITextField.ViewMode) {}

}

Expand Down