-
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
Change TextField's visibility icon behaviour in order to match more Android EditText's one #979
Conversation
artemisia-absynthium
commented
Nov 22, 2017
•
edited
Loading
edited
- Add visibility off material icon, toggle animation between visibility on and off icons and ripple, much more similar to Android's original EditText
- Remove font change because it would eliminate any custom font when changing visibility the first time
…ty on and off icons and ripple, much more similar to Android's original EditText * remove font change because it would eliminate any custom font when changing visibility the first time
@@ -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)) |
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:
IconButton(image: isSecureTextEntry ? Icon.visibility : Icon.visibilityOff, tintColor: placeholderNormalColor.withAlphaComponent(0.54))
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! :)
} | ||
|
||
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 comment
The 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 comment
The 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 ^^'
Anyway, I think that the two icons are inverted in this snippet.
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.
You did great! It is my responsibility to massage it into the framework. Keep it coming ;)