diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 85f072f92..5571ea35c 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -137,6 +137,11 @@ static NSTimeInterval launchStartedAt; return SSKEnvironment.shared.messageManager; } +- (OWSWindowManager *)windowManager +{ + return Environment.shared.windowManager; +} + #pragma mark - - (void)applicationDidEnterBackground:(UIApplication *)application { @@ -919,6 +924,23 @@ static NSTimeInterval launchStartedAt; return NO; } +#pragma mark - Orientation + +- (UIInterfaceOrientationMask)application:(UIApplication *)application + supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window +{ + if (self.windowManager.rootWindow != window) { + return UIInterfaceOrientationMaskPortrait; + } + + if (self.windowManager.hasCall) { + // The call-banner window is only suitable for portrait display + return UIInterfaceOrientationMaskPortrait; + } + + return UIInterfaceOrientationMaskAllButUpsideDown; +} + #pragma mark Push Notifications Delegate Methods - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { diff --git a/Signal/src/ViewControllers/LoadingViewController.swift b/Signal/src/ViewControllers/LoadingViewController.swift index 172d8ed49..18f491413 100644 --- a/Signal/src/ViewControllers/LoadingViewController.swift +++ b/Signal/src/ViewControllers/LoadingViewController.swift @@ -90,6 +90,14 @@ public class LoadingViewController: UIViewController { } } + // MARK: Orientation + + override public var supportedInterfaceOrientations: UIInterfaceOrientationMask { + return .portrait + } + + // MARK: + private func buildLabel() -> UILabel { let label = UILabel() diff --git a/Signal/src/ViewControllers/MediaGalleryViewController.swift b/Signal/src/ViewControllers/MediaGalleryViewController.swift index 019dc7f09..694e49863 100644 --- a/Signal/src/ViewControllers/MediaGalleryViewController.swift +++ b/Signal/src/ViewControllers/MediaGalleryViewController.swift @@ -205,6 +205,14 @@ class MediaGalleryViewController: OWSNavigationController, MediaGalleryDataSourc notImplemented() } + // MARK: View LifeCycle + + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + // If the user's device is already rotated, try to respect that by rotating to landscape now + UIViewController.attemptRotationToDeviceOrientation() + } + // HACK: Though we don't have an input accessory view, the VC we are presented above (ConversationVC) does. // If the app is backgrounded and then foregrounded, when OWSWindowManager calls mainWindow.makeKeyAndVisible // the ConversationVC's inputAccessoryView will appear *above* us unless we'd previously become first responder. @@ -908,4 +916,10 @@ class MediaGalleryViewController: OWSNavigationController, MediaGalleryDataSourc } return Int(count) - deletedMessages.count } + + // MARK: Orientation + + public override var supportedInterfaceOrientations: UIInterfaceOrientationMask { + return .allButUpsideDown + } } diff --git a/Signal/src/ViewControllers/MediaPageViewController.swift b/Signal/src/ViewControllers/MediaPageViewController.swift index a98607093..990790a27 100644 --- a/Signal/src/ViewControllers/MediaPageViewController.swift +++ b/Signal/src/ViewControllers/MediaPageViewController.swift @@ -510,7 +510,10 @@ class MediaPageViewController: UIPageViewController, UIPageViewControllerDataSou return } - mediaGalleryDataSource.dismissMediaDetailViewController(self, animated: isAnimated, completion: completion) + mediaGalleryDataSource.dismissMediaDetailViewController(self, animated: isAnimated) { + UIDevice.current.ows_setOrientation(.portrait) + completion?() + } } // MARK: MediaDetailViewControllerDelegate diff --git a/Signal/src/ViewControllers/MenuActionsViewController.swift b/Signal/src/ViewControllers/MenuActionsViewController.swift index 42b49aaaa..8d16c123d 100644 --- a/Signal/src/ViewControllers/MenuActionsViewController.swift +++ b/Signal/src/ViewControllers/MenuActionsViewController.swift @@ -90,6 +90,12 @@ class MenuActionsViewController: UIViewController, MenuActionSheetDelegate { ensureDelegateIsInformedThatDisappearenceCompleted() } + // MARK: Orientation + + override var supportedInterfaceOrientations: UIInterfaceOrientationMask { + return .portrait + } + // MARK: Present / Dismiss animations var presentationFocusOffset: CGFloat? diff --git a/SignalMessaging/ViewControllers/OWSNavigationController.m b/SignalMessaging/ViewControllers/OWSNavigationController.m index 9c45f4ca3..875b0deaa 100644 --- a/SignalMessaging/ViewControllers/OWSNavigationController.m +++ b/SignalMessaging/ViewControllers/OWSNavigationController.m @@ -172,6 +172,13 @@ NS_ASSUME_NONNULL_BEGIN [UIView setAnimationsEnabled:YES]; } +#pragma mark - Orientation + +- (UIInterfaceOrientationMask)supportedInterfaceOrientations +{ + return UIInterfaceOrientationMaskPortrait; +} + @end NS_ASSUME_NONNULL_END diff --git a/SignalMessaging/ViewControllers/OWSViewController.m b/SignalMessaging/ViewControllers/OWSViewController.m index 9846aecf8..8ed439d0a 100644 --- a/SignalMessaging/ViewControllers/OWSViewController.m +++ b/SignalMessaging/ViewControllers/OWSViewController.m @@ -177,6 +177,13 @@ NS_ASSUME_NONNULL_BEGIN [self.bottomLayoutView.superview layoutIfNeeded]; } +#pragma mark - Orientation + +- (UIInterfaceOrientationMask)supportedInterfaceOrientations +{ + return UIInterfaceOrientationMaskPortrait; +} + @end NS_ASSUME_NONNULL_END diff --git a/SignalMessaging/ViewControllers/ReturnToCallViewController.swift b/SignalMessaging/ViewControllers/ReturnToCallViewController.swift index 794ee65cb..76c7ce61f 100644 --- a/SignalMessaging/ViewControllers/ReturnToCallViewController.swift +++ b/SignalMessaging/ViewControllers/ReturnToCallViewController.swift @@ -77,4 +77,11 @@ public class ReturnToCallViewController: UIViewController { super.viewDidLayoutSubviews() } + + // MARK: Orientation + + public override var supportedInterfaceOrientations: UIInterfaceOrientationMask { + return .portrait + } + } diff --git a/SignalMessaging/ViewControllers/ScreenLockViewController.m b/SignalMessaging/ViewControllers/ScreenLockViewController.m index 24659c879..d2f5543e7 100644 --- a/SignalMessaging/ViewControllers/ScreenLockViewController.m +++ b/SignalMessaging/ViewControllers/ScreenLockViewController.m @@ -147,4 +147,11 @@ NSString *NSStringForScreenLockUIState(ScreenLockUIState value) return YES; } +#pragma mark - Orientation + +- (UIInterfaceOrientationMask)supportedInterfaceOrientations +{ + return UIInterfaceOrientationMaskPortrait; +} + @end diff --git a/SignalMessaging/Views/OWSNavigationBar.swift b/SignalMessaging/Views/OWSNavigationBar.swift index deae451a0..f28c9b08f 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/categories/UIDevice+featureSupport.swift b/SignalMessaging/categories/UIDevice+featureSupport.swift index cf4fff9b4..c5c450eb9 100644 --- a/SignalMessaging/categories/UIDevice+featureSupport.swift +++ b/SignalMessaging/categories/UIDevice+featureSupport.swift @@ -53,4 +53,16 @@ public extension UIDevice { return isNativeIPad || isCompatabilityModeIPad } + + public func ows_setOrientation(_ orientation: UIInterfaceOrientation) { + // XXX - This is not officially supported, but there's no other way to programmatically rotate + // the interface. + let orientationKey = "orientation" + self.setValue(orientation.rawValue, forKey: orientationKey) + + // Not strictly necessary for the orientation to appear as changed + // but allegedly helps ensure related rotation delegate methods are called. + // https://stackoverflow.com/questions/20987249/how-do-i-programmatically-set-device-orientation-in-ios7 + UINavigationController.attemptRotationToDeviceOrientation() + } } diff --git a/SignalMessaging/utils/OWSWindowManager.h b/SignalMessaging/utils/OWSWindowManager.h index 6696dbd2d..2ae99cad8 100644 --- a/SignalMessaging/utils/OWSWindowManager.h +++ b/SignalMessaging/utils/OWSWindowManager.h @@ -26,6 +26,8 @@ extern const UIWindowLevel UIWindowLevel_Background; - (void)setupWithRootWindow:(UIWindow *)rootWindow screenBlockingWindow:(UIWindow *)screenBlockingWindow; +@property (nonatomic, readonly) UIWindow *rootWindow; + - (void)setIsScreenBlockActive:(BOOL)isScreenBlockActive; #pragma mark - Message Actions diff --git a/SignalMessaging/utils/OWSWindowManager.m b/SignalMessaging/utils/OWSWindowManager.m index f64658875..be1f429c5 100644 --- a/SignalMessaging/utils/OWSWindowManager.m +++ b/SignalMessaging/utils/OWSWindowManager.m @@ -91,6 +91,13 @@ const UIWindowLevel UIWindowLevel_MessageActions(void) return YES; } +#pragma mark - Orientation + +- (UIInterfaceOrientationMask)supportedInterfaceOrientations +{ + return UIInterfaceOrientationMaskPortrait; +} + @end #pragma mark - @@ -259,7 +266,8 @@ const UIWindowLevel UIWindowLevel_MessageActions(void) OWSAssertDebug(!self.callNavigationController); self.callNavigationController = navigationController; - window.rootViewController = navigationController; + // MJK DO NOT COMMIT. + window.rootViewController = viewController; return window; }