mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-26 13:29:31 -04:00
search
This commit is contained in:
parent
2e4891e42e
commit
243bbece05
@ -57,16 +57,9 @@ class RecentSearchController: UIViewController, UICollectionViewDataSource, UICo
|
||||
// MARK: - CollectionView Delegate
|
||||
|
||||
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
||||
guard let mainVC = parent?.parent?.parent as? MainController else {return}
|
||||
print("tapped")
|
||||
|
||||
// guard let mainVC = parent?.parent?.parent as? MainController,
|
||||
// let searchController = parent?.parent as? SearchController,
|
||||
// let cell = collectionView.cellForItem(at: indexPath) as? LocalLangCell,
|
||||
// let text = cell.label.text else {return}
|
||||
// mainVC.searchBar.searchTerm = text
|
||||
// searchController.startSearch(text, delayed: false)
|
||||
// collectionView.deselectItem(at: indexPath, animated: true)
|
||||
guard let cell = collectionView.cellForItem(at: indexPath) as? LocalLangCell,
|
||||
let text = cell.label.text else {return}
|
||||
Controllers.main.searchBar.searchText = text
|
||||
}
|
||||
|
||||
// MARK: - CollectionView Delegate FlowLayout
|
||||
|
@ -17,10 +17,25 @@ class SearchBar: UIView, UITextFieldDelegate {
|
||||
let delayTextChangeCallback = true
|
||||
weak var delegate: SearchBarDelegate?
|
||||
private var cachedSearchText: String?
|
||||
private var previousSearchText = ""
|
||||
|
||||
/**
|
||||
The text to display when search bar is not the first responder
|
||||
*/
|
||||
var title = "" {
|
||||
didSet {
|
||||
if !isFirstResponder {textField.text = title}
|
||||
guard !isFirstResponder else {return}
|
||||
textField.text = title
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
The search text of the search bar. It is preserved even if search bar resigns and then become first responser again
|
||||
*/
|
||||
var searchText = "" {
|
||||
didSet {
|
||||
guard searchText != textField.text && isFirstResponder else {return}
|
||||
textField.text = searchText
|
||||
textDidChange(textField: textField)
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,8 +127,7 @@ class SearchBar: UIView, UITextFieldDelegate {
|
||||
textField.isUserInteractionEnabled = true
|
||||
textField.textAlignment = .left
|
||||
textField.becomeFirstResponder()
|
||||
title = textField.text ?? ""
|
||||
textField.text = previousSearchText
|
||||
textField.text = searchText
|
||||
delegate?.didBecomeFirstResponder(searchBar: self)
|
||||
return true
|
||||
}
|
||||
@ -122,7 +136,7 @@ class SearchBar: UIView, UITextFieldDelegate {
|
||||
textField.isUserInteractionEnabled = false
|
||||
textField.textAlignment = .center
|
||||
textField.resignFirstResponder()
|
||||
previousSearchText = textField.text ?? ""
|
||||
searchText = textField.text ?? ""
|
||||
textField.text = title
|
||||
delegate?.didResignFirstResponder(searchBar: self)
|
||||
return true
|
||||
|
Loading…
x
Reference in New Issue
Block a user