-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change TextField's visibility icon behaviour in order to match more Android EditText's one #979
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "ic_visibility_off_white.png", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "ic_visibility_off_white@2x.png", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "ic_visibility_off_white@3x.png", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -350,9 +350,9 @@ open class TextField: UITextField { | |
return | ||
} | ||
|
||
visibilityIconButton = IconButton(image: Icon.visibility, tintColor: placeholderNormalColor.withAlphaComponent(isSecureTextEntry ? 0.38 : 0.54)) | ||
visibilityIconButton = isSecureTextEntry ? IconButton(image: Icon.visibility, tintColor: placeholderNormalColor.withAlphaComponent(0.54)) : IconButton(image: Icon.visibilityOff, tintColor: placeholderNormalColor.withAlphaComponent(0.54)) | ||
visibilityIconButton!.contentEdgeInsetsPreset = .none | ||
visibilityIconButton!.pulseAnimation = .none | ||
visibilityIconButton!.pulseAnimation = .centerRadialBeyondBounds | ||
isSecureTextEntry = true | ||
clearButtonMode = .never | ||
rightViewMode = .whileEditing | ||
|
@@ -643,12 +643,13 @@ fileprivate extension TextField { | |
func handleVisibilityIconButton() { | ||
isSecureTextEntry = !isSecureTextEntry | ||
|
||
if !isSecureTextEntry { | ||
super.font = nil | ||
font = placeholderLabel.font | ||
} | ||
|
||
visibilityIconButton?.tintColor = visibilityIconButton?.tintColor.withAlphaComponent(isSecureTextEntry ? 0.38 : 0.54) | ||
UIView.transition(with: (visibilityIconButton?.imageView)!, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One more note, if the developer sets the tint color of the button, it will be changed here to the placeholder color. So this should handle that: animations: { [weak self] in
guard let `self` = self else {
return
}
guard let v = self.visibilityIconButton else {
return
}
v.image = self.isSecureTextEntry ? Icon.visibilityOff?.tint(with: v.tintColor.withAlphaComponent(0.54)) : Icon.visibility?.tint(with: v.tintColor.withAlphaComponent(0.54))
}, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right again! I'm sorry, I'm not much used to coding for public libraries ^^' There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You did great! It is my responsibility to massage it into the framework. Keep it coming ;) |
||
duration: 0.3, | ||
options: .transitionCrossDissolve, | ||
animations: { | ||
self.visibilityIconButton?.image = self.isSecureTextEntry ? Icon.visibilityOff?.tint(with: self.placeholderNormalColor.withAlphaComponent(0.54)) : Icon.visibility?.tint(with: self.placeholderNormalColor.withAlphaComponent(0.54)) | ||
}, | ||
completion: nil) | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a note, I updated this line to:
less code :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh! You're totally right!! Thanks a lot! :)