From 7a990ed1ff5b429fd75a28878b4be9683fc46994 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 1 Feb 2019 10:13:44 -0500 Subject: [PATCH 1/4] Ensure 'link new device' view is portrait. --- .../AppSettings/OWSLinkDeviceViewController.m | 58 +++++++++++-------- .../categories/UIDevice+featureSupport.swift | 3 +- SignalMessaging/categories/UIView+OWS.swift | 32 ++++++++++ .../categories/UIViewController+OWS.m | 14 ++--- 4 files changed, 76 insertions(+), 31 deletions(-) diff --git a/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.m b/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.m index 7e707980a..42c74cac7 100644 --- a/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.m +++ b/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.m @@ -111,19 +111,16 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - -- (void)viewWillAppear:(BOOL)animated -{ - [super viewWillAppear:animated]; -} - - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self.qrScanningController startCapture]; + + [UIDevice.currentDevice ows_setOrientation:UIInterfaceOrientationPortrait]; } -// pragma mark - OWSQRScannerDelegate +#pragma mark - OWSQRScannerDelegate - (void)controller:(OWSQRCodeScanningViewController *)controller didDetectQRCodeWithString:(NSString *)string { @@ -137,14 +134,13 @@ NS_ASSUME_NONNULL_BEGIN UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:body preferredStyle:UIAlertControllerStyleAlert]; - UIAlertAction *cancelAction = - [UIAlertAction actionWithTitle:CommonStrings.cancelButton - style:UIAlertActionStyleCancel - handler:^(UIAlertAction *action) { - dispatch_async(dispatch_get_main_queue(), ^{ - [self.navigationController popViewControllerAnimated:YES]; - }); - }]; + UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:CommonStrings.cancelButton + style:UIAlertActionStyleCancel + handler:^(UIAlertAction *action) { + dispatch_async(dispatch_get_main_queue(), ^{ + [self popToLinkedDeviceList]; + }); + }]; [alertController addAction:cancelAction]; UIAlertAction *proceedAction = @@ -166,14 +162,13 @@ NS_ASSUME_NONNULL_BEGIN message:linkingDescription preferredStyle:UIAlertControllerStyleAlert]; - UIAlertAction *cancelAction = - [UIAlertAction actionWithTitle:CommonStrings.cancelButton - style:UIAlertActionStyleCancel - handler:^(UIAlertAction *action) { - dispatch_async(dispatch_get_main_queue(), ^{ - [self.navigationController popViewControllerAnimated:YES]; - }); - }]; + UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:CommonStrings.cancelButton + style:UIAlertActionStyleCancel + handler:^(UIAlertAction *action) { + dispatch_async(dispatch_get_main_queue(), ^{ + [self popToLinkedDeviceList]; + }); + }]; [alertController addAction:cancelAction]; UIAlertAction *proceedAction = @@ -214,7 +209,7 @@ NS_ASSUME_NONNULL_BEGIN OWSLogInfo(@"Successfully provisioned device."); dispatch_async(dispatch_get_main_queue(), ^{ [self.linkedDevicesTableViewController expectMoreDevices]; - [self.navigationController popToViewController:self.linkedDevicesTableViewController animated:YES]; + [self popToAppSettings]; // The service implementation of the socket connection caches the linked device state, // so all sync message sends will fail on the socket until it is cycled. @@ -264,6 +259,23 @@ NS_ASSUME_NONNULL_BEGIN return alertController; } +- (void)popToLinkedDeviceList +{ + [self.navigationController popViewControllerWithAnimated:YES + completion:^{ + [UIViewController attemptRotationToDeviceOrientation]; + }]; +} + +- (void)popToAppSettings +{ + [self.navigationController popToViewControllerWithViewController:self.linkedDevicesTableViewController + animated:YES + completion:^{ + [UIViewController attemptRotationToDeviceOrientation]; + }]; +} + #pragma mark - Orientation - (UIInterfaceOrientationMask)supportedInterfaceOrientations diff --git a/SignalMessaging/categories/UIDevice+featureSupport.swift b/SignalMessaging/categories/UIDevice+featureSupport.swift index c5c450eb9..26f1ba3a9 100644 --- a/SignalMessaging/categories/UIDevice+featureSupport.swift +++ b/SignalMessaging/categories/UIDevice+featureSupport.swift @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // import Foundation @@ -54,6 +54,7 @@ public extension UIDevice { return isNativeIPad || isCompatabilityModeIPad } + @objc public func ows_setOrientation(_ orientation: UIInterfaceOrientation) { // XXX - This is not officially supported, but there's no other way to programmatically rotate // the interface. diff --git a/SignalMessaging/categories/UIView+OWS.swift b/SignalMessaging/categories/UIView+OWS.swift index 089346665..1ea3c908c 100644 --- a/SignalMessaging/categories/UIView+OWS.swift +++ b/SignalMessaging/categories/UIView+OWS.swift @@ -12,3 +12,35 @@ public extension UIEdgeInsets { right: CurrentAppContext().isRTL ? leading : trailing) } } + +@objc +public extension UINavigationController { + @objc + public func pushViewController(viewController: UIViewController, + animated: Bool, + completion: (() -> Void)?) { + CATransaction.begin() + CATransaction.setCompletionBlock(completion) + pushViewController(viewController, animated: animated) + CATransaction.commit() + } + + @objc + public func popViewController(animated: Bool, + completion: (() -> Void)?) { + CATransaction.begin() + CATransaction.setCompletionBlock(completion) + popViewController(animated: animated) + CATransaction.commit() + } + + @objc + public func popToViewController(viewController: UIViewController, + animated: Bool, + completion: (() -> Void)?) { + CATransaction.begin() + CATransaction.setCompletionBlock(completion) + self.popToViewController(viewController, animated: animated) + CATransaction.commit() + } +} diff --git a/SignalMessaging/categories/UIViewController+OWS.m b/SignalMessaging/categories/UIViewController+OWS.m index 86a231323..eb923067f 100644 --- a/SignalMessaging/categories/UIViewController+OWS.m +++ b/SignalMessaging/categories/UIViewController+OWS.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // #import "Theme.h" @@ -19,13 +19,13 @@ NS_ASSUME_NONNULL_BEGIN while (YES) { UIViewController *_Nullable nextViewController = viewController.presentedViewController; if (nextViewController) { - if (ignoringAlerts) { - if ([nextViewController isKindOfClass:[UIAlertController class]]) { - break; - } + if (!ignoringAlerts || ![nextViewController isKindOfClass:[UIAlertController class]]) { + viewController = nextViewController; + continue; } - viewController = nextViewController; - } else if ([viewController isKindOfClass:[UINavigationController class]]) { + } + + if ([viewController isKindOfClass:[UINavigationController class]]) { UINavigationController *navigationController = (UINavigationController *)viewController; if (navigationController.topViewController) { viewController = navigationController.topViewController; From bf685776be5a647464c18dacecb319a54d0941e3 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 1 Feb 2019 10:18:35 -0500 Subject: [PATCH 2/4] Ensure 'link new device' view is portrait. --- .../AppSettings/OWSLinkDeviceViewController.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.m b/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.m index 42c74cac7..ccb8593ed 100644 --- a/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.m +++ b/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.m @@ -115,9 +115,11 @@ NS_ASSUME_NONNULL_BEGIN { [super viewDidAppear:animated]; - [self.qrScanningController startCapture]; - [UIDevice.currentDevice ows_setOrientation:UIInterfaceOrientationPortrait]; + + dispatch_async(dispatch_get_main_queue(), ^{ + [self.qrScanningController startCapture]; + }); } #pragma mark - OWSQRScannerDelegate From 6bfe0f0418df97b00fd9ee3fffa02b5b40a293d6 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 1 Feb 2019 10:22:33 -0500 Subject: [PATCH 3/4] Ensure 'link new device' view is portrait. --- .../categories/UIViewController+OWS.m | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/SignalMessaging/categories/UIViewController+OWS.m b/SignalMessaging/categories/UIViewController+OWS.m index eb923067f..04c1ba1d8 100644 --- a/SignalMessaging/categories/UIViewController+OWS.m +++ b/SignalMessaging/categories/UIViewController+OWS.m @@ -15,11 +15,19 @@ NS_ASSUME_NONNULL_BEGIN - (UIViewController *)findFrontmostViewController:(BOOL)ignoringAlerts { + NSMutableArray *visitedViewControllers = [NSMutableArray new]; + UIViewController *viewController = self; while (YES) { + [visitedViewControllers addObject:viewController]; + UIViewController *_Nullable nextViewController = viewController.presentedViewController; if (nextViewController) { if (!ignoringAlerts || ![nextViewController isKindOfClass:[UIAlertController class]]) { + if ([visitedViewControllers containsObject:nextViewController]) { + // Cycle detected. + return viewController; + } viewController = nextViewController; continue; } @@ -27,8 +35,13 @@ NS_ASSUME_NONNULL_BEGIN if ([viewController isKindOfClass:[UINavigationController class]]) { UINavigationController *navigationController = (UINavigationController *)viewController; - if (navigationController.topViewController) { - viewController = navigationController.topViewController; + nextViewController = navigationController.topViewController; + if (nextViewController) { + if ([visitedViewControllers containsObject:nextViewController]) { + // Cycle detected. + return viewController; + } + viewController = nextViewController; } else { break; } From 4cbe3236e40179f2ad982137a92757a726634034 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 1 Feb 2019 17:39:37 -0500 Subject: [PATCH 4/4] Respond to CR. --- .../AppSettings/OWSLinkDeviceViewController.m | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.m b/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.m index ccb8593ed..b704db862 100644 --- a/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.m +++ b/Signal/src/ViewControllers/AppSettings/OWSLinkDeviceViewController.m @@ -211,7 +211,7 @@ NS_ASSUME_NONNULL_BEGIN OWSLogInfo(@"Successfully provisioned device."); dispatch_async(dispatch_get_main_queue(), ^{ [self.linkedDevicesTableViewController expectMoreDevices]; - [self popToAppSettings]; + [self popToLinkedDeviceList]; // The service implementation of the socket connection caches the linked device state, // so all sync message sends will fail on the socket until it is cycled. @@ -269,15 +269,6 @@ NS_ASSUME_NONNULL_BEGIN }]; } -- (void)popToAppSettings -{ - [self.navigationController popToViewControllerWithViewController:self.linkedDevicesTableViewController - animated:YES - completion:^{ - [UIViewController attemptRotationToDeviceOrientation]; - }]; -} - #pragma mark - Orientation - (UIInterfaceOrientationMask)supportedInterfaceOrientations