Skip to content

Commit af3fee1

Browse files
committed
Support for LTR language
1 parent 19c933e commit af3fee1

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

TextFieldEffects/TextFieldEffects/KaedeTextField.swift

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,20 @@ import UIKit
8484
}
8585

8686
override open func animateViewsForTextEntry() {
87+
let directionOverride: CGFloat
88+
89+
if #available(iOS 9.0, *) {
90+
directionOverride = UIView.userInterfaceLayoutDirection(for: semanticContentAttribute) == .rightToLeft ? -1.0 : 1.0
91+
} else {
92+
directionOverride = 1.0
93+
}
94+
8795
UIView.animate(withDuration: 0.35, delay: 0.0, usingSpringWithDamping: 0.8, initialSpringVelocity: 2.0, options: .beginFromCurrentState, animations: ({
88-
self.placeholderLabel.frame.origin = CGPoint(x: self.frame.size.width * 0.65, y: self.placeholderInsets.y)
96+
self.placeholderLabel.frame.origin = CGPoint(x: self.frame.size.width * 0.65 * directionOverride, y: self.placeholderInsets.y)
8997
}), completion: nil)
9098

9199
UIView.animate(withDuration: 0.45, delay: 0.0, usingSpringWithDamping: 0.8, initialSpringVelocity: 1.5, options: .beginFromCurrentState, animations: ({
92-
self.foregroundView.frame.origin = CGPoint(x: self.frame.size.width * 0.6, y: 0)
100+
self.foregroundView.frame.origin = CGPoint(x: self.frame.size.width * 0.6 * directionOverride, y: 0)
93101
}), completion: { _ in
94102
self.animationCompletionHandler?(.textEntry)
95103
})
@@ -128,15 +136,19 @@ import UIKit
128136
// MARK: - Overrides
129137

130138
override open func editingRect(forBounds bounds: CGRect) -> CGRect {
131-
let frame = CGRect(origin: bounds.origin, size: CGSize(width: bounds.size.width * 0.6, height: bounds.size.height))
132-
139+
var frame = CGRect(origin: bounds.origin, size: CGSize(width: bounds.size.width * 0.6, height: bounds.size.height))
140+
141+
if #available(iOS 9.0, *) {
142+
if UIView.userInterfaceLayoutDirection(for: semanticContentAttribute) == .rightToLeft {
143+
frame.origin = CGPoint(x: bounds.size.width - frame.size.width, y: frame.origin.y)
144+
}
145+
}
146+
133147
return frame.insetBy(dx: textFieldInsets.x, dy: textFieldInsets.y)
134148
}
135149

136150
override open func textRect(forBounds bounds: CGRect) -> CGRect {
137-
let frame = CGRect(origin: bounds.origin, size: CGSize(width: bounds.size.width * 0.6, height: bounds.size.height))
138-
139-
return frame.insetBy(dx: textFieldInsets.x, dy: textFieldInsets.y)
151+
return editingRect(forBounds: bounds)
140152
}
141-
153+
142154
}

0 commit comments

Comments
 (0)