mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
3.6 KiB
Matlab
119 lines
3.6 KiB
Matlab
7 years ago
|
//
|
||
6 years ago
|
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||
7 years ago
|
//
|
||
|
|
||
|
#import "OWSSearchBar.h"
|
||
|
#import "Theme.h"
|
||
|
#import "UIView+OWS.h"
|
||
5 years ago
|
#import <SignalUtilitiesKit/SignalUtilitiesKit-Swift.h>
|
||
5 years ago
|
#import <SessionUIKit/SessionUIKit.h>
|
||
7 years ago
|
|
||
|
NS_ASSUME_NONNULL_BEGIN
|
||
|
|
||
7 years ago
|
@implementation OWSSearchBar
|
||
7 years ago
|
|
||
7 years ago
|
- (instancetype)init
|
||
|
{
|
||
|
if (self = [super init]) {
|
||
|
[self ows_configure];
|
||
|
}
|
||
7 years ago
|
|
||
7 years ago
|
return self;
|
||
|
}
|
||
7 years ago
|
|
||
|
- (instancetype)initWithFrame:(CGRect)frame
|
||
|
{
|
||
|
if (self = [super initWithFrame:frame]) {
|
||
|
[self ows_configure];
|
||
|
}
|
||
|
|
||
|
return self;
|
||
|
}
|
||
|
|
||
|
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder
|
||
|
{
|
||
|
if (self = [super initWithCoder:aDecoder]) {
|
||
|
[self ows_configure];
|
||
|
}
|
||
|
|
||
|
return self;
|
||
|
}
|
||
|
|
||
|
- (void)ows_configure
|
||
|
{
|
||
|
[self ows_applyTheme];
|
||
|
|
||
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||
|
selector:@selector(themeDidChange:)
|
||
|
name:ThemeDidChangeNotification
|
||
|
object:nil];
|
||
|
}
|
||
|
|
||
|
- (void)dealloc
|
||
|
{
|
||
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||
|
}
|
||
|
|
||
|
- (void)ows_applyTheme
|
||
6 years ago
|
{
|
||
|
[self.class applyThemeToSearchBar:self];
|
||
|
}
|
||
|
|
||
|
+ (void)applyThemeToSearchBar:(UISearchBar *)searchBar
|
||
7 years ago
|
{
|
||
|
OWSAssertIsOnMainThread();
|
||
|
|
||
6 years ago
|
UIColor *foregroundColor = UIColor.lokiLightestGray;
|
||
6 years ago
|
searchBar.barTintColor = Theme.backgroundColor;
|
||
|
searchBar.barStyle = Theme.barStyle;
|
||
6 years ago
|
searchBar.tintColor = UIColor.lokiGreen;
|
||
6 years ago
|
|
||
7 years ago
|
// Hide searchBar border.
|
||
|
// Alternatively we could hide the border by using `UISearchBarStyleMinimal`, but that causes an issue when toggling
|
||
|
// from light -> dark -> light theme wherein the textField background color appears darker than it should
|
||
|
// (regardless of our re-setting textfield.backgroundColor below).
|
||
6 years ago
|
searchBar.backgroundImage = [UIImage new];
|
||
7 years ago
|
|
||
7 years ago
|
if (Theme.isDarkThemeEnabled) {
|
||
|
UIImage *clearImage = [UIImage imageNamed:@"searchbar_clear"];
|
||
6 years ago
|
[searchBar setImage:[clearImage asTintedImageWithColor:foregroundColor]
|
||
7 years ago
|
forSearchBarIcon:UISearchBarIconClear
|
||
|
state:UIControlStateNormal];
|
||
|
|
||
|
UIImage *searchImage = [UIImage imageNamed:@"searchbar_search"];
|
||
6 years ago
|
[searchBar setImage:[searchImage asTintedImageWithColor:foregroundColor]
|
||
7 years ago
|
forSearchBarIcon:UISearchBarIconSearch
|
||
|
state:UIControlStateNormal];
|
||
|
} else {
|
||
6 years ago
|
[searchBar setImage:nil forSearchBarIcon:UISearchBarIconClear state:UIControlStateNormal];
|
||
7 years ago
|
|
||
6 years ago
|
[searchBar setImage:nil forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
|
||
7 years ago
|
}
|
||
|
|
||
6 years ago
|
[searchBar traverseViewHierarchyWithVisitor:^(UIView *view) {
|
||
7 years ago
|
if ([view isKindOfClass:[UITextField class]]) {
|
||
|
UITextField *textField = (UITextField *)view;
|
||
7 years ago
|
textField.backgroundColor = Theme.searchFieldBackgroundColor;
|
||
|
textField.textColor = Theme.primaryColor;
|
||
6 years ago
|
NSString *placeholder = textField.placeholder;
|
||
|
if (placeholder != nil) {
|
||
|
NSMutableAttributedString *attributedPlaceholder = [[NSMutableAttributedString alloc] initWithString:placeholder];
|
||
|
[attributedPlaceholder addAttribute:NSForegroundColorAttributeName value:foregroundColor range:NSMakeRange(0, placeholder.length)];
|
||
|
textField.attributedPlaceholder = attributedPlaceholder;
|
||
|
}
|
||
5 years ago
|
textField.keyboardAppearance = LKAppModeUtilities.isLightMode ? UIKeyboardAppearanceDefault : UIKeyboardAppearanceDark;
|
||
7 years ago
|
}
|
||
|
}];
|
||
7 years ago
|
}
|
||
|
|
||
|
- (void)themeDidChange:(NSNotification *)notification
|
||
|
{
|
||
|
OWSAssertIsOnMainThread();
|
||
|
|
||
|
[self ows_applyTheme];
|
||
|
}
|
||
|
|
||
|
@end
|
||
|
|
||
|
NS_ASSUME_NONNULL_END
|