mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			204 lines
		
	
	
		
			5.9 KiB
		
	
	
	
		
			Matlab
		
	
		
		
			
		
	
	
			204 lines
		
	
	
		
			5.9 KiB
		
	
	
	
		
			Matlab
		
	
| 
											8 years ago
										 | // | ||
| 
											7 years ago
										 | //  Copyright (c) 2019 Open Whisper Systems. All rights reserved. | ||
| 
											8 years ago
										 | // | ||
|  | 
 | ||
| 
											5 years ago
										 | #import "AppContext.h" | ||
| 
											8 years ago
										 | #import "OWSNavigationController.h" | ||
| 
											5 years ago
										 | #import <SignalUtilitiesKit/SignalUtilitiesKit-Swift.h> | ||
| 
											5 years ago
										 | #import <SessionUIKit/SessionUIKit.h> | ||
| 
											8 years ago
										 | 
 | ||
| 
											8 years ago
										 | NS_ASSUME_NONNULL_BEGIN | ||
|  | 
 | ||
| 
											8 years ago
										 | @interface UINavigationController (OWSNavigationController) <UINavigationBarDelegate, NavBarLayoutDelegate> | ||
| 
											8 years ago
										 | 
 | ||
|  | @end | ||
|  | 
 | ||
|  | #pragma mark - | ||
|  | 
 | ||
| 
											8 years ago
										 | // Expose that UINavigationController already secretly implements UIGestureRecognizerDelegate | ||
|  | // so we can call [super navigationBar:shouldPopItem] in our own implementation to take advantage | ||
|  | // of the important side effects of that method. | ||
| 
											8 years ago
										 | @interface OWSNavigationController () <UIGestureRecognizerDelegate> | ||
| 
											8 years ago
										 | 
 | ||
|  | @end | ||
|  | 
 | ||
|  | #pragma mark - | ||
|  | 
 | ||
|  | @implementation OWSNavigationController | ||
|  | 
 | ||
| 
											7 years ago
										 | - (instancetype)init | ||
| 
											8 years ago
										 | { | ||
| 
											7 years ago
										 |     self = [super initWithNavigationBarClass:[OWSNavigationBar class] toolbarClass:nil]; | ||
| 
											8 years ago
										 |     if (!self) { | ||
|  |         return self; | ||
|  |     } | ||
| 
											7 years ago
										 |     [self setupNavbar]; | ||
| 
											7 years ago
										 | 
 | ||
| 
											8 years ago
										 |     return self; | ||
|  | } | ||
|  | 
 | ||
| 
											7 years ago
										 | - (instancetype)initWithRootViewController:(UIViewController *)rootViewController | ||
|  | { | ||
| 
											7 years ago
										 |     self = [self init]; | ||
| 
											7 years ago
										 |     if (!self) { | ||
|  |         return self; | ||
|  |     } | ||
|  |     [self pushViewController:rootViewController animated:NO]; | ||
|  | 
 | ||
|  |     return self; | ||
|  | } | ||
|  | 
 | ||
| 
											7 years ago
										 | - (void)dealloc | ||
|  | { | ||
|  |     [[NSNotificationCenter defaultCenter] removeObserver:self]; | ||
|  | } | ||
|  | 
 | ||
| 
											7 years ago
										 | #pragma mark - | ||
|  | 
 | ||
| 
											8 years ago
										 | - (void)viewDidLoad | ||
| 
											8 years ago
										 | { | ||
| 
											8 years ago
										 |     [super viewDidLoad]; | ||
| 
											8 years ago
										 | 
 | ||
| 
											8 years ago
										 |     self.interactivePopGestureRecognizer.delegate = self; | ||
| 
											8 years ago
										 | } | ||
|  | 
 | ||
| 
											7 years ago
										 | - (BOOL)prefersStatusBarHidden | ||
|  | { | ||
|  |     if (self.ows_prefersStatusBarHidden) { | ||
|  |         return self.ows_prefersStatusBarHidden.boolValue; | ||
|  |     } | ||
|  |     return [super prefersStatusBarHidden]; | ||
|  | } | ||
|  | 
 | ||
