mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-12 23:28:25 +00:00
72 lines
2.3 KiB
Swift
72 lines
2.3 KiB
Swift
//
|
|
// SearchSectionController.swift
|
|
// RepoSearcher
|
|
//
|
|
// Created by Marvin Nazari on 2017-02-18.
|
|
// Copyright © 2017 Marvin Nazari. All rights reserved.
|
|
//
|
|
|
|
import AsyncDisplayKit
|
|
import IGListKit
|
|
|
|
protocol SearchSectionControllerDelegate: class {
|
|
func searchSectionController(_ sectionController: SearchSectionController, didChangeText text: String)
|
|
}
|
|
|
|
final class SearchSectionController: ListSectionController, ASSectionController {
|
|
|
|
weak var delegate: SearchSectionControllerDelegate?
|
|
|
|
override init() {
|
|
super.init()
|
|
scrollDelegate = self
|
|
}
|
|
|
|
func nodeBlockForItem(at index: Int) -> ASCellNodeBlock {
|
|
return { [weak self] in
|
|
return SearchNode(delegate: self)
|
|
}
|
|
}
|
|
|
|
override func numberOfItems() -> Int {
|
|
return 1
|
|
}
|
|
|
|
override func didUpdate(to object: Any) {}
|
|
override func didSelectItem(at index: Int) {}
|
|
|
|
//ASDK Replacement
|
|
override func sizeForItem(at index: Int) -> CGSize {
|
|
return ASIGListSectionControllerMethods.sizeForItem(at: index)
|
|
}
|
|
|
|
override func cellForItem(at index: Int) -> UICollectionViewCell {
|
|
return ASIGListSectionControllerMethods.cellForItem(at: index, sectionController: self)
|
|
}
|
|
}
|
|
|
|
extension SearchSectionController: ListScrollDelegate {
|
|
func listAdapter(_ listAdapter: ListAdapter, didScroll sectionController: ListSectionController) {
|
|
guard let searchNode = collectionContext?.nodeForItem(at: 0, sectionController: self) as? SearchNode else { return }
|
|
|
|
let searchBar = searchNode.searchBarNode.searchBar
|
|
searchBar.text = ""
|
|
searchBar.resignFirstResponder()
|
|
}
|
|
|
|
func listAdapter(_ listAdapter: ListAdapter, willBeginDragging sectionController: ListSectionController) {}
|
|
func listAdapter(_ listAdapter: ListAdapter, didEndDragging sectionController: ListSectionController, willDecelerate decelerate: Bool) {}
|
|
|
|
}
|
|
|
|
extension SearchSectionController: UISearchBarDelegate {
|
|
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
|
|
delegate?.searchSectionController(self, didChangeText: searchText)
|
|
}
|
|
|
|
func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {
|
|
delegate?.searchSectionController(self, didChangeText: "")
|
|
}
|
|
}
|
|
|