From 9bcc6a6c572f891866a842b1e884d8c520e06c02 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Sat, 24 Nov 2018 17:16:16 -0600 Subject: [PATCH] show navbar for photo/album picker, not approval --- .../MediaGalleryViewController.swift | 6 +- .../PhotoLibrary/ImagePickerController.swift | 12 ++-- .../PhotoCollectionPickerController.swift | 16 +++-- .../AttachmentApprovalViewController.swift | 8 ++- SignalMessaging/Views/OWSNavigationBar.swift | 60 +++++++++---------- 5 files changed, 52 insertions(+), 50 deletions(-) diff --git a/Signal/src/ViewControllers/MediaGalleryViewController.swift b/Signal/src/ViewControllers/MediaGalleryViewController.swift index df0d1dc74..3f4876b54 100644 --- a/Signal/src/ViewControllers/MediaGalleryViewController.swift +++ b/Signal/src/ViewControllers/MediaGalleryViewController.swift @@ -291,11 +291,7 @@ class MediaGalleryNavigationController: OWSNavigationController { return } - navigationBar.respectsTheme = false - navigationBar.barStyle = .black - navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: Theme.darkThemePrimaryColor] - navigationBar.barTintColor = Theme.darkThemeBackgroundColor.withAlphaComponent(0.6) - navigationBar.tintColor = Theme.darkThemePrimaryColor + navigationBar.overrideTheme(type: .alwaysDark) } override func viewDidAppear(_ animated: Bool) { diff --git a/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift b/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift index f999fb84b..f8cd2061f 100644 --- a/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift +++ b/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift @@ -59,12 +59,6 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat view.backgroundColor = .ows_gray95 - if let navBar = self.navigationController?.navigationBar as? OWSNavigationBar { - navBar.makeClear() - } else { - owsFailDebug("Invalid nav bar.") - } - let cancelButton = UIBarButtonItem(barButtonSystemItem: .stop, target: self, action: #selector(didPressCancel)) @@ -107,6 +101,12 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) + if let navBar = self.navigationController?.navigationBar as? OWSNavigationBar { + navBar.overrideTheme(type: .alwaysDark) + } else { + owsFailDebug("Invalid nav bar.") + } + // Determine the size of the thumbnails to request let scale = UIScreen.main.scale let cellSize = collectionViewFlowLayout.itemSize diff --git a/Signal/src/ViewControllers/PhotoLibrary/PhotoCollectionPickerController.swift b/Signal/src/ViewControllers/PhotoLibrary/PhotoCollectionPickerController.swift index 6f2748122..bbe0ebf58 100644 --- a/Signal/src/ViewControllers/PhotoLibrary/PhotoCollectionPickerController.swift +++ b/Signal/src/ViewControllers/PhotoLibrary/PhotoCollectionPickerController.swift @@ -39,12 +39,6 @@ class PhotoCollectionPickerController: OWSTableViewController, PhotoLibraryDeleg view.backgroundColor = .ows_gray95 - if let navBar = self.navigationController?.navigationBar as? OWSNavigationBar { - navBar.makeClear() - } else { - owsFailDebug("Invalid nav bar.") - } - if #available(iOS 11, *) { let titleLabel = UILabel() titleLabel.text = previousPhotoCollection.localizedTitle() @@ -77,6 +71,16 @@ class PhotoCollectionPickerController: OWSTableViewController, PhotoLibraryDeleg updateContents() } + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + + if let navBar = self.navigationController?.navigationBar as? OWSNavigationBar { + navBar.overrideTheme(type: .alwaysDark) + } else { + owsFailDebug("Invalid nav bar.") + } + } + private func updateContents() { photoCollections = library.allPhotoCollections() diff --git a/SignalMessaging/ViewControllers/AttachmentApprovalViewController.swift b/SignalMessaging/ViewControllers/AttachmentApprovalViewController.swift index 7f6e61f9a..191dcd61d 100644 --- a/SignalMessaging/ViewControllers/AttachmentApprovalViewController.swift +++ b/SignalMessaging/ViewControllers/AttachmentApprovalViewController.swift @@ -145,7 +145,7 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC owsFailDebug("navigationBar was nil or unexpected class") return navController } - navigationBar.makeClear() + navigationBar.overrideTheme(type: .clear) return navController } @@ -247,6 +247,12 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC super.viewWillAppear(animated) CurrentAppContext().setStatusBarHidden(true, animated: animated) + + guard let navigationBar = navigationController?.navigationBar as? OWSNavigationBar else { + owsFailDebug("navigationBar was nil or unexpected class") + return + } + navigationBar.overrideTheme(type: .clear) } override public func viewDidAppear(_ animated: Bool) { diff --git a/SignalMessaging/Views/OWSNavigationBar.swift b/SignalMessaging/Views/OWSNavigationBar.swift index 3f341c42f..d091cdf81 100644 --- a/SignalMessaging/Views/OWSNavigationBar.swift +++ b/SignalMessaging/Views/OWSNavigationBar.swift @@ -59,14 +59,11 @@ public class OWSNavigationBar: UINavigationBar { private func applyTheme() { guard respectsTheme else { - removeBlurEffectView() - - self.setBackgroundImage(nil, for: .default) return } if UIAccessibilityIsReduceTransparencyEnabled() { - removeBlurEffectView() + blurEffectView?.isHidden = true let color = Theme.navbarBackgroundColor let backgroundImage = UIImage(color: color) self.setBackgroundImage(backgroundImage, for: .default) @@ -189,38 +186,37 @@ public class OWSNavigationBar: UINavigationBar { } } - // MARK: + // MARK: Override Theme @objc - public func makeClear() { - self.backgroundColor = .clear - // Making a toolbar transparent requires setting an empty uiimage - self.setBackgroundImage(UIImage(), for: .default) - self.shadowImage = UIImage() - self.clipsToBounds = true - removeBlurEffectView() + public enum NavigationBarThemeOverride: Int { + case clear, alwaysDark } - // MARK: - - private func removeBlurEffectView() { - // Avoid crash on iOS 10.3.3 and iOS 9.4. - // - // Last Exception Backtrace: - // 0 CoreFoundation 0x1b6bfb38 __exceptionPreprocess + 124 (NSException.m:165) - // 1 libobjc.A.dylib 0x1a947062 objc_exception_throw + 34 (objc-exception.mm:521) - // 2 CoreFoundation 0x1b6bfa80 +[NSException raise:format:] + 104 (NSException.m:140) - // 3 UIKit 0x20bfc9fe -[UINavigationBar removeConstraint:] + 84 (UINavigationBar.m:4618) - // 4 UIKit 0x208ee3d4 _UIViewRemoveConstraintsMadeDanglyByChangingSuperview + 534 // (NSLayoutConstraint_UIKitAdditions.m:4716) - // 5 UIKit 0x208ede90 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 40 // (UIView.m:9467) - // 6 UIKit 0x208edd6c -[UIView(Hierarchy) _postMovedFromSuperview:] + 710 (UIView.m:361) - // 7 UIKit 0x20bd19e8 __UIViewWasRemovedFromSuperview + 154 (UIView.m:8889) - // 8 UIKit 0x208ecf6a -[UIView(Hierarchy) removeFromSuperview] + 528 (UIView.m:8961) - // 9 SignalMessaging 0x1d42b64 OWSNavigationBar.applyTheme() + 218 (OWSNavigationBar.swift:62) - if #available(iOS 11, *) { - self.blurEffectView?.removeFromSuperview() - } else { - self.blurEffectView?.isHidden = true + @objc + public func overrideTheme(type: NavigationBarThemeOverride) { + respectsTheme = false + + barStyle = .black + titleTextAttributes = [NSAttributedStringKey.foregroundColor: Theme.darkThemePrimaryColor] + barTintColor = Theme.darkThemeBackgroundColor.withAlphaComponent(0.6) + tintColor = Theme.darkThemePrimaryColor + + switch type { + case .clear: + blurEffectView?.isHidden = true + clipsToBounds = true + + // Making a toolbar transparent requires setting an empty uiimage + setBackgroundImage(UIImage(), for: .default) + shadowImage = UIImage() + backgroundColor = .clear + case .alwaysDark: + blurEffectView?.isHidden = false + clipsToBounds = false + + setBackgroundImage(nil, for: .default) + shadowImage = nil } } }