Skip to content

Commit d28661d

Browse files
LucasVieiraalucas vieira
and
lucas vieira
authored
✨ feat: add navigation-bar (#198)
Co-authored-by: lucas vieira <lucasgomes114@gmai.com>
1 parent 488c8a2 commit d28661d

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

solutions/devsprint-matheus-reis-8/GitHubApp/Screens/List/ListViewController.swift

+28-9
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,60 @@ import UIKit
99
final class ListViewController: UIViewController {
1010

1111
private let listView: ListView = {
12-
1312
let listView = ListView()
1413
return listView
1514
}()
15+
16+
private lazy var searchController: UISearchController = {
17+
let searchController = UISearchController()
18+
searchController.searchBar.delegate = self
19+
searchController.searchBar.placeholder = "Type a GitHub user name"
20+
21+
return searchController
22+
}()
1623

1724
private let service = Service()
1825

1926
init() {
2027
super.init(nibName: nil, bundle: nil)
21-
2228
}
2329

2430
required init?(coder: NSCoder) {
2531
fatalError("init(coder:) has not been implemented")
2632
}
2733

2834
override func viewDidLoad() {
29-
30-
self.navigationController?.navigationBar.prefersLargeTitles = true
31-
self.navigationItem.title = "GitHub App 🐙"
35+
setupNavigationBar()
3236
}
3337

3438
override func viewDidAppear(_ animated: Bool) {
35-
3639
service.fetchList { repositories in
37-
3840
DispatchQueue.main.async {
39-
4041
self.listView.updateView(with: repositories)
4142
}
4243
}
43-
4444
}
4545

4646
override func loadView() {
4747
self.view = listView
4848
}
49+
50+
private func setupNavigationBar() {
51+
let navBarAppearance = UINavigationBarAppearance()
52+
navBarAppearance.configureWithOpaqueBackground()
53+
navBarAppearance.backgroundColor = UIColor(red: 245, green: 245, blue: 245)
54+
55+
navigationController?.navigationBar.scrollEdgeAppearance = navBarAppearance
56+
navigationController?.navigationBar.prefersLargeTitles = true
57+
navigationItem.title = "Repositories"
58+
navigationItem.searchController = searchController
59+
}
60+
}
61+
62+
extension ListViewController: UISearchBarDelegate {
63+
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
64+
let text = searchBar.text
65+
searchController.isActive = false
66+
searchBar.text = text
67+
}
4968
}

0 commit comments

Comments
 (0)