// // SearchSectionController.swift // Texture // // Copyright (c) Pinterest, Inc. All rights reserved. // Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0 // 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: "") } }