From 20424d9a7e1e0014739e4ba5f2ae8e9c4cfc3761 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Mon, 21 May 2018 16:00:35 -0400 Subject: [PATCH] remove debug code, reorder for clarity // FREEBIE --- .../ViewControllers/OWSNavigationController.m | 93 ++++++++++--------- SignalMessaging/Views/OWSNavigationBar.swift | 8 +- SignalMessaging/utils/OWSWindowManager.m | 23 +++-- 3 files changed, 62 insertions(+), 62 deletions(-) diff --git a/SignalMessaging/ViewControllers/OWSNavigationController.m b/SignalMessaging/ViewControllers/OWSNavigationController.m index cd85fc451..23a2e1571 100644 --- a/SignalMessaging/ViewControllers/OWSNavigationController.m +++ b/SignalMessaging/ViewControllers/OWSNavigationController.m @@ -38,51 +38,6 @@ NS_ASSUME_NONNULL_BEGIN return self; } -- (void)navBarCallLayoutDidChangeWithNavbar:(OWSNavigationBar *)navbar -{ - [self updateLayoutForNavbar:navbar]; -} - -- (void)updateLayoutForNavbar:(OWSNavigationBar *)navbar -{ - DDLogDebug(@"%@ in %s", self.logTag, __PRETTY_FUNCTION__); - - if (@available(iOS 11.0, *)) { - if (OWSWindowManager.sharedManager.hasCall) { - if (UIDevice.currentDevice.isIPhoneX) { - // iPhoneX computes status bar height differently. - self.additionalSafeAreaInsets = UIEdgeInsetsMake(navbar.navbarWithoutStatusHeight + 20, 0, 0, 0); - } else { - self.additionalSafeAreaInsets - = UIEdgeInsetsMake(navbar.navbarWithoutStatusHeight + CurrentAppContext().statusBarHeight, 0, 0, 0); - } - } else { - self.additionalSafeAreaInsets = UIEdgeInsetsZero; - } - // in iOS11 we have to ensure the navbar frame *in* layoutSubviews. - [navbar layoutSubviews]; - } else { - // Pre iOS11 we size the navbar, and position it vertically once. - [navbar sizeToFit]; - - if (OWSWindowManager.sharedManager.hasCall) { - CGRect oldFrame = navbar.frame; - CGRect newFrame - = CGRectMake(oldFrame.origin.x, navbar.callBannerHeight, oldFrame.size.width, oldFrame.size.height); - navbar.frame = newFrame; - } else { - CGRect oldFrame = navbar.frame; - CGRect newFrame - = CGRectMake(oldFrame.origin.x, navbar.statusBarHeight, oldFrame.size.width, oldFrame.size.height); - navbar.frame = newFrame; - } - - // Since the navbar's frame was updated, we need to be sure our child VC's - // container view is updated. - [self.view setNeedsLayout]; - } -} - - (void)viewDidLoad { [super viewDidLoad]; @@ -138,6 +93,54 @@ NS_ASSUME_NONNULL_BEGIN } } + +#pragma mark - NavBarLayoutDelegate + +- (void)navBarCallLayoutDidChangeWithNavbar:(OWSNavigationBar *)navbar +{ + [self updateLayoutForNavbar:navbar]; +} + +- (void)updateLayoutForNavbar:(OWSNavigationBar *)navbar +{ + DDLogDebug(@"%@ in %s", self.logTag, __PRETTY_FUNCTION__); + + if (@available(iOS 11.0, *)) { + if (OWSWindowManager.sharedManager.hasCall) { + if (UIDevice.currentDevice.isIPhoneX) { + // iPhoneX computes status bar height differently. + self.additionalSafeAreaInsets = UIEdgeInsetsMake(navbar.navbarWithoutStatusHeight + 20, 0, 0, 0); + } else { + self.additionalSafeAreaInsets + = UIEdgeInsetsMake(navbar.navbarWithoutStatusHeight + CurrentAppContext().statusBarHeight, 0, 0, 0); + } + } else { + self.additionalSafeAreaInsets = UIEdgeInsetsZero; + } + // in iOS11 we have to ensure the navbar frame *in* layoutSubviews. + [navbar layoutSubviews]; + } else { + // Pre iOS11 we size the navbar, and position it vertically once. + [navbar sizeToFit]; + + if (OWSWindowManager.sharedManager.hasCall) { + CGRect oldFrame = navbar.frame; + CGRect newFrame + = CGRectMake(oldFrame.origin.x, navbar.callBannerHeight, oldFrame.size.width, oldFrame.size.height); + navbar.frame = newFrame; + } else { + CGRect oldFrame = navbar.frame; + CGRect newFrame + = CGRectMake(oldFrame.origin.x, navbar.statusBarHeight, oldFrame.size.width, oldFrame.size.height); + navbar.frame = newFrame; + } + + // Since the navbar's frame was updated, we need to be sure our child VC's + // container view is updated. + [self.view setNeedsLayout]; + } +} + @end NS_ASSUME_NONNULL_END diff --git a/SignalMessaging/Views/OWSNavigationBar.swift b/SignalMessaging/Views/OWSNavigationBar.swift index 04be1803a..f1250afc6 100644 --- a/SignalMessaging/Views/OWSNavigationBar.swift +++ b/SignalMessaging/Views/OWSNavigationBar.swift @@ -65,17 +65,11 @@ class OWSNavigationBar: UINavigationBar { // pre iOS11, sizeThatFits is repeatedly called to determine how much space to reserve for that navbar. // That is, increasing this causes the child view controller to be pushed down. // (as of iOS11, this is not used and instead we use additionalSafeAreaInsets) - let result = CGSize(width: fullWidth, height: navbarWithoutStatusHeight + statusBarHeight) - - Logger.debug("\(self.logTag) in \(#function): \(result)") - - return result + return CGSize(width: fullWidth, height: navbarWithoutStatusHeight + statusBarHeight) } } override func layoutSubviews() { - Logger.debug("\(self.logTag) in \(#function) with frame: \(frame)") - guard OWSWindowManager.shared().hasCall() else { super.layoutSubviews() return diff --git a/SignalMessaging/utils/OWSWindowManager.m b/SignalMessaging/utils/OWSWindowManager.m index a1ede3eae..8beae7885 100644 --- a/SignalMessaging/utils/OWSWindowManager.m +++ b/SignalMessaging/utils/OWSWindowManager.m @@ -28,10 +28,6 @@ const CGFloat OWSWindowManagerCallScreenHeight(void) // Behind everything, especially the root window. const UIWindowLevel UIWindowLevel_Background = -1.f; -// Putting the call banner above the status bar is not ideal. -// It obscures status bar content like the system clock -// But being behind the status bar introduces two worse problems that'd we'd need to address -// 1. Tap target is too small, only the 20px below the status bar are tappable const UIWindowLevel UIWindowLevel_ReturnToCall(void); const UIWindowLevel UIWindowLevel_ReturnToCall(void) { @@ -124,9 +120,6 @@ const UIWindowLevel UIWindowLevel_ScreenBlocking(void) OWSAssert(screenBlockingWindow); OWSAssert(!self.screenBlockingWindow); - // MJK FIXME - rootWindow.backgroundColor = UIColor.yellowColor; - self.rootWindow = rootWindow; self.screenBlockingWindow = screenBlockingWindow; @@ -211,6 +204,19 @@ const UIWindowLevel UIWindowLevel_ScreenBlocking(void) #pragma mark - Calls +- (void)setCallViewController:(nullable UIViewController *)callViewController +{ + OWSAssertIsOnMainThread(); + + if (callViewController == _callViewController) { + return; + } + + _callViewController = callViewController; + + [NSNotificationCenter.defaultCenter postNotificationName:OWSWindowManagerCallDidChangeNotification object:nil]; +} + - (void)startCall:(UIViewController *)callViewController { OWSAssertIsOnMainThread(); @@ -218,8 +224,6 @@ const UIWindowLevel UIWindowLevel_ScreenBlocking(void) OWSAssert(!self.callViewController); self.callViewController = callViewController; - // TODO move to setter? - [NSNotificationCenter.defaultCenter postNotificationName:OWSWindowManagerCallDidChangeNotification object:nil]; // Attach callViewController to window. [self.callNavigationController popToRootViewControllerAnimated:NO]; @@ -243,7 +247,6 @@ const UIWindowLevel UIWindowLevel_ScreenBlocking(void) // Dettach callViewController from window. [self.callNavigationController popToRootViewControllerAnimated:NO]; self.callViewController = nil; - [NSNotificationCenter.defaultCenter postNotificationName:OWSWindowManagerCallDidChangeNotification object:nil]; self.shouldShowCallView = NO;