forked from organicmaps/organicmaps
[ios] Fixed search UI.
This commit is contained in:
parent
f7699b747e
commit
310008e062
3 changed files with 45 additions and 21 deletions
|
@ -3,6 +3,11 @@
|
|||
#import "UIColor+MapsMeColor.h"
|
||||
#import "UIImageView+Coloring.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
NSTimeInterval constexpr kOnSearchCompletedDelay = 0.2;
|
||||
} // namespace
|
||||
|
||||
@interface MWMSearchTextField ()<MWMSearchObserver>
|
||||
|
||||
@property(nonatomic) BOOL isSearching;
|
||||
|
@ -16,7 +21,7 @@
|
|||
self = [super initWithCoder:aDecoder];
|
||||
if (self)
|
||||
{
|
||||
self.isSearching = NO;
|
||||
[self setStaticIcon];
|
||||
self.leftViewMode = UITextFieldViewModeAlways;
|
||||
self.textColor = [UIColor blackSecondaryText];
|
||||
[MWMSearch addObserver:self];
|
||||
|
@ -35,6 +40,8 @@
|
|||
|
||||
- (void)setIsSearching:(BOOL)isSearching
|
||||
{
|
||||
if (_isSearching == isSearching)
|
||||
return;
|
||||
_isSearching = isSearching;
|
||||
if (isSearching)
|
||||
{
|
||||
|
@ -48,13 +55,34 @@
|
|||
}
|
||||
else
|
||||
{
|
||||
self.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ic_search"]];
|
||||
static_cast<UIImageView *>(self.leftView).mwm_coloring = MWMImageColoringBlack;
|
||||
[self setStaticIcon];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setStaticIcon
|
||||
{
|
||||
self.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ic_search"]];
|
||||
static_cast<UIImageView *>(self.leftView).mwm_coloring = MWMImageColoringBlack;
|
||||
}
|
||||
|
||||
- (void)stopSpinner
|
||||
{
|
||||
self.isSearching = NO;
|
||||
}
|
||||
|
||||
#pragma mark - MWMSearchObserver
|
||||
|
||||
- (void)onSearchStarted { self.isSearching = YES; }
|
||||
- (void)onSearchCompleted { self.isSearching = NO; }
|
||||
- (void)onSearchStarted
|
||||
{
|
||||
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(stopSpinner) object:nil];
|
||||
self.isSearching = YES;
|
||||
}
|
||||
|
||||
- (void)onSearchCompleted
|
||||
{
|
||||
SEL const selector = @selector(stopSpinner);
|
||||
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:selector object:nil];
|
||||
[self performSelector:selector withObject:nil afterDelay:kOnSearchCompletedDelay];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -57,10 +57,11 @@ NSString * identifierForType(MWMSearchTableCellType type)
|
|||
[self setupTableView];
|
||||
}
|
||||
|
||||
- (void)viewDidAppear:(BOOL)animated
|
||||
- (void)viewWillAppear:(BOOL)animated
|
||||
{
|
||||
[super viewDidAppear:animated];
|
||||
[super viewWillAppear:animated];
|
||||
[MWMSearch addObserver:self];
|
||||
[self.tableView reloadData];
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated
|
||||
|
|
|
@ -13,8 +13,6 @@ namespace
|
|||
{
|
||||
using TObserver = id<MWMSearchObserver>;
|
||||
using TObservers = NSHashTable<__kindof TObserver>;
|
||||
|
||||
NSTimeInterval constexpr kOnSearchCompletedDelay = 0.2;
|
||||
} // namespace
|
||||
|
||||
@interface MWMSearch ()
|
||||
|
@ -28,6 +26,8 @@ NSTimeInterval constexpr kOnSearchCompletedDelay = 0.2;
|
|||
|
||||
@property(nonatomic) TObservers * observers;
|
||||
|
||||
@property(nonatomic) NSTimeInterval lastSearchTimestamp;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MWMSearch
|
||||
|
@ -59,15 +59,19 @@ NSTimeInterval constexpr kOnSearchCompletedDelay = 0.2;
|
|||
|
||||
- (void)updateCallbacks
|
||||
{
|
||||
NSTimeInterval const timestamp = [NSDate date].timeIntervalSince1970;
|
||||
self.lastSearchTimestamp = timestamp;
|
||||
__weak auto weakSelf = self;
|
||||
m_everywhereParams.m_onResults = [weakSelf](search::Results const & results) {
|
||||
m_everywhereParams.m_onResults = [weakSelf, timestamp](search::Results const & results) {
|
||||
__strong auto self = weakSelf;
|
||||
if (!self)
|
||||
return;
|
||||
if (timestamp != self.lastSearchTimestamp)
|
||||
return;
|
||||
if (results.IsEndMarker())
|
||||
{
|
||||
self.everywhereSearchActive = NO;
|
||||
[self delayedOnSearchCompleted];
|
||||
[self onSearchCompleted];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -93,7 +97,7 @@ NSTimeInterval constexpr kOnSearchCompletedDelay = 0.2;
|
|||
if (!self)
|
||||
return;
|
||||
self.viewportSearchActive = NO;
|
||||
[self delayedOnSearchCompleted];
|
||||
[self onSearchCompleted];
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -125,13 +129,6 @@ NSTimeInterval constexpr kOnSearchCompletedDelay = 0.2;
|
|||
[self onSearchStarted];
|
||||
}
|
||||
|
||||
- (void)delayedOnSearchCompleted
|
||||
{
|
||||
SEL const selector = @selector(onSearchCompleted);
|
||||
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:selector object:nil];
|
||||
[self performSelector:selector withObject:nil afterDelay:kOnSearchCompletedDelay];
|
||||
}
|
||||
|
||||
#pragma mark - Add/Remove Observers
|
||||
|
||||
+ (void)addObserver:(id<MWMSearchObserver>)observer
|
||||
|
@ -206,8 +203,6 @@ NSTimeInterval constexpr kOnSearchCompletedDelay = 0.2;
|
|||
|
||||
- (void)onSearchStarted
|
||||
{
|
||||
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(onSearchCompleted) object:nil];
|
||||
|
||||
for (TObserver observer in self.observers)
|
||||
{
|
||||
if ([observer respondsToSelector:@selector(onSearchStarted)])
|
||||
|
|
Loading…
Add table
Reference in a new issue