From 856ced4062b0b93cd6129922a3237b0585151bbb Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Thu, 4 Aug 2022 18:26:27 -0700 Subject: [PATCH] Use supportedInterfaceOrientations to force calls to portrait Previously this used UIDevice.ows_setOrientation, an undocumented hack to basically lie to the device about which way is up. This sounds sketchy, but it's the result of a lot of testing various solutions for something that could reliably force the app into portrait orientation. However, every UIWindow has its own "supported orientations", provided by the root view controller. And calls are implemented in their own UIWindow (so that they don't disrupt whatever you were doing). So for *calls specifically*, we can use supportedInterfaceOrientations to force the app into portrait mode. All other callers of UIDevice.ows_setOrientation work in the shared main window, so they'll be left alone. This only changes things for the call window. --- Signal/src/UserInterface/OWSWindowManager.m | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/Signal/src/UserInterface/OWSWindowManager.m b/Signal/src/UserInterface/OWSWindowManager.m index c81568a322..e5956c05a6 100644 --- a/Signal/src/UserInterface/OWSWindowManager.m +++ b/Signal/src/UserInterface/OWSWindowManager.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2021 Open Whisper Systems. All rights reserved. +// Copyright (c) 2022 Open Whisper Systems. All rights reserved. // #import "OWSWindowManager.h" @@ -53,19 +53,19 @@ const UIWindowLevel UIWindowLevel_ScreenBlocking(void) #pragma mark - -@interface OWSWindowRootNavigationViewController : UINavigationController +@interface OWSCallWindowRootNavigationViewController : UINavigationController @end #pragma mark - -@implementation OWSWindowRootNavigationViewController : UINavigationController +@implementation OWSCallWindowRootNavigationViewController : UINavigationController #pragma mark - Orientation - (UIInterfaceOrientationMask)supportedInterfaceOrientations { - return UIDevice.currentDevice.defaultSupportedOrientations; + return UIDevice.currentDevice.isIPad ? UIInterfaceOrientationMaskAll : UIInterfaceOrientationMaskPortrait; } @end @@ -167,8 +167,8 @@ const UIWindowLevel UIWindowLevel_ScreenBlocking(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. - OWSWindowRootNavigationViewController *navigationController = - [[OWSWindowRootNavigationViewController alloc] initWithRootViewController:viewController]; + OWSCallWindowRootNavigationViewController *navigationController = + [[OWSCallWindowRootNavigationViewController alloc] initWithRootViewController:viewController]; navigationController.navigationBarHidden = YES; OWSAssertDebug(!self.callNavigationController); self.callNavigationController = navigationController; @@ -238,11 +238,7 @@ const UIWindowLevel UIWindowLevel_ScreenBlocking(void) [self.callNavigationController popToRootViewControllerAnimated:NO]; [self.callNavigationController pushViewController:callViewController animated:NO]; self.shouldShowCallView = YES; - // CallViewController only supports portrait for iPhones, but if we're _already_ landscape it won't - // automatically switch. - if (!UIDevice.currentDevice.isIPad) { - [UIDevice.currentDevice ows_setOrientation:UIDeviceOrientationPortrait]; - } + [self ensureWindowState]; }