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

[trello.com/c/G77vaoVI]: handle keyboard 'Go' button tap and start login instantly #639

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
65 changes: 60 additions & 5 deletions Adamant/Helpers/UITextField+adamant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,24 +144,32 @@ extension UITextField {
}

extension UITextField {

// MARK: - Password toggle button

func enablePasswordToggle() {
let button = UIButton(type: .custom)
updatePasswordToggleImage(button)
button.addTarget(self, action: #selector(togglePasswordView(_:)), for: .touchUpInside)
let button = makePasswordButton()

let contanerView = UIView()
contanerView.addSubview(button)
button.snp.makeConstraints { make in
make.directionalEdges.equalToSuperview().inset(3)
make.directionalEdges.equalToSuperview().inset(buttonContainerInset)
}
contanerView.snp.makeConstraints { make in
make.size.equalTo(28)
make.size.equalTo(buttonContainerHeight)
}

rightView = contanerView
rightViewMode = .always
}

private func makePasswordButton() -> UIButton {
let button = UIButton(type: .custom)
updatePasswordToggleImage(button)
button.addTarget(self, action: #selector(togglePasswordView(_:)), for: .touchUpInside)
return button
}

private func updatePasswordToggleImage(_ button: UIButton) {
let imageName = isSecureTextEntry ? "eye_close" : "eye_open"
button.setImage(.asset(named: imageName), for: .normal)
Expand All @@ -171,4 +179,51 @@ extension UITextField {
isSecureTextEntry.toggle()
updatePasswordToggleImage(sender)
}

// MARK: - Paste button and password toggle

func enablePasteButtonAndPasswordToggle() {
let passwordToggleButton = makePasswordButton()
let pasteButton = makePasteButton()

let contanerView = UIView()
let buttonStack = UIStackView(arrangedSubviews: [pasteButton, passwordToggleButton])
buttonStack.axis = .horizontal
buttonStack.spacing = 16 // to be discussed with designer
contanerView.addSubview(buttonStack)
buttonStack.snp.makeConstraints { make in
make.directionalEdges.equalToSuperview().inset(buttonContainerInset)
}

contanerView.snp.makeConstraints { make in
make.height.equalTo(buttonContainerHeight)
}

pasteButton.snp.makeConstraints { make in
make.width.equalTo(pasteButton.snp.height)
}

passwordToggleButton.snp.makeConstraints { make in
make.width.equalTo(passwordToggleButton.snp.height)
}

rightView = contanerView
rightViewMode = .always
}

private func makePasteButton() -> UIButton {
let button = UIButton(type: .custom)
button.setImage(.asset(named: "clipboard"), for: .normal)
button.addTarget(self, action: #selector(pasteFromPasteboard(_:)), for: .touchUpInside)
return button
}

@objc private func pasteFromPasteboard(_ sender: UIButton) {
if let pasteboardText = UIPasteboard.general.string {
self.text = pasteboardText
}
}

private var buttonContainerHeight: CGFloat { 28 }
private var buttonContainerInset: CGFloat { 3 }
}
13 changes: 12 additions & 1 deletion Adamant/Modules/Login/LoginViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ final class LoginViewController: FormViewController {
$0.tag = Rows.passphrase.tag
$0.placeholder = Rows.passphrase.localized
$0.placeholderColor = UIColor.adamant.secondary
$0.cell.textField.enablePasswordToggle()
$0.cell.textField.enablePasteButtonAndPasswordToggle()
$0.keyboardReturnType = KeyboardReturnTypeConfiguration(nextKeyboardType: .go, defaultKeyboardType: .go)
}

Expand Down Expand Up @@ -413,6 +413,17 @@ final class LoginViewController: FormViewController {
versionFooterView.sizeToFit()
}

// MARK: - FormViewController

override func textInputShouldReturn<T>(_ textInput: UITextInput, cell: Cell<T>) -> Bool {
let result = super.textInputShouldReturn(textInput, cell: cell)
if cell.row.tag == Rows.passphrase.tag, let passphrase = cell.row.value as? String {
loginWith(passphrase: passphrase)
}

return result
}

// MARK: - Other

private func setColors() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "clipboard.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
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.