Merge branch 'charlesmchen/linkNewDeviceVsOrientation' into release/2.35.0

pull/1/head
Matthew Chen 6 years ago
commit 94089f1d57

@ -111,19 +111,18 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - #pragma mark -
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated - (void)viewDidAppear:(BOOL)animated
{ {
[super viewDidAppear:animated]; [super viewDidAppear:animated];
[self.qrScanningController startCapture]; [UIDevice.currentDevice ows_setOrientation:UIInterfaceOrientationPortrait];
dispatch_async(dispatch_get_main_queue(), ^{
[self.qrScanningController startCapture];
});
} }
// pragma mark - OWSQRScannerDelegate #pragma mark - OWSQRScannerDelegate
- (void)controller:(OWSQRCodeScanningViewController *)controller didDetectQRCodeWithString:(NSString *)string - (void)controller:(OWSQRCodeScanningViewController *)controller didDetectQRCodeWithString:(NSString *)string
{ {
@ -137,14 +136,13 @@ NS_ASSUME_NONNULL_BEGIN
UIAlertController *alertController = UIAlertController *alertController =
[UIAlertController alertControllerWithTitle:title message:body preferredStyle:UIAlertControllerStyleAlert]; [UIAlertController alertControllerWithTitle:title message:body preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:CommonStrings.cancelButton
[UIAlertAction actionWithTitle:CommonStrings.cancelButton style:UIAlertActionStyleCancel
style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
handler:^(UIAlertAction *action) { dispatch_async(dispatch_get_main_queue(), ^{
dispatch_async(dispatch_get_main_queue(), ^{ [self popToLinkedDeviceList];
[self.navigationController popViewControllerAnimated:YES]; });
}); }];
}];
[alertController addAction:cancelAction]; [alertController addAction:cancelAction];
UIAlertAction *proceedAction = UIAlertAction *proceedAction =
@ -166,14 +164,13 @@ NS_ASSUME_NONNULL_BEGIN
message:linkingDescription message:linkingDescription
preferredStyle:UIAlertControllerStyleAlert]; preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:CommonStrings.cancelButton
[UIAlertAction actionWithTitle:CommonStrings.cancelButton style:UIAlertActionStyleCancel
style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
handler:^(UIAlertAction *action) { dispatch_async(dispatch_get_main_queue(), ^{
dispatch_async(dispatch_get_main_queue(), ^{ [self popToLinkedDeviceList];
[self.navigationController popViewControllerAnimated:YES]; });
}); }];
}];
[alertController addAction:cancelAction]; [alertController addAction:cancelAction];
UIAlertAction *proceedAction = UIAlertAction *proceedAction =
@ -214,7 +211,7 @@ NS_ASSUME_NONNULL_BEGIN
OWSLogInfo(@"Successfully provisioned device."); OWSLogInfo(@"Successfully provisioned device.");
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[self.linkedDevicesTableViewController expectMoreDevices]; [self.linkedDevicesTableViewController expectMoreDevices];
[self.navigationController popToViewController:self.linkedDevicesTableViewController animated:YES]; [self popToLinkedDeviceList];
// The service implementation of the socket connection caches the linked device state, // 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. // so all sync message sends will fail on the socket until it is cycled.
@ -264,6 +261,14 @@ NS_ASSUME_NONNULL_BEGIN
return alertController; return alertController;
} }
- (void)popToLinkedDeviceList
{
[self.navigationController popViewControllerWithAnimated:YES
completion:^{
[UIViewController attemptRotationToDeviceOrientation];
}];
}
#pragma mark - Orientation #pragma mark - Orientation
- (UIInterfaceOrientationMask)supportedInterfaceOrientations - (UIInterfaceOrientationMask)supportedInterfaceOrientations

@ -1,5 +1,5 @@
// //
// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // Copyright (c) 2019 Open Whisper Systems. All rights reserved.
// //
import Foundation import Foundation
@ -54,6 +54,7 @@ public extension UIDevice {
return isNativeIPad || isCompatabilityModeIPad return isNativeIPad || isCompatabilityModeIPad
} }
@objc
public func ows_setOrientation(_ orientation: UIInterfaceOrientation) { public func ows_setOrientation(_ orientation: UIInterfaceOrientation) {
// XXX - This is not officially supported, but there's no other way to programmatically rotate // XXX - This is not officially supported, but there's no other way to programmatically rotate
// the interface. // the interface.

@ -12,3 +12,35 @@ public extension UIEdgeInsets {
right: CurrentAppContext().isRTL ? leading : trailing) 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()
}
}

@ -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" #import "Theme.h"
@ -15,20 +15,33 @@ NS_ASSUME_NONNULL_BEGIN
- (UIViewController *)findFrontmostViewController:(BOOL)ignoringAlerts - (UIViewController *)findFrontmostViewController:(BOOL)ignoringAlerts
{ {
NSMutableArray<UIViewController *> *visitedViewControllers = [NSMutableArray new];
UIViewController *viewController = self; UIViewController *viewController = self;
while (YES) { while (YES) {
[visitedViewControllers addObject:viewController];
UIViewController *_Nullable nextViewController = viewController.presentedViewController; UIViewController *_Nullable nextViewController = viewController.presentedViewController;
if (nextViewController) { if (nextViewController) {
if (ignoringAlerts) { if (!ignoringAlerts || ![nextViewController isKindOfClass:[UIAlertController class]]) {
if ([nextViewController isKindOfClass:[UIAlertController class]]) { if ([visitedViewControllers containsObject:nextViewController]) {
break; // Cycle detected.
return viewController;
} }
viewController = nextViewController;
continue;
} }
viewController = nextViewController; }
} else if ([viewController isKindOfClass:[UINavigationController class]]) {
if ([viewController isKindOfClass:[UINavigationController class]]) {
UINavigationController *navigationController = (UINavigationController *)viewController; UINavigationController *navigationController = (UINavigationController *)viewController;
if (navigationController.topViewController) { nextViewController = navigationController.topViewController;
viewController = navigationController.topViewController; if (nextViewController) {
if ([visitedViewControllers containsObject:nextViewController]) {
// Cycle detected.
return viewController;
}
viewController = nextViewController;
} else { } else {
break; break;
} }

Loading…
Cancel
Save