Auto-dismiss search keyboard; "cancel search" button.

This commit is contained in:
Matthew Chen 2018-06-21 09:59:01 -04:00
parent 6933e28e47
commit f516f30c26
2 changed files with 49 additions and 1 deletions

View File

@ -4,9 +4,17 @@
import Foundation
@objc
protocol ConversationSearchViewDelegate: class {
func conversationSearchViewWillBeginDragging()
}
@objc
class ConversationSearchViewController: UITableViewController {
@objc
public weak var delegate: ConversationSearchViewDelegate?
@objc
public var searchText = "" {
didSet {
@ -300,6 +308,12 @@ class ConversationSearchViewController: UITableViewController {
// TODO: more performant way to do this?
self.tableView.reloadData()
}
// MARK: - UIScrollViewDelegate
override func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
delegate?.conversationSearchViewWillBeginDragging()
}
}
class EmptySearchResultCell: UITableViewCell {

View File

@ -45,7 +45,8 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
@interface HomeViewController () <UITableViewDelegate,
UITableViewDataSource,
UIViewControllerPreviewingDelegate,
UISearchBarDelegate>
UISearchBarDelegate,
ConversationSearchViewDelegate>
@property (nonatomic) UITableView *tableView;
@property (nonatomic) UILabel *emptyBoxLabel;
@ -378,6 +379,7 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
self.tableView.tableHeaderView = self.searchBar;
ConversationSearchViewController *searchResultsController = [ConversationSearchViewController new];
searchResultsController.delegate = self;
self.searchResultsController = searchResultsController;
[self addChildViewController:searchResultsController];
[self.view addSubview:searchResultsController.view];
@ -938,16 +940,22 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
[self.tableView setContentOffset:CGPointZero animated:NO];
[self updateSearchResultsVisibility];
[self ensureSearchBarCancelButton];
}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
[self updateSearchResultsVisibility];
[self ensureSearchBarCancelButton];
}
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
[self updateSearchResultsVisibility];
[self ensureSearchBarCancelButton];
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
@ -959,7 +967,17 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
{
self.searchBar.text = nil;
[self.searchBar resignFirstResponder];
OWSAssert(!self.searchBar.isFirstResponder);
[self updateSearchResultsVisibility];
[self ensureSearchBarCancelButton];
}
- (void)ensureSearchBarCancelButton
{
self.searchBar.showsCancelButton = (self.searchBar.isFirstResponder || self.searchBar.text.length > 0);
}
- (void)updateSearchResultsVisibility
@ -979,6 +997,22 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
}
}
#pragma mark - UIScrollViewDelegate
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
[self.searchBar resignFirstResponder];
OWSAssert(!self.searchBar.isFirstResponder);
}
#pragma mark - ConversationSearchViewDelegate
- (void)conversationSearchViewWillBeginDragging
{
[self.searchBar resignFirstResponder];
OWSAssert(!self.searchBar.isFirstResponder);
}
#pragma mark - HomeFeedTableViewCellDelegate
- (void)tableViewCellTappedDelete:(NSIndexPath *)indexPath