Skip to content
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

Merged
merged 1 commit into from
Nov 22, 2017
Merged

Conversation

artemisia-absynthium
Copy link

@artemisia-absynthium artemisia-absynthium commented Nov 22, 2017

  • 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
@artemisia-absynthium artemisia-absynthium changed the title Change visibility icon behaviour in order to match more Android EditText's one Change TextField's visibility icon behaviour in order to match more Android EditText's one Nov 22, 2017
@daniel-jonathan daniel-jonathan self-requested a review November 22, 2017 16:25
@daniel-jonathan daniel-jonathan self-assigned this Nov 22, 2017
@daniel-jonathan daniel-jonathan merged commit df8dd2b into CosmicMind:development Nov 22, 2017
@@ -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))
Copy link
Member

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 :)

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)!,
Copy link
Member

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))
                            
                          },

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.

Copy link
Member

@daniel-jonathan daniel-jonathan Nov 22, 2017

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 ;)

@artemisia-absynthium artemisia-absynthium deleted the development branch December 21, 2017 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants