Implement alternative approach to veto-able back buttons.
// FREEBIE
This commit is contained in:
parent
9d8c396848
commit
08347478a2
|
@ -74,6 +74,7 @@
|
|||
34B3F89C1E8DF3270035BE1A /* BlockListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F89B1E8DF3270035BE1A /* BlockListViewController.m */; };
|
||||
34B3F89F1E8DF5490035BE1A /* OWSTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F89E1E8DF5490035BE1A /* OWSTableViewController.m */; };
|
||||
34B3F8A21E8EA6040035BE1A /* ViewControllerUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F8A11E8EA6040035BE1A /* ViewControllerUtils.m */; };
|
||||
34C42D5B1F45F7A80072EC04 /* OWSNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34C42D5A1F45F7A80072EC04 /* OWSNavigationController.m */; };
|
||||
34CCAF381F0C0599004084F4 /* AppUpdateNag.m in Sources */ = {isa = PBXBuildFile; fileRef = 34CCAF371F0C0599004084F4 /* AppUpdateNag.m */; };
|
||||
34CCAF3B1F0C2748004084F4 /* OWSAddToContactViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34CCAF3A1F0C2748004084F4 /* OWSAddToContactViewController.m */; };
|
||||
34CE88E71F2FB9A10098030F /* ProfileViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34CE88E61F2FB9A10098030F /* ProfileViewController.m */; };
|
||||
|
@ -505,6 +506,8 @@
|
|||
34B3F89E1E8DF5490035BE1A /* OWSTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSTableViewController.m; sourceTree = "<group>"; };
|
||||
34B3F8A01E8EA6040035BE1A /* ViewControllerUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewControllerUtils.h; sourceTree = "<group>"; };
|
||||
34B3F8A11E8EA6040035BE1A /* ViewControllerUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ViewControllerUtils.m; sourceTree = "<group>"; };
|
||||
34C42D591F45F7A80072EC04 /* OWSNavigationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSNavigationController.h; sourceTree = "<group>"; };
|
||||
34C42D5A1F45F7A80072EC04 /* OWSNavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSNavigationController.m; sourceTree = "<group>"; };
|
||||
34CCAF361F0C0599004084F4 /* AppUpdateNag.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppUpdateNag.h; sourceTree = "<group>"; };
|
||||
34CCAF371F0C0599004084F4 /* AppUpdateNag.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppUpdateNag.m; sourceTree = "<group>"; };
|
||||
34CCAF391F0C2748004084F4 /* OWSAddToContactViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSAddToContactViewController.h; sourceTree = "<group>"; };
|
||||
|
@ -1026,6 +1029,8 @@
|
|||
34B3F85F1E8DF1700035BE1A /* OWSLinkedDevicesTableViewController.h */,
|
||||
34B3F8601E8DF1700035BE1A /* OWSLinkedDevicesTableViewController.m */,
|
||||
34B3F8611E8DF1700035BE1A /* OWSMessagesToolbarContentView.xib */,
|
||||
34C42D591F45F7A80072EC04 /* OWSNavigationController.h */,
|
||||
34C42D5A1F45F7A80072EC04 /* OWSNavigationController.m */,
|
||||
34B3F8621E8DF1700035BE1A /* OWSQRCodeScanningViewController.h */,
|
||||
34B3F8631E8DF1700035BE1A /* OWSQRCodeScanningViewController.m */,
|
||||
34B3F89D1E8DF5490035BE1A /* OWSTableViewController.h */,
|
||||
|
@ -2307,6 +2312,7 @@
|
|||
341BB7491DB727EE001E2975 /* JSQMediaItem+OWS.m in Sources */,
|
||||
34B3F89C1E8DF3270035BE1A /* BlockListViewController.m in Sources */,
|
||||
45F2B1941D9C9F48000D2C69 /* OWSOutgoingMessageCollectionViewCell.m in Sources */,
|
||||
34C42D5B1F45F7A80072EC04 /* OWSNavigationController.m in Sources */,
|
||||
BFB074C919A5611000F2947C /* ObservableValue.m in Sources */,
|
||||
B68EF9BA1C0B1EBD009C3DCD /* FLAnimatedImage.m in Sources */,
|
||||
B68112EA1A4D9EC400BA82FF /* UIImage+normalizeImage.m in Sources */,
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#import "NotificationsManager.h"
|
||||
#import "OWSContactsManager.h"
|
||||
#import "OWSContactsSyncing.h"
|
||||
#import "OWSNavigationController.h"
|
||||
#import "OWSProfileManager.h"
|
||||
#import "OWSStaleNotificationObserver.h"
|
||||
#import "Pastelog.h"
|
||||
|
@ -802,8 +803,8 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
|
|||
self.window.rootViewController = navigationController;
|
||||
} else {
|
||||
RegistrationViewController *viewController = [RegistrationViewController new];
|
||||
UINavigationController *navigationController =
|
||||
[[UINavigationController alloc] initWithRootViewController:viewController];
|
||||
OWSNavigationController *navigationController =
|
||||
[[OWSNavigationController alloc] initWithRootViewController:viewController];
|
||||
navigationController.navigationBarHidden = YES;
|
||||
self.window.rootViewController = navigationController;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#import "ContactsViewHelper.h"
|
||||
#import "Environment.h"
|
||||
#import "OWSContactsManager.h"
|
||||
#import "OWSNavigationController.h"
|
||||
#import "OWSTableViewController.h"
|
||||
#import "Signal-Swift.h"
|
||||
#import "SignalKeyingStorage.h"
|
||||
|
@ -34,7 +35,8 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68;
|
|||
AvatarViewHelperDelegate,
|
||||
AddToGroupViewControllerDelegate,
|
||||
OWSTableViewControllerDelegate,
|
||||
UINavigationControllerDelegate>
|
||||
UINavigationControllerDelegate,
|
||||
OWSNavigationView>
|
||||
|
||||
@property (nonatomic, readonly) OWSMessageSender *messageSender;
|
||||
@property (nonatomic, readonly) ContactsViewHelper *contactsViewHelper;
|
||||
|
@ -97,8 +99,6 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68;
|
|||
[super loadView];
|
||||
|
||||
self.title = NSLocalizedString(@"NEW_GROUP_DEFAULT_TITLE", @"The navbar title for the 'new group' view.");
|
||||
self.navigationItem.leftBarButtonItem =
|
||||
[self createOWSBackButtonWithTarget:self selector:@selector(backButtonPressed:)];
|
||||
|
||||
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
|
||||
initWithTitle:NSLocalizedString(@"NEW_GROUP_CREATE_BUTTON", @"The title for the 'create group' button.")
|
||||
|
@ -547,7 +547,7 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68;
|
|||
|
||||
#pragma mark - Event Handling
|
||||
|
||||
- (void)backButtonPressed:(id)sender
|
||||
- (void)backButtonPressed
|
||||
{
|
||||
[self.groupNameTextField resignFirstResponder];
|
||||
|
||||
|
@ -649,6 +649,13 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68;
|
|||
return [self.memberRecipientIds containsObject:recipientId];
|
||||
}
|
||||
|
||||
#pragma mark - OWSNavigationView
|
||||
|
||||
- (void)navBackButtonPressed
|
||||
{
|
||||
[self backButtonPressed];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
|
@ -827,10 +827,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
updateGroupViewController.conversationSettingsViewDelegate = self.conversationSettingsViewDelegate;
|
||||
updateGroupViewController.thread = (TSGroupThread *)self.thread;
|
||||
updateGroupViewController.mode = mode;
|
||||
|
||||
UINavigationController *navigationController =
|
||||
[[UINavigationController alloc] initWithRootViewController:updateGroupViewController];
|
||||
[self presentViewController:navigationController animated:YES completion:nil];
|
||||
[self.navigationController pushViewController:updateGroupViewController animated:YES];
|
||||
}
|
||||
|
||||
- (void)presentContactViewController
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@protocol OWSNavigationView <NSObject>
|
||||
|
||||
- (void)navBackButtonPressed;
|
||||
|
||||
@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,37 @@
|
|||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "OWSNavigationController.h"
|
||||
|
||||
@interface OWSNavigationController ()
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@implementation OWSNavigationController
|
||||
|
||||
- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item
|
||||
{
|
||||
|
||||
UIViewController *topViewController = self.topViewController;
|
||||
BOOL wasBackButtonClicked = topViewController.navigationItem == item;
|
||||
|
||||
if (wasBackButtonClicked) {
|
||||
if ([topViewController respondsToSelector:@selector(navBackButtonPressed)]) {
|
||||
// if user did press back on the view controller where you handle the navBackButtonPressed
|
||||
[topViewController performSelector:@selector(navBackButtonPressed)];
|
||||
return NO;
|
||||
} else {
|
||||
// if user did press back but you are not on the view controller that can handle the navBackButtonPressed
|
||||
[self popViewControllerAnimated:YES];
|
||||
return YES;
|
||||
}
|
||||
} else {
|
||||
// when you call popViewController programmatically you do not want to pop it twice
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
|
@ -5,6 +5,7 @@
|
|||
#import "ProfileViewController.h"
|
||||
#import "AppDelegate.h"
|
||||
#import "AvatarViewHelper.h"
|
||||
#import "OWSNavigationController.h"
|
||||
#import "OWSProfileManager.h"
|
||||
#import "Signal-Swift.h"
|
||||
#import "SignalsNavigationController.h"
|
||||
|
@ -27,7 +28,7 @@ typedef NS_ENUM(NSInteger, ProfileViewMode) {
|
|||
NSString *const kProfileView_Collection = @"kProfileView_Collection";
|
||||
NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDate";
|
||||
|
||||
@interface ProfileViewController () <UITextFieldDelegate, AvatarViewHelperDelegate>
|
||||
@interface ProfileViewController () <UITextFieldDelegate, AvatarViewHelperDelegate, OWSNavigationView>
|
||||
|
||||
@property (nonatomic, readonly) AvatarViewHelper *avatarViewHelper;
|
||||
|
||||
|
@ -259,8 +260,6 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
|
|||
// context.
|
||||
switch (self.profileViewMode) {
|
||||
case ProfileViewMode_AppSettings:
|
||||
self.navigationItem.leftBarButtonItem =
|
||||
[self createOWSBackButtonWithTarget:self selector:@selector(backOrSkipButtonPressed)];
|
||||
break;
|
||||
case ProfileViewMode_UpgradeOrNag:
|
||||
self.navigationItem.leftBarButtonItem =
|
||||
|
@ -432,6 +431,7 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
|
|||
+ (void)presentForAppSettings:(UINavigationController *)navigationController
|
||||
{
|
||||
OWSAssert(navigationController);
|
||||
OWSAssert([navigationController isKindOfClass:[OWSNavigationController class]]);
|
||||
|
||||
ProfileViewController *vc = [[ProfileViewController alloc] initWithMode:ProfileViewMode_AppSettings];
|
||||
[navigationController pushViewController:vc animated:YES];
|
||||
|
@ -440,6 +440,7 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
|
|||
+ (void)presentForRegistration:(UINavigationController *)navigationController
|
||||
{
|
||||
OWSAssert(navigationController);
|
||||
OWSAssert([navigationController isKindOfClass:[OWSNavigationController class]]);
|
||||
|
||||
ProfileViewController *vc = [[ProfileViewController alloc] initWithMode:ProfileViewMode_Registration];
|
||||
[navigationController pushViewController:vc animated:YES];
|
||||
|
@ -450,7 +451,7 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
|
|||
OWSAssert(presentingController);
|
||||
|
||||
ProfileViewController *vc = [[ProfileViewController alloc] initWithMode:ProfileViewMode_UpgradeOrNag];
|
||||
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:vc];
|
||||
OWSNavigationController *navigationController = [[OWSNavigationController alloc] initWithRootViewController:vc];
|
||||
[presentingController presentTopLevelModalViewController:navigationController
|
||||
animateDismissal:YES
|
||||
animatePresentation:YES];
|
||||
|
@ -492,6 +493,13 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
|
|||
self.avatar = nil;
|
||||
}
|
||||
|
||||
#pragma mark - OWSNavigationView
|
||||
|
||||
- (void)navBackButtonPressed
|
||||
{
|
||||
[self backOrSkipButtonPressed];
|
||||
}
|
||||
|
||||
#pragma mark - Logging
|
||||
|
||||
+ (NSString *)tag
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "OWSNavigationController.h"
|
||||
|
||||
@interface SignalsNavigationController : UINavigationController
|
||||
@interface SignalsNavigationController : OWSNavigationController
|
||||
|
||||
@end
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#import "MessagesViewController.h"
|
||||
#import "NSDate+millisecondTimeStamp.h"
|
||||
#import "OWSContactsManager.h"
|
||||
#import "OWSNavigationController.h"
|
||||
#import "ProfileViewController.h"
|
||||
#import "PropertyListPreferences.h"
|
||||
#import "PushManager.h"
|
||||
|
@ -309,7 +310,7 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
|
|||
|
||||
- (void)settingsButtonPressed:(id)sender {
|
||||
AppSettingsViewController *vc = [AppSettingsViewController new];
|
||||
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:vc];
|
||||
OWSNavigationController *navigationController = [[OWSNavigationController alloc] initWithRootViewController:vc];
|
||||
[self presentViewController:navigationController animated:YES completion:nil];
|
||||
}
|
||||
|
||||
|
@ -353,8 +354,8 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
|
|||
//
|
||||
// We just want to make sure contact access is *complete* before showing the compose
|
||||
// screen to avoid flicker.
|
||||
UINavigationController *navigationController =
|
||||
[[UINavigationController alloc] initWithRootViewController:viewController];
|
||||
OWSNavigationController *navigationController =
|
||||
[[OWSNavigationController alloc] initWithRootViewController:viewController];
|
||||
[self presentTopLevelModalViewController:navigationController animateDismissal:YES animatePresentation:YES];
|
||||
}];
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#import "ContactsViewHelper.h"
|
||||
#import "Environment.h"
|
||||
#import "OWSContactsManager.h"
|
||||
#import "OWSNavigationController.h"
|
||||
#import "OWSTableViewController.h"
|
||||
#import "Signal-Swift.h"
|
||||
#import "SignalKeyingStorage.h"
|
||||
|
@ -33,7 +34,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
AvatarViewHelperDelegate,
|
||||
AddToGroupViewControllerDelegate,
|
||||
OWSTableViewControllerDelegate,
|
||||
UINavigationControllerDelegate>
|
||||
UINavigationControllerDelegate,
|
||||
OWSNavigationView>
|
||||
|
||||
@property (nonatomic, readonly) OWSMessageSender *messageSender;
|
||||
@property (nonatomic, readonly) ContactsViewHelper *contactsViewHelper;
|
||||
|
@ -103,8 +105,6 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
self.previousMemberRecipientIds = [NSSet setWithArray:self.thread.groupModel.groupMemberIds];
|
||||
|
||||
self.title = NSLocalizedString(@"EDIT_GROUP_DEFAULT_TITLE", @"The navbar title for the 'update group' view.");
|
||||
self.navigationItem.leftBarButtonItem =
|
||||
[self createOWSBackButtonWithTarget:self selector:@selector(backButtonPressed:)];
|
||||
|
||||
// First section.
|
||||
|
||||
|
@ -409,13 +409,13 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
#pragma mark - Event Handling
|
||||
|
||||
- (void)backButtonPressed:(id)sender
|
||||
- (void)backButtonPressed
|
||||
{
|
||||
[self.groupNameTextField resignFirstResponder];
|
||||
|
||||
if (!self.hasUnsavedChanges) {
|
||||
// If user made no changes, return to conversation settings view.
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -441,7 +441,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
@"The label for the 'don't save' button in action sheets.")
|
||||
style:UIAlertActionStyleDestructive
|
||||
handler:^(UIAlertAction *action) {
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
}]];
|
||||
[self presentViewController:controller animated:YES completion:nil];
|
||||
}
|
||||
|
@ -528,6 +528,13 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
return [self.memberRecipientIds containsObject:recipientId];
|
||||
}
|
||||
|
||||
#pragma mark - OWSNavigationView
|
||||
|
||||
- (void)navBackButtonPressed
|
||||
{
|
||||
[self backButtonPressed];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
|
@ -17,8 +17,6 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
*/
|
||||
- (UIBarButtonItem *)createOWSBackButton;
|
||||
|
||||
- (UIBarButtonItem *)createOWSBackButtonWithTarget:(id)target selector:(SEL)selector;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
Loading…
Reference in New Issue