// // SearchViewController.swift // Mastodon // // Created by sxiaojian on 2021/3/31. // import UIKit import Combine final class SearchViewController: UIViewController, NeedsDependency { weak var context: AppContext! { willSet { precondition(!isViewLoaded) } } weak var coordinator: SceneCoordinator! { willSet { precondition(!isViewLoaded) } } var disposeBag = Set() private(set) lazy var viewModel = SearchViewModel(context: context) let searchBar: UISearchBar = { let searchBar = UISearchBar() searchBar.placeholder = L10n.Scene.Search.Searchbar.placeholder searchBar.tintColor = Asset.Colors.buttonDefault.color searchBar.translatesAutoresizingMaskIntoConstraints = false let micImage = UIImage(systemName: "mic.fill") searchBar.setImage(micImage, for: .bookmark, state: .normal) searchBar.showsBookmarkButton = true return searchBar }() let recommendView: UICollectionView = { let flowLayout = UICollectionViewFlowLayout() flowLayout.scrollDirection = .horizontal let view = ControlContainableCollectionView(frame: .zero, collectionViewLayout: flowLayout) view.backgroundColor = .clear view.showsHorizontalScrollIndicator = false view.showsVerticalScrollIndicator = false view.layer.masksToBounds = false view.translatesAutoresizingMaskIntoConstraints = false return view }() } extension SearchViewController { override func viewDidLoad() { super.viewDidLoad() searchBar.delegate = self navigationItem.titleView = searchBar navigationItem.hidesBackButton = true } } extension SearchViewController: UISearchBarDelegate { func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) { searchBar.setShowsCancelButton(true, animated: true) } func searchBarTextDidEndEditing(_ searchBar: UISearchBar) { searchBar.setShowsCancelButton(false, animated: true) } func searchBarCancelButtonClicked(_ searchBar: UISearchBar) { searchBar.setShowsCancelButton(false, animated: true) searchBar.text = "" searchBar.resignFirstResponder() } func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { viewModel.searchText.send(searchText) } func searchBarBookmarkButtonClicked(_ searchBar: UISearchBar) { } } extension SearchViewController { }