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.
142 lines
4.8 KiB
Matlab
142 lines
4.8 KiB
Matlab
8 years ago
|
//
|
||
7 years ago
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||
8 years ago
|
//
|
||
|
|
||
|
#import "OWSNavigationController.h"
|
||
7 years ago
|
#import <SignalMessaging/SignalMessaging-Swift.h>
|
||
8 years ago
|
|
||
7 years ago
|
NS_ASSUME_NONNULL_BEGIN
|
||
|
|
||
|
|
||
|
@interface OWSNavigationController (OWSNavigationController) <UINavigationBarDelegate>
|
||
8 years ago
|
|
||
|
@end
|
||
|
|
||
|
#pragma mark -
|
||
|
|
||
|
@interface OWSNavigationController () <UIGestureRecognizerDelegate>
|
||
8 years ago
|
|
||
|
@end
|
||
|
|
||
|
#pragma mark -
|
||
|
|
||
|
@implementation OWSNavigationController
|
||
|
|
||
7 years ago
|
- (instancetype)initWithRootViewController:(UIViewController *)rootViewController
|
||
|
{
|
||
|
// Attempt 1: negative additionalSafeArea
|
||
|
// Failure: additionalSafeArea insets cannot be negative
|
||
|
// UIEdgeInsets newSafeArea = UIEdgeInsetsMake(-50, 30, 20, 30);
|
||
|
// rootViewController.additionalSafeAreaInsets = newSafeArea;
|
||
7 years ago
|
|
||
7 years ago
|
// Attempt 2: safeAreaInsets on vc.view
|
||
|
// failure. they're already 0
|
||
|
// UIEdgeInsets existingInsets = rootViewController.view.safeAreaInsets;
|
||
7 years ago
|
|
||
7 years ago
|
// Attempt 3: override topLayoutGuide?
|
||
|
// Failure - not called.
|
||
|
// overriding it does no good - it's not called by default layout code.
|
||
|
// presumably it just existing if you want to use it as an anchor.
|
||
7 years ago
|
|
||
7 years ago
|
// Attemp 4: sizeForChildContentConainer?
|
||
|
// Failure - not called.
|
||
7 years ago
|
|
||
7 years ago
|
// Attempt 5: autoSetDimension on navbar
|
||
|
// Failure: no effect on rendered size
|
||
7 years ago
|
|
||
7 years ago
|
// Attempt 6: manually set child frames in will/didLayoutSubviews
|
||
|
// glitchy, and viewcontrollers re-layout themselves afterwards anyway
|
||
7 years ago
|
|
||
7 years ago
|
// Attempt 7: Since we can't seem to *shrink* the navbar, maybe we can grow it.
|
||
|
// make additionalSafeAreaInsets
|
||
7 years ago
|
|
||
7 years ago
|
[self updateAdditionalSafeAreaInsets];
|
||
7 years ago
|
|
||
|
self = [self initWithNavigationBarClass:[OWSNavigationBar class] toolbarClass:nil];
|
||
7 years ago
|
[self pushViewController:rootViewController animated:NO];
|
||
7 years ago
|
|
||
7 years ago
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||
|
selector:@selector(windowManagerCallDidChange:)
|
||
|
name:OWSWindowManagerCallDidChangeNotification
|
||
|
object:nil];
|
||
7 years ago
|
|
||
7 years ago
|
return self;
|
||
|
}
|
||
|
|
||
|
- (void)windowManagerCallDidChange:(NSNotification *)notification
|
||
|
{
|
||
|
DDLogDebug(@"%@ in %s", self.logTag, __PRETTY_FUNCTION__);
|
||
|
[self updateAdditionalSafeAreaInsets];
|
||
|
}
|
||
|
|
||
|
- (void)updateAdditionalSafeAreaInsets
|
||
|
{
|
||
|
if (OWSWindowManager.sharedManager.hasCall) {
|
||
|
self.additionalSafeAreaInsets = UIEdgeInsetsMake(64, 0, 0, 0);
|
||
|
} else {
|
||
|
self.additionalSafeAreaInsets = UIEdgeInsetsZero;
|
||
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
- (void)viewDidLoad
|
||
8 years ago
|
{
|
||
8 years ago
|
[super viewDidLoad];
|
||
8 years ago
|
|
||
7 years ago
|
// self.interactivePopGestureRecognizer.delegate = self;
|
||
8 years ago
|
}
|
||
|
|
||
|
#pragma mark - UINavigationBarDelegate
|
||
|
|
||
7 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.
|
||
7 years ago
|
//- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item
|
||
|
//{
|
||
|
// OWSAssert(self.interactivePopGestureRecognizer.delegate == self);
|
||
|
// 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.
|
||
|
//
|
||
|
// // MJK WTF?? This seems super broken. It won't compile now, but how could it ever
|
||
|
// // have? This is a delegate method, so how are we calling it on super?
|
||
|
// // [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.
|
||
7 years ago
|
//- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
|
||
|
//{
|
||
|
// UIViewController *topViewController = self.topViewController;
|
||
|
// if ([topViewController conformsToProtocol:@protocol(OWSNavigationView)]) {
|
||
|
// id<OWSNavigationView> navigationView = (id<OWSNavigationView>)topViewController;
|
||
|
// return ![navigationView shouldCancelNavigationBack];
|
||
|
// } else {
|
||
|
// return YES;
|
||
|
// }
|
||
|
//}
|
||
8 years ago
|
|
||
|
@end
|
||
7 years ago
|
|
||
|
NS_ASSUME_NONNULL_END
|