-
Notifications
You must be signed in to change notification settings - Fork 11
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
UL&S: SiteCredentialsViewController username and password fields #329
Merged
Merged
Changes from 30 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
b6a4624
Bump podspec to 1.20.0-beta.7
mindgraffiti 31273c8
Set label to word wrap
mindgraffiti fc80cbc
Add a display string for the site address flow step 2 instructions
mindgraffiti b30d791
Use the new display string
mindgraffiti e99a5e5
Forgot to add a period at the end of the sentence
mindgraffiti 1897f4e
Add the username placeholder to display strings
mindgraffiti f6eda09
Add the username case and set the keyboard type
mindgraffiti 7988301
Add the username textfield to the SiteCredentials VC
mindgraffiti 3aebf50
Add the firstTextField property to keep a reference to the active tex…
mindgraffiti ae24fc9
Merge branch 'develop' into feature/322-site-credentials-i
mindgraffiti ba819b5
Bump podspec to 1.20.0-beta.8
mindgraffiti 6622d65
Add NUXKeyboardResponder
mindgraffiti 9cac35d
Save a reference to the username and password textfields
mindgraffiti bd62dbd
Make the username textfield the first responder
mindgraffiti 502c117
Transition to password textfield as first responder after return key tap
mindgraffiti e45dac5
Add the username cell to the rows
mindgraffiti 8317233
Change the keyboard `return` key to use `next` on username style
mindgraffiti 9a98549
Add the password placeholder display string
mindgraffiti 8181711
Add the password case to the Row enum
mindgraffiti 8016a2a
Add the Log In title to the nav bar
mindgraffiti 21635fa
Clear the textfield references after the tableview ends displaying cells
mindgraffiti 72a0975
Clean up indentation
mindgraffiti f6b1ce9
Add the password textfield cell
mindgraffiti b97a933
Clean up the displayed site address
mindgraffiti 3ede7f5
Set up the keyboard type and return key type for the password style
mindgraffiti 7b87ce8
Merge branch 'develop' into feature/322-site-credentials-i
mindgraffiti a95217c
Update podspec version to 1.21.0-beta.2
mindgraffiti b735731
Set the secure text entry icon color
mindgraffiti 37bbfe8
Implement secureTextEntry toggle button for passwords
mindgraffiti 1dde2be
Leave the cursor blue, but the eye icon gray
mindgraffiti 73dda96
Don't configure the Continue button yet
mindgraffiti f10acbe
Make the code more Swift-y and less Obj-C
mindgraffiti 3cb289f
Remove bugfix for textfield font
mindgraffiti 562bd67
Update podspec to version 1.21.0-beta.3
mindgraffiti 6ef979e
Merge branch 'develop' into feature/322-site-credentials-i
mindgraffiti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,18 +5,27 @@ import UIKit | |
/// | ||
final class TextFieldTableViewCell: UITableViewCell { | ||
|
||
/// Private properties | ||
/// Private properties. | ||
/// | ||
@IBOutlet private weak var borderView: UIView! | ||
@IBOutlet private weak var borderWidth: NSLayoutConstraint! | ||
private var secureTextEntryToggle: UIButton? | ||
private var secureTextEntryImageVisible: UIImage? | ||
private var secureTextEntryImageHidden: UIImage? | ||
|
||
private var hairlineBorderWidth: CGFloat { | ||
return 1.0 / UIScreen.main.scale | ||
} | ||
|
||
/// Public properties | ||
/// Public properties. | ||
/// | ||
@IBOutlet public weak var textField: UITextField! // public so it can be the first responder | ||
@IBInspectable public var showSecureTextEntryToggle: Bool = false { | ||
didSet { | ||
configureSecureTextEntryToggle() | ||
} | ||
} | ||
|
||
public static let reuseIdentifier = "TextFieldTableViewCell" | ||
|
||
override func awakeFromNib() { | ||
|
@@ -52,23 +61,96 @@ private extension TextFieldTableViewCell { | |
func setCommonTextFieldStyles() { | ||
textField.font = UIFont.preferredFont(forTextStyle: .body) | ||
textField.autocorrectionType = .no | ||
textField.returnKeyType = .continue | ||
} | ||
|
||
/// Sets the textfield keyboard type and applies common traits. | ||
/// - note: Don't assign first responder here. It's too early in the view lifecycle. | ||
/// | ||
func applyTextFieldStyle(_ style: TextFieldStyle) { | ||
switch style { | ||
switch style { | ||
case .url: | ||
textField.keyboardType = .URL | ||
default: | ||
setCommonTextFieldStyles() | ||
textField.returnKeyType = .continue | ||
case .username: | ||
textField.keyboardType = .default | ||
textField.returnKeyType = .next | ||
case .password: | ||
textField.keyboardType = .default | ||
textField.returnKeyType = .continue | ||
setSecureTextEntry(true) | ||
showSecureTextEntryToggle = true | ||
configureSecureTextEntryToggle() | ||
} | ||
} | ||
} | ||
|
||
|
||
// MARK: - Secure Text Entry | ||
/// Methods ported from WPWalkthroughTextField.h/.m | ||
/// | ||
private extension TextFieldTableViewCell { | ||
|
||
/// Build the show / hide icon in the textfield. | ||
/// | ||
func configureSecureTextEntryToggle() { | ||
if showSecureTextEntryToggle == false { | ||
return | ||
} | ||
|
||
secureTextEntryImageVisible = UIImage.gridicon(.visible) | ||
secureTextEntryImageHidden = UIImage.gridicon(.notVisible) | ||
|
||
secureTextEntryToggle = UIButton(type: .custom) | ||
secureTextEntryToggle?.clipsToBounds = true | ||
// The icon should match the border color. | ||
let tintColor = WordPressAuthenticator.shared.unifiedStyle?.borderColor ?? WordPressAuthenticator.shared.style.primaryNormalBorderColor | ||
secureTextEntryToggle?.tintColor = tintColor | ||
|
||
secureTextEntryToggle?.addTarget(self, | ||
action: #selector(secureTextEntryToggleAction), | ||
for: .touchUpInside) | ||
|
||
updateSecureTextEntryToggleImage() | ||
updateSecureTextEntryForAccessibility() | ||
textField.rightView = secureTextEntryToggle | ||
textField.rightViewMode = .always | ||
} | ||
|
||
func setSecureTextEntry(_ secureTextEntry: Bool) { | ||
// This is a fix for a bug where the text field reverts to a system | ||
// serif font if you disable secure text entry while it contains text. | ||
textField.font = nil | ||
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. Is setting it to |
||
textField.font = UIFont.preferredFont(forTextStyle: .body) | ||
|
||
textField.isSecureTextEntry = secureTextEntry | ||
updateSecureTextEntryToggleImage() | ||
updateSecureTextEntryForAccessibility() | ||
} | ||
|
||
@objc func secureTextEntryToggleAction(_ sender: Any) { | ||
textField.isSecureTextEntry = !textField.isSecureTextEntry | ||
|
||
// Save and re-apply the current selection range to save the cursor position | ||
let currentTextRange = textField.selectedTextRange | ||
textField.becomeFirstResponder() | ||
textField.selectedTextRange = currentTextRange | ||
updateSecureTextEntryToggleImage() | ||
updateSecureTextEntryForAccessibility() | ||
} | ||
|
||
func updateSecureTextEntryToggleImage() { | ||
let image = textField.isSecureTextEntry ? secureTextEntryImageHidden : secureTextEntryImageVisible | ||
secureTextEntryToggle?.setImage(image, for: .normal) | ||
secureTextEntryToggle?.sizeToFit() | ||
} | ||
|
||
func updateSecureTextEntryForAccessibility() { | ||
secureTextEntryToggle?.accessibilityLabel = Constants.showPassword | ||
secureTextEntryToggle?.accessibilityValue = textField.isSecureTextEntry ? Constants.passwordHidden : Constants.passwordShown | ||
} | ||
} | ||
|
||
|
||
// MARK: - Constants | ||
extension TextFieldTableViewCell { | ||
|
||
|
@@ -79,4 +161,16 @@ extension TextFieldTableViewCell { | |
case username | ||
case password | ||
} | ||
|
||
struct Constants { | ||
/// Accessibility Hints | ||
/// | ||
static let passwordHidden = NSLocalizedString("Hidden", | ||
comment: "Accessibility value if login page's password field is hiding the password (i.e. with asterisks).") | ||
static let passwordShown = NSLocalizedString("Shown", | ||
comment: "Accessibility value if login page's password field is displaying the password.") | ||
static let showPassword = NSLocalizedString("Show password", | ||
comment:"Accessibility label for the 'Show password' button in the login page's password field.") | ||
|
||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
WordPressAuthenticator/Unified Auth/View Related/Reusable Views/TextFieldTableViewCell.xib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Just a suggestion - maybe this could be a
guard
?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.
Thanks! I converted the Obj-C class
WPWalkthroughTextField
into Swift and forgot to make the code actually Swift-y 😀