From 6d8a7ed800f2e70dbf2502ef6f499ff8b6c8a51c Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Wed, 31 Oct 2018 17:37:33 -0600 Subject: [PATCH] things working --- .../MediaGalleryViewController.swift | 5 ++- .../ViewControllers/OWSNavigationController.h | 3 +- .../ViewControllers/OWSNavigationController.m | 39 +++++++++++-------- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/Signal/src/ViewControllers/MediaGalleryViewController.swift b/Signal/src/ViewControllers/MediaGalleryViewController.swift index 44a8ba500..6b2b75136 100644 --- a/Signal/src/ViewControllers/MediaGalleryViewController.swift +++ b/Signal/src/ViewControllers/MediaGalleryViewController.swift @@ -168,6 +168,7 @@ protocol MediaGalleryDataSourceDelegate: class { func mediaGalleryDataSource(_ mediaGalleryDataSource: MediaGalleryDataSource, deletedSections: IndexSet, deletedItems: [IndexPath]) } +@objc class MediaGalleryViewController: OWSNavigationController, MediaGalleryDataSource, MediaTileViewControllerDelegate { private var pageViewController: MediaPageViewController? @@ -197,7 +198,9 @@ class MediaGalleryViewController: OWSNavigationController, MediaGalleryDataSourc self.options = options self.mediaGalleryFinder = OWSMediaGalleryFinder(thread: thread) - super.init(owsNavigationBar: ()) + super.init(nibName: nil, bundle: nil) + self.setValue(OWSNavigationBar(), forKey: "navigationBar") + super.setupNavbar() } required init?(coder aDecoder: NSCoder) { diff --git a/SignalMessaging/ViewControllers/OWSNavigationController.h b/SignalMessaging/ViewControllers/OWSNavigationController.h index 5da136eca..ebd38e06c 100644 --- a/SignalMessaging/ViewControllers/OWSNavigationController.h +++ b/SignalMessaging/ViewControllers/OWSNavigationController.h @@ -23,7 +23,8 @@ NS_ASSUME_NONNULL_BEGIN // unsaved changes. @interface OWSNavigationController : UINavigationController -- (instancetype)initWithOWSNavigationBar; +- (instancetype)init; +- (void)setupNavbar; @end diff --git a/SignalMessaging/ViewControllers/OWSNavigationController.m b/SignalMessaging/ViewControllers/OWSNavigationController.m index ba3a34201..e1ebb9ebb 100644 --- a/SignalMessaging/ViewControllers/OWSNavigationController.m +++ b/SignalMessaging/ViewControllers/OWSNavigationController.m @@ -24,33 +24,20 @@ NS_ASSUME_NONNULL_BEGIN @implementation OWSNavigationController -- (instancetype)initWithOWSNavigationBar +- (instancetype)init { - self = [self initWithNavigationBarClass:[OWSNavigationBar class] toolbarClass:nil]; + self = [super initWithNavigationBarClass:[OWSNavigationBar class] toolbarClass:nil]; if (!self) { return self; } - - if (![self.navigationBar isKindOfClass:[OWSNavigationBar class]]) { - OWSFailDebug(@"navigationBar was unexpected class: %@", self.navigationBar); - return self; - } - - OWSNavigationBar *navbar = (OWSNavigationBar *)self.navigationBar; - navbar.navBarLayoutDelegate = self; - [self updateLayoutForNavbar:navbar]; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(themeDidChange:) - name:ThemeDidChangeNotification - object:nil]; + [self setupNavbar]; return self; } - (instancetype)initWithRootViewController:(UIViewController *)rootViewController { - self = [self initWithOWSNavigationBar]; + self = [self init]; if (!self) { return self; } @@ -64,6 +51,8 @@ NS_ASSUME_NONNULL_BEGIN [[NSNotificationCenter defaultCenter] removeObserver:self]; } +#pragma mark - + - (void)themeDidChange:(NSNotification *)notification { OWSAssertIsOnMainThread(); @@ -82,6 +71,22 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - UINavigationBarDelegate +- (void)setupNavbar +{ + if (![self.navigationBar isKindOfClass:[OWSNavigationBar class]]) { + OWSFailDebug(@"navigationBar was unexpected class: %@", self.navigationBar); + return; + } + OWSNavigationBar *navbar = (OWSNavigationBar *)self.navigationBar; + navbar.navBarLayoutDelegate = self; + [self updateLayoutForNavbar:navbar]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(themeDidChange:) + name:ThemeDidChangeNotification + object:nil]; +} + // All OWSNavigationController serve as the UINavigationBarDelegate for their navbar. // We override shouldPopItem: in order to cancel some back button presses - for example, // if a view has unsaved changes.