-
-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy pathPasswordsViewController.swift
71 lines (57 loc) · 2.21 KB
/
PasswordsViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// PasswordsViewController.swift
// passAutoFillExtension
//
// Created by Sun, Mingshen on 12/31/20.
// Copyright © 2020 Bob Sun. All rights reserved.
//
import AuthenticationServices
import passKit
import UIKit
class PasswordsViewController: UIViewController {
@IBOutlet var tableView: UITableView!
var dataSource: PasswordsTableDataSource!
weak var selectionDelegate: PasswordSelectionDelegate?
lazy var searchController: UISearchController = {
let uiSearchController = UISearchController(searchResultsController: nil)
uiSearchController.searchBar.isTranslucent = true
uiSearchController.obscuresBackgroundDuringPresentation = false
uiSearchController.searchBar.sizeToFit()
uiSearchController.searchBar.searchTextField.clearButtonMode = .whileEditing
return uiSearchController
}()
lazy var searchBar: UISearchBar = self.searchController.searchBar
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = false
searchBar.delegate = self
tableView.delegate = self
tableView.dataSource = dataSource
}
func showPasswordsWithSuggestion(matching text: String) {
dataSource.showTableEntriesWithSuggestion(matching: text)
tableView.reloadData()
}
}
extension PasswordsViewController: UISearchBarDelegate {
func searchBar(_: UISearchBar, textDidChange searchText: String) {
dataSource.showTableEntries(matching: searchText)
tableView.reloadData()
}
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
searchBar.resignFirstResponder()
}
func searchBarCancelButtonClicked(_: UISearchBar) {
dataSource.showTableEntries(matching: "")
tableView.reloadData()
}
}
extension PasswordsViewController: UITableViewDelegate {
func tableView(_: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let entry = dataSource.tableEntry(at: indexPath)
UIImpactFeedbackGenerator(style: .medium).impactOccurred()
selectionDelegate?.selected(password: entry)
}
}