| 
											8 years ago
										 | #pragma mark - UINavigationBarDelegate | ||
|  | 
 | ||
| 
											7 years ago
										 | - (void)setupNavbar | ||
|  | { | ||
|  |     if (![self.navigationBar isKindOfClass:[OWSNavigationBar class]]) { | ||
|  |         OWSFailDebug(@"navigationBar was unexpected class: %@", self.navigationBar); | ||
|  |         return; | ||
|  |     } | ||
|  |     OWSNavigationBar *navbar = (OWSNavigationBar *)self.navigationBar; | ||
|  |     navbar.navBarLayoutDelegate = self; | ||
|  |     [self updateLayoutForNavbar:navbar]; | ||
|  | } | ||
|  | 
 | ||
| 
											8 years ago
										 | // All OWSNavigationController serve as the UINavigationBarDelegate for their navbar. | ||
| 
											8 years ago
										 | // We override shouldPopItem: in order to cancel some back button presses - for example, | ||
|  | // if a view has unsaved changes. | ||
| 
											8 years ago
										 | - (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item | ||
|  | { | ||
| 
											7 years ago
										 |     OWSAssertDebug(self.interactivePopGestureRecognizer.delegate == self); | ||
| 
											8 years ago
										 |     UIViewController *topViewController = self.topViewController; | ||
|  | 
 | ||
|  |     // wasBackButtonClicked is YES if the back button was pressed but not | ||
|  |     // if a back gesture was performed or if the view is popped programmatically. | ||
|  |     BOOL wasBackButtonClicked = topViewController.navigationItem == item; | ||
|  |     BOOL result = YES; | ||
|  |     if (wasBackButtonClicked) { | ||
|  |         if ([topViewController conformsToProtocol:@protocol(OWSNavigationView)]) { | ||
|  |             id<OWSNavigationView> navigationView = (id<OWSNavigationView>)topViewController; | ||
|  |             result = ![navigationView shouldCancelNavigationBack]; | ||
|  |         } | ||
|  |     } | ||
|  | 
 | ||
|  |     // If we're not going to cancel the pop/back, we need to call the super | ||
|  |     // implementation since it has important side effects. | ||
|  |     if (result) { | ||
|  |         // NOTE: result might end up NO if the super implementation cancels the | ||
|  |         //       the pop/back. | ||
|  |         [super navigationBar:navigationBar shouldPopItem:item]; | ||
|  |         result =  YES; | ||
|  |     } | ||
|  |     return result; | ||
|  | } | ||
| 
											8 years ago
										 | 
 | ||
|  | #pragma mark - UIGestureRecognizerDelegate | ||
|  | 
 | ||
|  | // We serve as the UIGestureRecognizerDelegate of the interactivePopGestureRecognizer | ||
|  | // in order to cancel some "back" gestures - for example, | ||
|  | // if a view has unsaved changes. | ||
| 
											8 years ago
										 | - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer | ||
|  | { | ||
| 
											7 years ago
										 |     OWSAssertDebug(gestureRecognizer == self.interactivePopGestureRecognizer); | ||
| 
											7 years ago
										 | 
 | ||
| 
											8 years ago
										 |     UIViewController *topViewController = self.topViewController; | ||
|  |     if ([topViewController conformsToProtocol:@protocol(OWSNavigationView)]) { | ||
|  |         id<OWSNavigationView> navigationView = (id<OWSNavigationView>)topViewController; | ||
|  |         return ![navigationView shouldCancelNavigationBack]; | ||
|  |     } else { | ||
| 
											7 years ago
										 |         UIViewController *rootViewController = self.viewControllers.firstObject; | ||
|  |         if (topViewController == rootViewController) { | ||
|  |             return NO; | ||
|  |         } else { | ||
|  |             return YES; | ||
|  |         } | ||
| 
											8 years ago
										 |     } | ||
|  | } | ||
| 
											8 years ago
										 | 
 | ||
| 
											8 years ago
										 | #pragma mark - NavBarLayoutDelegate | ||
|  | 
 | ||
|  | - (void)navBarCallLayoutDidChangeWithNavbar:(OWSNavigationBar *)navbar | ||
|  | { | ||
|  |     [self updateLayoutForNavbar:navbar]; | ||
| 
											7 years ago
										 |     [self setNeedsStatusBarAppearanceUpdate]; | ||
|  | } | ||
|  | 
 | ||
|  | - (UIStatusBarStyle)preferredStatusBarStyle | ||
|  | { | ||
| 
											7 years ago
										 |     if (!CurrentAppContext().isMainApp) { | ||
|  |         return super.preferredStatusBarStyle; | ||
|  |     } else if (OWSWindowManager.sharedManager.hasCall) { | ||
| 
											7 years ago
										 |         // Status bar is overlaying the green "call banner" | ||
|  |         return UIStatusBarStyleLightContent; | ||
|  |     } else { | ||
| 
											6 years ago
										 |         return LKAppModeUtilities.isLightMode ? UIStatusBarStyleDefault : UIStatusBarStyleLightContent; | ||
| 
											7 years ago
										 |     } | ||
| 
											8 years ago
										 | } | ||
|  | 
 | ||
|  | - (void)updateLayoutForNavbar:(OWSNavigationBar *)navbar | ||
|  | { | ||
| 
											7 years ago
										 |     OWSLogDebug(@""); | ||
| 
											8 years ago
										 | 
 | ||
| 
											8 years ago
										 |     [UIView setAnimationsEnabled:NO]; | ||
|  | 
 | ||
| 
											8 years ago
										 |     if (@available(iOS 11.0, *)) { | ||
| 
											7 years ago
										 |         if (!CurrentAppContext().isMainApp) { | ||
|  |             self.additionalSafeAreaInsets = UIEdgeInsetsZero; | ||
|  |         } else if (OWSWindowManager.sharedManager.hasCall) { | ||
| 
											7 years ago
										 |             self.additionalSafeAreaInsets = UIEdgeInsetsMake(20, 0, 0, 0); | ||
| 
											8 years ago
										 |         } else { | ||
|  |             self.additionalSafeAreaInsets = UIEdgeInsetsZero; | ||
|  |         } | ||
| 
											7 years ago
										 | 
 | ||
| 
											8 years ago
										 |         // in iOS11 we have to ensure the navbar frame *in* layoutSubviews. | ||
|  |         [navbar layoutSubviews]; | ||
|  |     } else { | ||
| 
											7 years ago
										 |         // in iOS9/10 we only need to size the navbar once | ||
| 
											8 years ago
										 |         [navbar sizeToFit]; | ||
| 
											7 years ago
										 |         [navbar layoutIfNeeded]; | ||
| 
											8 years ago
										 | 
 | ||
|  |         // Since the navbar's frame was updated, we need to be sure our child VC's | ||
|  |         // container view is updated. | ||
|  |         [self.view setNeedsLayout]; | ||
| 
											8 years ago
										 |         [self.view layoutSubviews]; | ||
| 
											8 years ago
										 |     } | ||
| 
											8 years ago
										 |     [UIView setAnimationsEnabled:YES]; | ||
| 
											8 years ago
										 | } | ||
|  | 
 | ||
| 
											7 years ago
										 | #pragma mark - Orientation | ||
|  | 
 | ||
| 
											6 years ago
										 | - (BOOL)shouldAutorotate | ||
|  | { | ||
|  |     return NO; | ||
|  | } | ||
|  | 
 | ||
| 
											7 years ago
										 | - (UIInterfaceOrientationMask)supportedInterfaceOrientations | ||
|  | { | ||
| 
											6 years ago
										 |     return UIInterfaceOrientationMaskPortrait; | ||
| 
											7 years ago
										 | } | ||
|  | 
 | ||
| 
											8 years ago
										 | @end | ||
| 
											8 years ago
										 | 
 | ||
|  | NS_ASSUME_NONNULL_END |