From 319a6ff765fad2918630ca195b7707356e52fb2c Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Thu, 17 May 2018 14:52:46 -0400 Subject: [PATCH] fixup behavior on iOS10 --- Signal/src/AppDelegate.m | 4 +- .../ViewControllers/OWSNavigationController.m | 28 +++++--- SignalMessaging/Views/OWSNavigationBar.swift | 67 ++++++++++--------- 3 files changed, 56 insertions(+), 43 deletions(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index cd1d2dd04..4f041a9d3 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -1099,8 +1099,8 @@ static NSTimeInterval launchStartedAt; // Resume lazy restore. [OWSBackupLazyRestoreJob runAsync]; #endif - - + + // MJK FIXME OutboundCallInitiator *outboundCallInitiator = SignalApp.sharedApp.outboundCallInitiator; [outboundCallInitiator initiateCallWithHandle:@"+14158181337"]; } diff --git a/SignalMessaging/ViewControllers/OWSNavigationController.m b/SignalMessaging/ViewControllers/OWSNavigationController.m index f938ac700..46f29e8e0 100644 --- a/SignalMessaging/ViewControllers/OWSNavigationController.m +++ b/SignalMessaging/ViewControllers/OWSNavigationController.m @@ -7,7 +7,6 @@ NS_ASSUME_NONNULL_BEGIN - @interface OWSNavigationController (OWSNavigationController) @end @@ -50,10 +49,10 @@ NS_ASSUME_NONNULL_BEGIN // Attempt 7: Since we can't seem to *shrink* the navbar, maybe we can grow it. // make additionalSafeAreaInsets - [self updateAdditionalSafeAreaInsets]; - self = [self initWithNavigationBarClass:[OWSNavigationBar class] toolbarClass:nil]; [self pushViewController:rootViewController animated:NO]; + + [self updateNavbarCallBannerLayout]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowManagerCallDidChange:) @@ -66,15 +65,28 @@ NS_ASSUME_NONNULL_BEGIN - (void)windowManagerCallDidChange:(NSNotification *)notification { DDLogDebug(@"%@ in %s", self.logTag, __PRETTY_FUNCTION__); - [self updateAdditionalSafeAreaInsets]; + [self updateNavbarCallBannerLayout]; } -- (void)updateAdditionalSafeAreaInsets +- (void)updateNavbarCallBannerLayout { - if (OWSWindowManager.sharedManager.hasCall) { - self.additionalSafeAreaInsets = UIEdgeInsetsMake(64, 0, 0, 0); + if (@available(iOS 11.0, *)) { + if (OWSWindowManager.sharedManager.hasCall) { + self.additionalSafeAreaInsets = UIEdgeInsetsMake(64, 0, 0, 0); + } else { + self.additionalSafeAreaInsets = UIEdgeInsetsZero; + } } else { - self.additionalSafeAreaInsets = UIEdgeInsetsZero; + if (![self.navigationBar isKindOfClass:[OWSNavigationBar class]]) { + OWSFail(@"%@ in %s navigationBar was unexpected class", self.logTag, __PRETTY_FUNCTION__); + return; + } + + OWSNavigationBar *navBar = (OWSNavigationBar *)self.navigationBar; + CGRect oldFrame = navBar.frame; + CGRect newFrame + = CGRectMake(oldFrame.origin.x, navBar.statusBarHeight, oldFrame.size.width, oldFrame.size.height); + navBar.frame = newFrame; } } diff --git a/SignalMessaging/Views/OWSNavigationBar.swift b/SignalMessaging/Views/OWSNavigationBar.swift index cc80768b4..113816a31 100644 --- a/SignalMessaging/Views/OWSNavigationBar.swift +++ b/SignalMessaging/Views/OWSNavigationBar.swift @@ -10,32 +10,34 @@ class OWSNavigationBar: UINavigationBar { // TODO - get a more precise value // TODO - test with other heights, e.g. w/ hotspot, w/ call in other app - let navbarHeight: CGFloat = 44 + let navbarWithoutStatusHeight: CGFloat = 44 let callBannerHeight: CGFloat = 40 + // MJK safe to hardcode? Do we even need this approach anymore? + var statusBarHeight: CGFloat { + // TODO? plumb through CurrentAppContext() + return 20 + } + override init(frame: CGRect) { super.init(frame: frame) self.isTranslucent = false - // TODO better place to observe? - NotificationCenter.default.addObserver(forName: .OWSWindowManagerCallDidChange, object: nil, queue: nil) { _ in - Logger.debug("\(self.logTag) in \(#function) OWSWindowManagerCallDidChange") - - self.callDidChange() - } + NotificationCenter.default.addObserver(self, selector: #selector(callDidChange), name: .OWSWindowManagerCallDidChange, object: nil) } - private func callDidChange() { -// if OWSWindowManager.shared().hasCall() { -// self.bounds.origin.y = -20 -// } else { -// self.bounds.origin.y = 0 -// } + @objc + public func callDidChange() { + Logger.debug("\(self.logTag) in \(#function) OWSWindowManagerCallDidChange") + if #available(iOS 11, *) { self.layoutSubviews() } else { self.sizeToFit() + self.frame.origin.y = statusBarHeight + + self.layoutSubviews() } } @@ -44,24 +46,22 @@ class OWSNavigationBar: UINavigationBar { } override func sizeThatFits(_ size: CGSize) -> CGSize { - // pre iOS11, sizeThatFits is repeatedly called to size the navbar, which is pretty straight forward - // as of iOS11, this is not true and we have to do things in layoutSubviews. - // FIXME: pre-iOS11, though the size is right, there's a glitch on the titleView while push/popping items. - - // MJK safe to hardcode? Do we even need this approach anymore? - let statusBarHeight: CGFloat = 20 - let result: CGSize = { - if OWSWindowManager.shared().hasCall() { - // status bar height gets re-added - return CGSize(width: CurrentAppContext().mainWindow!.bounds.width, height: navbarHeight - statusBarHeight) - } else { - return super.sizeThatFits(size) - } - }() + guard OWSWindowManager.shared().hasCall() else { + return super.sizeThatFits(size) + } - Logger.debug("\(self.logTag) in \(#function): \(result)") + if #available(iOS 11, *) { + return super.sizeThatFits(size) + } else { + // pre iOS11, sizeThatFits is repeatedly called to size the navbar + // as of iOS11, this is not true and we have to size things in layoutSubviews. + // FIXME: pre-iOS11, though the size is right, there's a glitch on the titleView while push/popping items. + let result = CGSize(width: CurrentAppContext().mainWindow!.bounds.width, height: navbarWithoutStatusHeight + statusBarHeight) + + Logger.debug("\(self.logTag) in \(#function): \(result)") - return result + return result + } } // override var center: CGPoint { @@ -83,7 +83,7 @@ class OWSNavigationBar: UINavigationBar { // seems unused. // override var intrinsicContentSize: CGSize { -// return CGSize(width: UIScreen.main.bounds.width, height: navbarHeight) +// return CGSize(width: UIScreen.main.bounds.width, height: navbarWithoutStatusHeight) // return CGSize(width: UIScreen.main.bounds.width, height: 20) // } @@ -108,15 +108,16 @@ class OWSNavigationBar: UINavigationBar { override func layoutSubviews() { Logger.debug("\(self.logTag) in \(#function)") - guard #available(iOS 11.0, *), OWSWindowManager.shared().hasCall() else { + guard OWSWindowManager.shared().hasCall() else { +// guard #available(iOS 11.0, *), OWSWindowManager.shared().hasCall() else { super.layoutSubviews() return } // let rect = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: self.navbarHeightWithoutStatusBar) // self.frame = CGRect(x: 0, y: 20, width: UI Screen.main.bounds.width, height: ios11NavbarHeight) - self.frame = CGRect(x: 0, y: callBannerHeight, width: UIScreen.main.bounds.width, height: navbarHeight) - self.bounds = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: navbarHeight) + self.frame = CGRect(x: 0, y: callBannerHeight, width: UIScreen.main.bounds.width, height: navbarWithoutStatusHeight) + self.bounds = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: navbarWithoutStatusHeight) super.layoutSubviews()