Rework "cancel navigate back" logic.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 25b0f79615
commit 1b055c485d

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

@ -8,6 +8,8 @@
// presses and back gestures should implement this protocol. // presses and back gestures should implement this protocol.
@protocol OWSNavigationView <NSObject> @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; - (BOOL)shouldCancelNavigationBack;
@end @end

@ -37,6 +37,8 @@
OWSAssert(self.interactivePopGestureRecognizer.delegate == self); OWSAssert(self.interactivePopGestureRecognizer.delegate == self);
UIViewController *topViewController = self.topViewController; 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 wasBackButtonClicked = topViewController.navigationItem == item;
BOOL result = YES; BOOL result = YES;
if (wasBackButtonClicked) { if (wasBackButtonClicked) {

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

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

Loading…
Cancel
Save