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

UL&S: SiteCredentialsViewController username and password fields #329

Merged
merged 35 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
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 Jul 9, 2020
31273c8
Set label to word wrap
mindgraffiti Jul 9, 2020
fc80cbc
Add a display string for the site address flow step 2 instructions
mindgraffiti Jul 9, 2020
b30d791
Use the new display string
mindgraffiti Jul 9, 2020
e99a5e5
Forgot to add a period at the end of the sentence
mindgraffiti Jul 9, 2020
1897f4e
Add the username placeholder to display strings
mindgraffiti Jul 9, 2020
f6eda09
Add the username case and set the keyboard type
mindgraffiti Jul 9, 2020
7988301
Add the username textfield to the SiteCredentials VC
mindgraffiti Jul 9, 2020
3aebf50
Add the firstTextField property to keep a reference to the active tex…
mindgraffiti Jul 9, 2020
ae24fc9
Merge branch 'develop' into feature/322-site-credentials-i
mindgraffiti Jul 9, 2020
ba819b5
Bump podspec to 1.20.0-beta.8
mindgraffiti Jul 9, 2020
6622d65
Add NUXKeyboardResponder
mindgraffiti Jul 9, 2020
9cac35d
Save a reference to the username and password textfields
mindgraffiti Jul 9, 2020
bd62dbd
Make the username textfield the first responder
mindgraffiti Jul 9, 2020
502c117
Transition to password textfield as first responder after return key tap
mindgraffiti Jul 9, 2020
e45dac5
Add the username cell to the rows
mindgraffiti Jul 9, 2020
8317233
Change the keyboard `return` key to use `next` on username style
mindgraffiti Jul 9, 2020
9a98549
Add the password placeholder display string
mindgraffiti Jul 9, 2020
8181711
Add the password case to the Row enum
mindgraffiti Jul 9, 2020
8016a2a
Add the Log In title to the nav bar
mindgraffiti Jul 9, 2020
21635fa
Clear the textfield references after the tableview ends displaying cells
mindgraffiti Jul 9, 2020
72a0975
Clean up indentation
mindgraffiti Jul 9, 2020
f6b1ce9
Add the password textfield cell
mindgraffiti Jul 9, 2020
b97a933
Clean up the displayed site address
mindgraffiti Jul 9, 2020
3ede7f5
Set up the keyboard type and return key type for the password style
mindgraffiti Jul 9, 2020
7b87ce8
Merge branch 'develop' into feature/322-site-credentials-i
mindgraffiti Jul 20, 2020
a95217c
Update podspec version to 1.21.0-beta.2
mindgraffiti Jul 20, 2020
b735731
Set the secure text entry icon color
mindgraffiti Jul 20, 2020
37bbfe8
Implement secureTextEntry toggle button for passwords
mindgraffiti Jul 20, 2020
1dde2be
Leave the cursor blue, but the eye icon gray
mindgraffiti Jul 20, 2020
73dda96
Don't configure the Continue button yet
mindgraffiti Jul 21, 2020
f10acbe
Make the code more Swift-y and less Obj-C
mindgraffiti Jul 21, 2020
3cb289f
Remove bugfix for textfield font
mindgraffiti Jul 21, 2020
562bd67
Update podspec to version 1.21.0-beta.3
mindgraffiti Jul 21, 2020
6ef979e
Merge branch 'develop' into feature/322-site-credentials-i
mindgraffiti Jul 21, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion WordPressAuthenticator.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "WordPressAuthenticator"
s.version = "1.21.0-beta.1"
s.version = "1.21.0-beta.2"
s.summary = "WordPressAuthenticator implements an easy and elegant way to authenticate your WordPress Apps."

s.description = <<-DESC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public struct WordPressAuthenticatorDisplayStrings {
public let emailLoginInstructions: String
public let jetpackLoginInstructions: String
public let siteLoginInstructions: String
public let siteCredentialInstructions: String

/// Strings: primary call-to-action button titles.
///
Expand All @@ -25,26 +26,37 @@ public struct WordPressAuthenticatorDisplayStrings {
public let findSiteButtonTitle: String
public let resetPasswordButtonTitle: String

/// Placeholder text for textfields.
///
public let usernamePlaceholder: String
public let passwordPlaceholder: String

/// Designated initializer.
///
public init(emailLoginInstructions: String,
jetpackLoginInstructions: String,
siteLoginInstructions: String,
siteCredentialInstructions: String,
continueButtonTitle: String,
findSiteButtonTitle: String,
resetPasswordButtonTitle: String,
gettingStartedTitle: String,
logInTitle: String,
signUpTitle: String) {
signUpTitle: String,
usernamePlaceholder: String,
passwordPlaceholder: String) {
self.emailLoginInstructions = emailLoginInstructions
self.jetpackLoginInstructions = jetpackLoginInstructions
self.siteLoginInstructions = siteLoginInstructions
self.siteCredentialInstructions = siteCredentialInstructions
self.continueButtonTitle = continueButtonTitle
self.findSiteButtonTitle = findSiteButtonTitle
self.resetPasswordButtonTitle = resetPasswordButtonTitle
self.gettingStartedTitle = gettingStartedTitle
self.logInTitle = logInTitle
self.signUpTitle = signUpTitle
self.usernamePlaceholder = usernamePlaceholder
self.passwordPlaceholder = passwordPlaceholder
}
}

Expand All @@ -57,6 +69,8 @@ public extension WordPressAuthenticatorDisplayStrings {
comment: "Instruction text on the login's email address screen."),
siteLoginInstructions: NSLocalizedString("Enter the address of the WordPress site you'd like to connect.",
comment: "Instruction text on the login's site addresss screen."),
siteCredentialInstructions: NSLocalizedString("Enter your account information for %@.",
comment: "Enter your account information for {site url}. Asks the user to enter a username and password for their self-hosted site."),
continueButtonTitle: NSLocalizedString("Continue",
comment: "The button title text when there is a next step for logging in or signing up."),
findSiteButtonTitle: NSLocalizedString("Find your site address",
Expand All @@ -68,7 +82,11 @@ public extension WordPressAuthenticatorDisplayStrings {
logInTitle: NSLocalizedString("Log In",
comment: "View title during the log in process."),
signUpTitle: NSLocalizedString("Sign Up",
comment: "View title during the sign up process.")
comment: "View title during the sign up process."),
usernamePlaceholder: NSLocalizedString("Username",
comment: "Placeholder for the username textfield."),
passwordPlaceholder: NSLocalizedString("Password",
comment: "Placeholder for the password textfield.")
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
}
Copy link
Contributor

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?

guard showSecureTextEntryToggle else {
	return
}	

Copy link
Contributor Author

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 😀


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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is setting it to nil necessary since it's immediately followed by setting the font? I commented it out and didn't see a difference.

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 {

Expand All @@ -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.")

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="16097" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="16097.2" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="i98-6g-rDP" userLabel="text label">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="i98-6g-rDP" userLabel="text label">
<rect key="frame" x="16" y="11" width="288" height="22"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
Expand Down
Loading