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

Added keyboard field navigation for username, password textfield in bookmark view #312

Merged
merged 4 commits into from
Mar 22, 2019
Merged
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
48 changes: 48 additions & 0 deletions ownCloud/Bookmarks/BookmarkViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,24 @@ class BookmarkViewController: StaticTableViewController {
var passwordRow : StaticTableViewRow?
var tokenInfoRow : StaticTableViewRow?
var deleteAuthDataButtonRow : StaticTableViewRow?
var activeTextField: UITextField?

lazy var continueBarButtonItem: UIBarButtonItem = UIBarButtonItem(title: "Continue".localized, style: .done, target: self, action: #selector(handleContinue))
lazy var saveBarButtonItem: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .save, target: self, action: #selector(BookmarkViewController.userActionSave))
lazy var nextBarButtonItem = UIBarButtonItem(image: UIImage(named: "arrow-down"), style: .plain, target: self, action: #selector(toogleTextField))
lazy var previousBarButtonItem = UIBarButtonItem(image: UIImage(named: "arrow-up"), style: .plain, target: self, action: #selector(toogleTextField))
lazy var inputToolbar: UIToolbar = {
var toolbar = UIToolbar()
toolbar.barStyle = .default
toolbar.isTranslucent = true
toolbar.sizeToFit()
let doneBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(resignTextField))
let flexibleSpaceBarButtonItem = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
let fixedSpaceBarButtonItem = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
toolbar.setItems([fixedSpaceBarButtonItem, previousBarButtonItem, fixedSpaceBarButtonItem, fixedSpaceBarButtonItem, nextBarButtonItem, flexibleSpaceBarButtonItem, doneBarButtonItem], animated: false)
toolbar.isUserInteractionEnabled = true
return toolbar
}()

// MARK: - Internal storage
var bookmark : OCBookmark?
Expand Down Expand Up @@ -727,6 +742,21 @@ class BookmarkViewController: StaticTableViewController {
func isAuthenticationMethodTokenBased(_ authenticationMethodIdentifier: OCAuthenticationMethodIdentifier) -> Bool {
return authenticationMethodTypeForIdentifier(authenticationMethodIdentifier) == OCAuthenticationMethodType.token
}

// MARK: - Keyboard AccessoryView
@objc func toogleTextField (_ sender: UIBarButtonItem) {
hosy marked this conversation as resolved.
Show resolved Hide resolved
if passwordRow?.textField?.isFirstResponder ?? false {
// Found next responder, so set it
usernameRow?.textField?.becomeFirstResponder()
} else {
// Not found, so remove keyboard
passwordRow?.textField?.becomeFirstResponder()
}
}

@objc func resignTextField (_ sender: UIBarButtonItem) {
activeTextField?.resignFirstResponder()
}
}

// MARK: - OCClassSettings support
Expand Down Expand Up @@ -759,6 +789,7 @@ extension BookmarkViewController : OCClassSettingsSupport {

// MARK: - Keyboard / return key tracking
extension BookmarkViewController : UITextFieldDelegate {

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
if self.navigationItem.rightBarButtonItem == continueBarButtonItem {
if !updateInputFocus() {
Expand All @@ -770,6 +801,23 @@ extension BookmarkViewController : UITextFieldDelegate {

return true
}

func textFieldDidBeginEditing(_ textField: UITextField) {
activeTextField = textField
if textField.isEqual(urlRow?.textField) {
textField.returnKeyType = .continue
} else if textField.isEqual(usernameRow?.textField) && passwordRow?.textField?.isEnabled ?? false {
previousBarButtonItem.isEnabled = false
nextBarButtonItem.isEnabled = true
textField.inputAccessoryView = inputToolbar
textField.returnKeyType = .next
} else if textField.isEqual(passwordRow?.textField) && usernameRow?.textField?.isEnabled ?? false {
previousBarButtonItem.isEnabled = true
nextBarButtonItem.isEnabled = false
textField.inputAccessoryView = inputToolbar
textField.returnKeyType = .continue
}
}
}

// MARK: - Password manager support
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "down 2.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
"images" : [
{
"idiom" : "universal",
"filename" : "checkmark.pdf"
"filename" : "up 2.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template",
"preserves-vector-representation" : true
}
}
Binary file not shown.
Binary file not shown.