From 85a4fc7b6672cf3462ba6144beb580065870e349 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Thu, 25 Oct 2018 11:46:48 -0600 Subject: [PATCH] restore calling banner The `statusBarDidChange` is called when entering but not leaving landscape mode we we've got to update manually before showing the call banner. --- SignalMessaging/Views/OWSNavigationBar.swift | 2 +- SignalMessaging/utils/OWSWindowManager.m | 35 ++++++++++++++++---- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/SignalMessaging/Views/OWSNavigationBar.swift b/SignalMessaging/Views/OWSNavigationBar.swift index f28c9b08f..deae451a0 100644 --- a/SignalMessaging/Views/OWSNavigationBar.swift +++ b/SignalMessaging/Views/OWSNavigationBar.swift @@ -48,7 +48,7 @@ public class OWSNavigationBar: UINavigationBar { 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(didChangeStatusBarFrame), name: .UIApplicationDidChangeStatusBarFrame, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(themeDidChange), name: .ThemeDidChange, diff --git a/SignalMessaging/utils/OWSWindowManager.m b/SignalMessaging/utils/OWSWindowManager.m index be1f429c5..d346e128a 100644 --- a/SignalMessaging/utils/OWSWindowManager.m +++ b/SignalMessaging/utils/OWSWindowManager.m @@ -19,7 +19,6 @@ const CGFloat OWSWindowManagerCallBannerHeight(void) return CurrentAppContext().statusBarHeight + 20; } - if (![UIDevice currentDevice].hasIPhoneXNotch) { return CurrentAppContext().statusBarHeight + 20; } @@ -100,6 +99,21 @@ const UIWindowLevel UIWindowLevel_MessageActions(void) @end +@interface OWSWindowRootNavigationViewController : UINavigationController + +@end + +@implementation OWSWindowRootNavigationViewController : UINavigationController + +#pragma mark - Orientation + +- (UIInterfaceOrientationMask)supportedInterfaceOrientations +{ + return UIInterfaceOrientationMaskPortrait; +} + +@end + #pragma mark - @interface OWSWindowManager () @@ -185,11 +199,18 @@ const UIWindowLevel UIWindowLevel_MessageActions(void) } - (void)didChangeStatusBarFrame:(NSNotification *)notification +{ + // Apple bug? Upon returning from landscape, this method *is* fired, but both the notification and [UIApplication + // sharedApplication].statusBarFrame still show a height of 0. So to work around we also call + // `ensureReturnToCallWindowFrame` before showing the call banner. + [self ensureReturnToCallWindowFrame]; +} + +- (void)ensureReturnToCallWindowFrame { CGRect newFrame = self.returnToCallWindow.frame; newFrame.size.height = OWSWindowManagerCallBannerHeight(); - - OWSLogDebug(@"StatusBar changed frames - updating returnToCallWindowFrame: %@", NSStringFromCGRect(newFrame)); + OWSLogDebug(@"returnToCallWindowFrame: %@", NSStringFromCGRect(newFrame)); self.returnToCallWindow.frame = newFrame; } @@ -260,14 +281,13 @@ const UIWindowLevel UIWindowLevel_MessageActions(void) // It adjusts the size of the navigation bar to reflect the // call window. We don't want those adjustments made within // the call window itself. - UINavigationController *navigationController = - [[UINavigationController alloc] initWithRootViewController:viewController]; + OWSWindowRootNavigationViewController *navigationController = + [[OWSWindowRootNavigationViewController alloc] initWithRootViewController:viewController]; navigationController.navigationBarHidden = YES; OWSAssertDebug(!self.callNavigationController); self.callNavigationController = navigationController; - // MJK DO NOT COMMIT. - window.rootViewController = viewController; + window.rootViewController = navigationController; return window; } @@ -478,6 +498,7 @@ const UIWindowLevel UIWindowLevel_MessageActions(void) return; } + [self ensureReturnToCallWindowFrame]; OWSLogInfo(@"showing 'return to call' window."); self.returnToCallWindow.hidden = NO; [self.returnToCallViewController startAnimating];