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

Support Deselecting Tokens #244

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions FreeOTP/TokensViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,18 @@ class TokensViewController : UICollectionViewController, UICollectionViewDelegat
}
}
}

@objc func handleTap(gestureRecognizer: UITapGestureRecognizer) {
// Neccessary to prevent gesture recognizer from overriding default behavior,
// such as UICollectionView's `didSelectItemAt` delegate method.
gestureRecognizer.cancelsTouchesInView = false

// Deselect tokens when empty space in collection view is tapped.
let tapLocation = gestureRecognizer.location(in: view)
if collectionView.indexPathForItem(at: tapLocation) == nil {
reloadData()
}
}

@IBAction func unwindToTokens(_ sender: UIStoryboardSegue) {
reloadData()
Expand Down Expand Up @@ -311,6 +323,10 @@ class TokensViewController : UICollectionViewController, UICollectionViewDelegat
let swipeGesture = UISwipeGestureRecognizer(target: self, action: #selector(self.handleSwipe))
collectionView?.addGestureRecognizer(swipeGesture)

let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.handleTap))
tapGesture.numberOfTapsRequired = 1
collectionView?.addGestureRecognizer(tapGesture)

// show the search bar only if there are items to be searched
showSearchButton()

Expand Down