Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Commit

Permalink
* add visibility off material icon, toggle animation between visibili…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
Cristina committed Nov 22, 2017
1 parent 840dbdd commit 403fb7c
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
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" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions Sources/iOS/Icon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public struct Icon {
public static let starHalf = Icon.icon("ic_star_half_white")
public static let videocam = Icon.icon("ic_videocam_white")
public static let visibility = Icon.icon("ic_visibility_white")
public static let visibilityOff = Icon.icon("ic_visibility_off_white")
public static let work = Icon.icon("ic_work_white")

/// CosmicMind icons.
Expand Down
17 changes: 9 additions & 8 deletions Sources/iOS/TextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)!,
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)
}
}

Expand Down

0 comments on commit 403fb7c

Please sign in to comment.