diff --git a/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m b/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m index ed33a4f63..e8cd6c38e 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m @@ -92,8 +92,7 @@ const CGFloat kMaxTextViewHeight = 98; CGFloat alpha = OWSNavigationBar.backgroundBlurMutingFactor; self.backgroundColor = [Theme.toolbarBackgroundColor colorWithAlphaComponent:alpha]; - UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; - UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; + UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:Theme.barBlurEffect]; [self addSubview:blurEffectView]; [blurEffectView autoPinEdgesToSuperviewEdges]; } diff --git a/SignalMessaging/Views/OWSNavigationBar.swift b/SignalMessaging/Views/OWSNavigationBar.swift index 330d3b1d8..2e55f0f2c 100644 --- a/SignalMessaging/Views/OWSNavigationBar.swift +++ b/SignalMessaging/Views/OWSNavigationBar.swift @@ -40,57 +40,76 @@ public class OWSNavigationBar: UINavigationBar { @objc public static let backgroundBlurMutingFactor: CGFloat = 0.5 - var blurEffectView: UIView? + var blurEffectView: UIVisualEffectView? override init(frame: CGRect) { super.init(frame: frame) - if !UIAccessibilityIsReduceTransparencyEnabled() { + applyTheme() + + NotificationCenter.default.addObserver(self, selector: #selector(callDidChange), name: .OWSWindowManagerCallDidChange, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(didChangeStatusBarFrame), name: .UIApplicationDidChangeStatusBarFrame, object: nil) + NotificationCenter.default.addObserver(self, + selector: #selector(themeDidChange), + name: .ThemeDidChange, + object: nil) + } + + // MARK: Theme + + private func applyTheme() { + if UIAccessibilityIsReduceTransparencyEnabled() { + self.blurEffectView?.removeFromSuperview() + let color = Theme.navbarBackgroundColor + let backgroundImage = UIImage(color: color) + self.setBackgroundImage(backgroundImage, for: .default) + } else { // Make navbar more translucent than default. Navbars remove alpha from any assigned backgroundColor, so // to achieve transparency, we have to assign a transparent image. let color = Theme.navbarBackgroundColor.withAlphaComponent(OWSNavigationBar.backgroundBlurMutingFactor) let backgroundImage = UIImage(color: color) self.setBackgroundImage(backgroundImage, for: .default) - let blurEffect = UIBlurEffect(style: .light) - let blurEffectView = UIVisualEffectView(effect: blurEffect) - blurEffectView.isUserInteractionEnabled = false - self.blurEffectView = blurEffectView + + let blurEffect = Theme.barBlurEffect + + let blurEffectView: UIVisualEffectView = { + if let existingBlurEffectView = self.blurEffectView { + return existingBlurEffectView + } + + let blurEffectView = UIVisualEffectView() + blurEffectView.isUserInteractionEnabled = false + + self.blurEffectView = blurEffectView + self.insertSubview(blurEffectView, at: 0) + + // navbar frame doesn't account for statusBar, so, same as the built-in navbar background, we need to exceed + // the navbar bounds to have the blur extend up and behind the status bar. + blurEffectView.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets(top: -statusBarHeight, left: 0, bottom: 0, right: 0)) + + return blurEffectView + }() + + blurEffectView.effect = blurEffect // remove hairline below bar. self.shadowImage = UIImage() - self.insertSubview(blurEffectView, at: 0) // On iOS11, despite inserting the blur at 0, other views are later inserted into the navbar behind the blur, // so we have to set a zindex to avoid obscuring navbar title/buttons. blurEffectView.layer.zPosition = -1 - // navbar frame doesn't account for statusBar, so, same as the built-in navbar background, we need to exceed - // the navbar bounds to have the blur extend up and behind the status bar. - blurEffectView.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets(top: -statusBarHeight, left: 0, bottom: 0, right: 0)) } - - NotificationCenter.default.addObserver(self, selector: #selector(callDidChange), name: .OWSWindowManagerCallDidChange, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(didChangeStatusBarFrame), name: .UIApplicationDidChangeStatusBarFrame, object: nil) - NotificationCenter.default.addObserver(self, - selector: #selector(themeDidChange), - name: .ThemeDidChange, - object: nil) } - // MARK: Layout - @objc public func themeDidChange() { Logger.debug("\(self.logTag) in \(#function)") - - guard self.backgroundImage(for: .default) != nil else { - return - } - let color = Theme.navbarBackgroundColor.withAlphaComponent(OWSNavigationBar.backgroundBlurMutingFactor) - let backgroundImage = UIImage(color: color) - self.setBackgroundImage(backgroundImage, for: .default) + applyTheme() } + // MARK: Layout + @objc public func callDidChange() { Logger.debug("\(self.logTag) in \(#function)") diff --git a/SignalMessaging/categories/Theme.h b/SignalMessaging/categories/Theme.h index 50333f89e..fc13568c7 100644 --- a/SignalMessaging/categories/Theme.h +++ b/SignalMessaging/categories/Theme.h @@ -47,6 +47,7 @@ extern NSString *const ThemeDidChangeNotification; @property (class, readonly, nonatomic) UIBarStyle barStyle; @property (class, readonly, nonatomic) UISearchBarStyle searchBarStyle; @property (class, readonly, nonatomic) UIColor *searchBarBackgroundColor; +@property (class, readonly, nonatomic) UIBlurEffect *barBlurEffect; @end diff --git a/SignalMessaging/categories/Theme.m b/SignalMessaging/categories/Theme.m index 106e9d800..b94b0b907 100644 --- a/SignalMessaging/categories/Theme.m +++ b/SignalMessaging/categories/Theme.m @@ -123,6 +123,12 @@ NSString *const ThemeKeyThemeEnabled = @"ThemeKeyThemeEnabled"; return (Theme.isDarkThemeEnabled ? [UIColor colorWithWhite:0.35f alpha:1.f] : UIColor.ows_light02Color); } ++ (UIBlurEffect *)barBlurEffect +{ + return Theme.isDarkThemeEnabled ? [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark] + : [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; +} + #pragma mark - + (UIBarStyle)barStyle