From 75bb9b60db3effe271f4298ed2da1d1661937aa1 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 21 Aug 2018 15:36:13 -0600 Subject: [PATCH] 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. --- SignalMessaging/Views/OWSSearchBar.m | 14 +++++++++----- SignalMessaging/categories/Theme.h | 3 +-- SignalMessaging/categories/Theme.m | 21 ++++----------------- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/SignalMessaging/Views/OWSSearchBar.m b/SignalMessaging/Views/OWSSearchBar.m index e081b0273..3f9f66be3 100644 --- a/SignalMessaging/Views/OWSSearchBar.m +++ b/SignalMessaging/Views/OWSSearchBar.m @@ -56,17 +56,21 @@ NS_ASSUME_NONNULL_BEGIN { OWSAssertIsOnMainThread(); - self.searchBarStyle = UISearchBarStyleMinimal; - self.backgroundColor = Theme.searchBarBackgroundColor; self.barTintColor = Theme.backgroundColor; 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) { if ([view isKindOfClass:[UITextField class]]) { UITextField *textField = (UITextField *)view; - textField.keyboardAppearance - = (Theme.isDarkThemeEnabled ? UIKeyboardAppearanceDark : UIKeyboardAppearanceDefault); + textField.backgroundColor = Theme.searchFieldBackgroundColor; + textField.textColor = Theme.primaryColor; + textField.keyboardAppearance = Theme.keyboardAppearance; } }]; } diff --git a/SignalMessaging/categories/Theme.h b/SignalMessaging/categories/Theme.h index 937a79ff4..d4b1fbb88 100644 --- a/SignalMessaging/categories/Theme.h +++ b/SignalMessaging/categories/Theme.h @@ -47,8 +47,7 @@ extern NSString *const ThemeDidChangeNotification; #pragma mark - @property (class, readonly, nonatomic) UIBarStyle barStyle; -@property (class, readonly, nonatomic) UISearchBarStyle searchBarStyle; -@property (class, readonly, nonatomic) UIColor *searchBarBackgroundColor; +@property (class, readonly, nonatomic) UIColor *searchFieldBackgroundColor; @property (class, readonly, nonatomic) UIBlurEffect *barBlurEffect; @property (class, readonly, nonatomic) UIKeyboardAppearance keyboardAppearance; diff --git a/SignalMessaging/categories/Theme.m b/SignalMessaging/categories/Theme.m index fff3faa5c..d8268e934 100644 --- a/SignalMessaging/categories/Theme.m +++ b/SignalMessaging/categories/Theme.m @@ -143,29 +143,16 @@ NSString *const ThemeKeyThemeEnabled = @"ThemeKeyThemeEnabled"; return Theme.isDarkThemeEnabled ? UIKeyboardAppearanceDark : UIKeyboardAppearanceDefault; } -#pragma mark - +#pragma mark - Search Bar + (UIBarStyle)barStyle { - if (Theme.isDarkThemeEnabled) { - return UIBarStyleDefault; - } else { - return UIBarStyleDefault; - } -} - -+ (UISearchBarStyle)searchBarStyle -{ - if (Theme.isDarkThemeEnabled) { - return UISearchBarStyleProminent; - } else { - return UISearchBarStyleMinimal; - } + return Theme.isDarkThemeEnabled ? UIBarStyleBlack : UIBarStyleDefault; } -+ (UIColor *)searchBarBackgroundColor ++ (UIColor *)searchFieldBackgroundColor { - return Theme.backgroundColor; + return Theme.isDarkThemeEnabled ? Theme.offBackgroundColor : UIColor.ows_light10Color; } #pragma mark -