2020-06-24 20:40:45 +00:00
|
|
|
//
|
|
|
|
// SearchViewController.swift
|
|
|
|
// Tusker
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 6/24/20.
|
|
|
|
// Copyright © 2020 Shadowfacts. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
class SearchViewController: UIViewController {
|
|
|
|
|
|
|
|
weak var mastodonController: MastodonController!
|
|
|
|
|
|
|
|
var resultsController: SearchResultsViewController!
|
|
|
|
var searchController: UISearchController!
|
|
|
|
|
2020-06-30 02:21:03 +00:00
|
|
|
var searchControllerStatusOnAppearance: Bool? = nil
|
|
|
|
|
2020-06-24 20:40:45 +00:00
|
|
|
init(mastodonController: MastodonController) {
|
|
|
|
self.mastodonController = mastodonController
|
|
|
|
|
|
|
|
super.init(nibName: nil, bundle: nil)
|
|
|
|
|
|
|
|
title = NSLocalizedString("Search", comment: "search tab title")
|
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
fatalError("init(coder:) has not been implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
2020-12-14 03:37:37 +00:00
|
|
|
view.backgroundColor = .systemBackground
|
|
|
|
|
2020-06-24 20:40:45 +00:00
|
|
|
resultsController = SearchResultsViewController(mastodonController: mastodonController)
|
|
|
|
resultsController.exploreNavigationController = self.navigationController
|
|
|
|
searchController = UISearchController(searchResultsController: resultsController)
|
|
|
|
searchController.searchResultsUpdater = resultsController
|
|
|
|
searchController.searchBar.autocapitalizationType = .none
|
|
|
|
searchController.searchBar.delegate = resultsController
|
|
|
|
definesPresentationContext = true
|
|
|
|
|
|
|
|
navigationItem.searchController = searchController
|
|
|
|
navigationItem.hidesSearchBarWhenScrolling = false
|
|
|
|
}
|
|
|
|
|
2020-06-30 02:21:03 +00:00
|
|
|
override func viewDidAppear(_ animated: Bool) {
|
|
|
|
super.viewDidAppear(animated)
|
|
|
|
|
|
|
|
// this is a workaround for the issue that setting isActive on a search controller that is not visible
|
|
|
|
// does not cause it to automatically become active once it becomes visible
|
|
|
|
// see FB7814561
|
|
|
|
if let active = searchControllerStatusOnAppearance {
|
|
|
|
searchController.isActive = active
|
|
|
|
searchControllerStatusOnAppearance = nil
|
|
|
|
}
|
|
|
|
}
|
2020-06-24 20:40:45 +00:00
|
|
|
|
|
|
|
}
|