mirror of https://github.com/oxen-io/session-ios
Merge branch 'charlesmchen/profileForNewAndOldUsers'
commit
636790c991
@ -0,0 +1,24 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
// Any view controller which wants to be able cancel back button
|
||||
// presses and back gestures should implement this protocol.
|
||||
@protocol OWSNavigationView <NSObject>
|
||||
|
||||
// shouldCancelNavigationBack will be called if the back button was pressed or
|
||||
// if a back gesture was performed but not if the view is popped programmatically.
|
||||
- (BOOL)shouldCancelNavigationBack;
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
// This navigation controller subclass should be used anywhere we might
|
||||
// want to cancel back button presses or back gestures due to, for example,
|
||||
// unsaved changes.
|
||||
@interface OWSNavigationController : UINavigationController
|
||||
|
||||
@end
|
@ -0,0 +1,76 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "OWSNavigationController.h"
|
||||
|
||||
// We use a category to expose UINavigationController's private
|
||||
// UINavigationBarDelegate methods.
|
||||
@interface UINavigationController (OWSNavigationController) <UINavigationBarDelegate>
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@interface OWSNavigationController () <UIGestureRecognizerDelegate>
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@implementation OWSNavigationController
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
|
||||
self.interactivePopGestureRecognizer.delegate = self;
|
||||
}
|
||||
|
||||
#pragma mark - UINavigationBarDelegate
|
||||
|
||||
// All UINavigationController serve as the UINavigationBarDelegate for their navbar.
|
||||
// We override shouldPopItem: in order to cancel some back button presses - for example,
|
||||
// if a view has unsaved changes.
|
||||
- (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) {
|
||||
result = [super navigationBar:navigationBar shouldPopItem:item];
|
||||
OWSAssert(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#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.
|
||||
- (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;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
Loading…
Reference in New Issue