Rework "cancel navigate back" logic.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-08-18 10:02:45 -04:00
parent 25b0f79615
commit 1b055c485d
5 changed files with 11 additions and 14 deletions

View File

@ -50,7 +50,6 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68;
@property (nonatomic) NSMutableSet<NSString *> *memberRecipientIds;
@property (nonatomic) BOOL hasUnsavedChanges;
@property (nonatomic) BOOL shouldIgnoreSavedChanges;
@property (nonatomic) BOOL hasAppeared;
@end
@ -552,7 +551,7 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68;
{
[self.groupNameTextField resignFirstResponder];
if (!self.hasUnsavedChanges || self.shouldIgnoreSavedChanges) {
if (!self.hasUnsavedChanges) {
// If user made no changes, return to conversation settings view.
[self.navigationController popViewControllerAnimated:YES];
return;
@ -571,7 +570,6 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68;
@"The label for the 'discard' button in alerts and action sheets.")
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) {
self.shouldIgnoreSavedChanges = YES;
[self.navigationController popViewControllerAnimated:YES];
}]];
[controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", nil)
@ -655,8 +653,8 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68;
- (BOOL)shouldCancelNavigationBack
{
BOOL result = self.hasUnsavedChanges && !self.shouldIgnoreSavedChanges;
if (result) {
BOOL result = self.hasUnsavedChanges;
if (self.hasUnsavedChanges) {
[self backButtonPressed];
}
return result;

View File

@ -8,6 +8,8 @@
// 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

View File

@ -37,6 +37,8 @@
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) {

View File

@ -44,8 +44,6 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
@property (nonatomic) BOOL hasUnsavedChanges;
@property (nonatomic) BOOL shouldIgnoreSavedChanges;
@property (nonatomic) ProfileViewMode profileViewMode;
@property (nonatomic) YapDatabaseConnection *databaseConnection;
@ -209,7 +207,7 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
{
[self.nameTextField resignFirstResponder];
if (!self.hasUnsavedChanges || self.shouldIgnoreSavedChanges) {
if (!self.hasUnsavedChanges) {
// If user made no changes, return to conversation settings view.
[self profileCompletedOrSkipped];
return;
@ -228,7 +226,6 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
@"The label for the 'discard' button in alerts and action sheets.")
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) {
self.shouldIgnoreSavedChanges = YES;
[self profileCompletedOrSkipped];
}]];
[controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", nil)
@ -500,7 +497,7 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
- (BOOL)shouldCancelNavigationBack
{
BOOL result = self.hasUnsavedChanges && !self.shouldIgnoreSavedChanges;
BOOL result = self.hasUnsavedChanges;
if (result) {
[self backOrSkipButtonPressed];
}

View File

@ -50,7 +50,6 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) NSMutableSet<NSString *> *memberRecipientIds;
@property (nonatomic) BOOL hasUnsavedChanges;
@property (nonatomic) BOOL shouldIgnoreSavedChanges;
@end
@ -414,7 +413,7 @@ NS_ASSUME_NONNULL_BEGIN
{
[self.groupNameTextField resignFirstResponder];
if (!self.hasUnsavedChanges || self.shouldIgnoreSavedChanges) {
if (!self.hasUnsavedChanges) {
// If user made no changes, return to conversation settings view.
[self.navigationController popViewControllerAnimated:YES];
return;
@ -442,7 +441,6 @@ NS_ASSUME_NONNULL_BEGIN
@"The label for the 'don't save' button in action sheets.")
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) {
self.shouldIgnoreSavedChanges = YES;
[self.navigationController popViewControllerAnimated:YES];
}]];
[self presentViewController:controller animated:YES completion:nil];
@ -534,7 +532,7 @@ NS_ASSUME_NONNULL_BEGIN
- (BOOL)shouldCancelNavigationBack
{
BOOL result = self.hasUnsavedChanges && !self.shouldIgnoreSavedChanges;
BOOL result = self.hasUnsavedChanges;
if (result) {
[self backButtonPressed];
}