Alternative dark theme search bar

Rather than our custom class, we can get pretty far using existing UISearchBar
styling, and then apply the final tweak, the search bar text field background
color by traversing the view.

This fixes a couple issues:

1. There was a small wavering in height of the custom search bar
2. When your table header view is a UISearchBar you get nice scroll "snapping"
   when showing/hiding the search bar.
pull/1/head
Michael Kirk 7 years ago
parent e435358bfd
commit 75bb9b60db

@ -56,17 +56,21 @@ NS_ASSUME_NONNULL_BEGIN
{ {
OWSAssertIsOnMainThread(); OWSAssertIsOnMainThread();
self.searchBarStyle = UISearchBarStyleMinimal;
self.backgroundColor = Theme.searchBarBackgroundColor;
self.barTintColor = Theme.backgroundColor; self.barTintColor = Theme.backgroundColor;
self.barStyle = Theme.barStyle; self.barStyle = Theme.barStyle;
self.searchBarStyle = Theme.searchBarStyle;
// 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).
self.backgroundImage = [UIImage new];
[self traverseViewHierarchyWithVisitor:^(UIView *view) { [self traverseViewHierarchyWithVisitor:^(UIView *view) {
if ([view isKindOfClass:[UITextField class]]) { if ([view isKindOfClass:[UITextField class]]) {
UITextField *textField = (UITextField *)view; UITextField *textField = (UITextField *)view;
textField.keyboardAppearance textField.backgroundColor = Theme.searchFieldBackgroundColor;
= (Theme.isDarkThemeEnabled ? UIKeyboardAppearanceDark : UIKeyboardAppearanceDefault); textField.textColor = Theme.primaryColor;
textField.keyboardAppearance = Theme.keyboardAppearance;
} }
}]; }];
} }

@ -47,8 +47,7 @@ extern NSString *const ThemeDidChangeNotification;
#pragma mark - #pragma mark -
@property (class, readonly, nonatomic) UIBarStyle barStyle; @property (class, readonly, nonatomic) UIBarStyle barStyle;
@property (class, readonly, nonatomic) UISearchBarStyle searchBarStyle; @property (class, readonly, nonatomic) UIColor *searchFieldBackgroundColor;
@property (class, readonly, nonatomic) UIColor *searchBarBackgroundColor;
@property (class, readonly, nonatomic) UIBlurEffect *barBlurEffect; @property (class, readonly, nonatomic) UIBlurEffect *barBlurEffect;
@property (class, readonly, nonatomic) UIKeyboardAppearance keyboardAppearance; @property (class, readonly, nonatomic) UIKeyboardAppearance keyboardAppearance;

@ -143,29 +143,16 @@ NSString *const ThemeKeyThemeEnabled = @"ThemeKeyThemeEnabled";
return Theme.isDarkThemeEnabled ? UIKeyboardAppearanceDark : UIKeyboardAppearanceDefault; return Theme.isDarkThemeEnabled ? UIKeyboardAppearanceDark : UIKeyboardAppearanceDefault;
} }
#pragma mark - #pragma mark - Search Bar
+ (UIBarStyle)barStyle + (UIBarStyle)barStyle
{ {
if (Theme.isDarkThemeEnabled) { return Theme.isDarkThemeEnabled ? UIBarStyleBlack : UIBarStyleDefault;
return UIBarStyleDefault;
} else {
return UIBarStyleDefault;
}
}
+ (UISearchBarStyle)searchBarStyle
{
if (Theme.isDarkThemeEnabled) {
return UISearchBarStyleProminent;
} else {
return UISearchBarStyleMinimal;
}
} }
+ (UIColor *)searchBarBackgroundColor + (UIColor *)searchFieldBackgroundColor
{ {
return Theme.backgroundColor; return Theme.isDarkThemeEnabled ? Theme.offBackgroundColor : UIColor.ows_light10Color;
} }
#pragma mark - #pragma mark -

Loading…
Cancel
Save