2021-02-23 09:45:00 +01:00
|
|
|
//
|
|
|
|
// SearchViewController.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
2021-03-31 08:28:40 +02:00
|
|
|
// Created by sxiaojian on 2021/3/31.
|
2021-02-23 09:45:00 +01:00
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
2021-03-31 08:28:40 +02:00
|
|
|
import Combine
|
2021-02-23 09:45:00 +01:00
|
|
|
|
|
|
|
final class SearchViewController: UIViewController, NeedsDependency {
|
|
|
|
|
|
|
|
weak var context: AppContext! { willSet { precondition(!isViewLoaded) } }
|
|
|
|
weak var coordinator: SceneCoordinator! { willSet { precondition(!isViewLoaded) } }
|
|
|
|
|
2021-03-31 08:28:40 +02:00
|
|
|
var disposeBag = Set<AnyCancellable>()
|
|
|
|
private(set) lazy var viewModel = SearchViewModel(context: context)
|
|
|
|
|
2021-03-31 09:06:46 +02:00
|
|
|
let searchBar: UISearchBar = {
|
|
|
|
let searchBar = UISearchBar()
|
2021-03-31 13:29:54 +02:00
|
|
|
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
|
2021-03-31 09:06:46 +02:00
|
|
|
return searchBar
|
|
|
|
}()
|
2021-03-31 13:29:54 +02:00
|
|
|
|
2021-03-31 14:56:11 +02:00
|
|
|
let recommendView: UICollectionView = {
|
2021-03-31 13:29:54 +02:00
|
|
|
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
|
|
|
|
}()
|
2021-02-23 09:45:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
extension SearchViewController {
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
2021-03-31 13:29:54 +02:00
|
|
|
searchBar.delegate = self
|
|
|
|
navigationItem.titleView = searchBar
|
|
|
|
navigationItem.hidesBackButton = true
|
2021-04-01 05:49:38 +02:00
|
|
|
viewModel.requestRecommendData()
|
2021-03-31 13:29:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-03-31 09:06:46 +02:00
|
|
|
|
2021-03-31 13:29:54 +02:00
|
|
|
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)
|
2021-02-23 09:45:00 +01:00
|
|
|
}
|
|
|
|
|
2021-03-31 13:29:54 +02:00
|
|
|
func searchBarBookmarkButtonClicked(_ searchBar: UISearchBar) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension SearchViewController {
|
|
|
|
|
2021-02-23 09:45:00 +01:00
|
|
|
}
|