From ab2bfb3a6746d07ae561dba8d77b58c7ec3a0774 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Wed, 22 Mar 2017 17:43:52 -0400 Subject: [PATCH] Fix spacing of custom back button ...and use it (only) in Messages VC Otherwise we'd have to do lots of manual handling of interactivePopGesture // FREEBIE --- Signal/src/util/UIViewController+OWS.h | 8 +++- Signal/src/util/UIViewController+OWS.m | 39 ++++++++++++++----- .../AboutTableViewController.m | 2 - .../AdvancedSettingsTableViewController.m | 3 -- .../FingerprintViewController.m | 1 - .../MessageComposeTableViewController.m | 1 - .../view controllers/NewGroupViewController.m | 2 - ...otificationSettingsOptionsViewController.m | 3 -- .../NotificationSettingsViewController.m | 3 -- ...SConversationSettingsTableViewController.m | 9 ----- .../OWSLinkDeviceViewController.m | 3 -- .../OWSLinkedDevicesTableViewController.m | 3 -- .../PrivacySettingsTableViewController.m | 3 -- .../ShowGroupMembersViewController.m | 3 -- 14 files changed, 37 insertions(+), 46 deletions(-) diff --git a/Signal/src/util/UIViewController+OWS.h b/Signal/src/util/UIViewController+OWS.h index b95a4b48f..ac00b42e9 100644 --- a/Signal/src/util/UIViewController+OWS.h +++ b/Signal/src/util/UIViewController+OWS.h @@ -8,8 +8,14 @@ NS_ASSUME_NONNULL_BEGIN @interface UIViewController (OWS) +/** + * Takes up a bit less space than the default system back button + * used in the MessagesViewController to help left-align the title view. + * + * **note** Using this breaks the interactive pop gesture (swipe back) unless you set/unset the + * interactivePopGesture.delegate to self/nil on viewWillAppear/Disappear + */ - (UIBarButtonItem *)createOWSBackButton; -- (void)useOWSBackButton; @end diff --git a/Signal/src/util/UIViewController+OWS.m b/Signal/src/util/UIViewController+OWS.m index 238e38afa..5a8aa295f 100644 --- a/Signal/src/util/UIViewController+OWS.m +++ b/Signal/src/util/UIViewController+OWS.m @@ -10,18 +10,39 @@ NS_ASSUME_NONNULL_BEGIN - (UIBarButtonItem *)createOWSBackButton { + // Nudge closer to the left edge to match default back button item. + const CGFloat kExtraLeftPadding = -8; + + // Give some extra hit area to the back button. This is a little smaller + // than the default back button, but makes sense for our left aligned title + // view in the MessagesViewController + const CGFloat kExtraRightPadding = 10; + + // Extra hit area above/below + const CGFloat kExtraHeightPadding = 4; + + // Matching the default backbutton placement is tricky. + // We can't just adjust the imageEdgeInsets on a UIBarButtonItem directly, + // so we adjust the imageEdgeInsets on a UIButton, then wrap that + // in a UIBarButtonItem. + UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom]; + [backButton addTarget:self action:@selector(backButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; + UIImage *backImage = [UIImage imageNamed:@"NavBarBack"]; OWSAssert(backImage); - UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:backImage - style:UIBarButtonItemStylePlain - target:self - action:@selector(backButtonPressed:)]; - return backItem; -} + [backButton setImage:backImage forState:UIControlStateNormal]; -- (void)useOWSBackButton -{ - self.navigationItem.leftBarButtonItem = [self createOWSBackButton]; + backButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; + + // Default back button is 1.5 pixel lower than our extracted image. + const CGFloat kTopInsetPadding = 1.5 + backButton.imageEdgeInsets = UIEdgeInsetsMake(kTopInsetPadding, kExtraLeftPadding, 0, 0); + + backButton.frame = CGRectMake(0, 0, backImage.size.width + kExtraRightPadding, backImage.size.height + kExtraHeightPadding); + + UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backButton]; + + return backItem; } #pragma mark - Event Handling diff --git a/Signal/src/view controllers/AboutTableViewController.m b/Signal/src/view controllers/AboutTableViewController.m index 047fd5041..41b7bafba 100644 --- a/Signal/src/view controllers/AboutTableViewController.m +++ b/Signal/src/view controllers/AboutTableViewController.m @@ -5,7 +5,6 @@ #import #import "AboutTableViewController.h" #import "UIUtil.h" -#import "UIViewController+OWS.h" @interface AboutTableViewController () @@ -33,7 +32,6 @@ typedef NS_ENUM(NSUInteger, AboutTableViewControllerSection) { - (void)viewDidLoad { [super viewDidLoad]; [self.navigationController.navigationBar setTranslucent:NO]; - [self useOWSBackButton]; self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; } diff --git a/Signal/src/view controllers/AdvancedSettingsTableViewController.m b/Signal/src/view controllers/AdvancedSettingsTableViewController.m index b2916a580..8d1c51445 100644 --- a/Signal/src/view controllers/AdvancedSettingsTableViewController.m +++ b/Signal/src/view controllers/AdvancedSettingsTableViewController.m @@ -10,7 +10,6 @@ #import "RPAccountManager.h" #import "Signal-Swift.h" #import "TSAccountManager.h" -#import "UIViewController+OWS.h" #import "Pastelog.h" #import @@ -52,8 +51,6 @@ typedef NS_ENUM(NSInteger, AdvancedSettingsTableViewControllerSection) { self.title = NSLocalizedString(@"SETTINGS_ADVANCED_TITLE", @""); - [self useOWSBackButton]; - // Enable Log self.enableLogCell = [[UITableViewCell alloc] init]; self.enableLogCell.textLabel.text = NSLocalizedString(@"SETTINGS_ADVANCED_DEBUGLOG", @""); diff --git a/Signal/src/view controllers/FingerprintViewController.m b/Signal/src/view controllers/FingerprintViewController.m index ec94f7e18..1f396afc4 100644 --- a/Signal/src/view controllers/FingerprintViewController.m +++ b/Signal/src/view controllers/FingerprintViewController.m @@ -8,7 +8,6 @@ #import "Signal-Swift.h" #import "UIUtil.h" #import "UIViewController+CameraPermissions.h" -#import "UIViewController+OWS.h" #import #import #import diff --git a/Signal/src/view controllers/MessageComposeTableViewController.m b/Signal/src/view controllers/MessageComposeTableViewController.m index f3c25ecfd..1950f5185 100644 --- a/Signal/src/view controllers/MessageComposeTableViewController.m +++ b/Signal/src/view controllers/MessageComposeTableViewController.m @@ -13,7 +13,6 @@ #import "Signal-Swift.h" #import "UIColor+OWS.h" #import "UIUtil.h" -#import "UIViewController+OWS.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Signal/src/view controllers/NewGroupViewController.m b/Signal/src/view controllers/NewGroupViewController.m index 6d1ec0504..241969aa5 100644 --- a/Signal/src/view controllers/NewGroupViewController.m +++ b/Signal/src/view controllers/NewGroupViewController.m @@ -12,7 +12,6 @@ #import "TSOutgoingMessage.h" #import "UIImage+normalizeImage.h" #import "UIUtil.h" -#import "UIViewController+OWS.h" #import #import #import @@ -101,7 +100,6 @@ static NSString *const kUnwindToMessagesViewSegue = @"UnwindToMessagesViewSegue" - (void)viewDidLoad { [super viewDidLoad]; [self.navigationController.navigationBar setTranslucent:NO]; - [self useOWSBackButton]; contacts = self.contactsManager.signalContacts; diff --git a/Signal/src/view controllers/NotificationSettingsOptionsViewController.m b/Signal/src/view controllers/NotificationSettingsOptionsViewController.m index 82c2292d2..161309286 100644 --- a/Signal/src/view controllers/NotificationSettingsOptionsViewController.m +++ b/Signal/src/view controllers/NotificationSettingsOptionsViewController.m @@ -5,7 +5,6 @@ #import "NotificationSettingsOptionsViewController.h" #import "Environment.h" #import "PropertyListPreferences.h" -#import "UIViewController+OWS.h" @interface NotificationSettingsOptionsViewController () @@ -19,8 +18,6 @@ self.options = @[ @(NotificationNamePreview), @(NotificationNameNoPreview), @(NotificationNoNameNoPreview) ]; [super viewDidLoad]; - - [self useOWSBackButton]; } #pragma mark - Table view data source diff --git a/Signal/src/view controllers/NotificationSettingsViewController.m b/Signal/src/view controllers/NotificationSettingsViewController.m index 5669078c1..8927f7e06 100644 --- a/Signal/src/view controllers/NotificationSettingsViewController.m +++ b/Signal/src/view controllers/NotificationSettingsViewController.m @@ -6,7 +6,6 @@ #import "Environment.h" #import "NotificationSettingsOptionsViewController.h" #import "PropertyListPreferences.h" -#import "UIViewController+OWS.h" #define kNotificationOptionSection 0 @@ -26,8 +25,6 @@ [super viewDidLoad]; [self setTitle:NSLocalizedString(@"SETTINGS_NOTIFICATIONS", nil)]; - [self useOWSBackButton]; - self.notificationsSections = @[ NSLocalizedString(@"NOTIFICATIONS_SECTION_BACKGROUND", nil), NSLocalizedString(@"NOTIFICATIONS_SECTION_INAPP", nil) diff --git a/Signal/src/view controllers/OWSConversationSettingsTableViewController.m b/Signal/src/view controllers/OWSConversationSettingsTableViewController.m index 2369ef431..52339bbb6 100644 --- a/Signal/src/view controllers/OWSConversationSettingsTableViewController.m +++ b/Signal/src/view controllers/OWSConversationSettingsTableViewController.m @@ -12,7 +12,6 @@ #import "ShowGroupMembersViewController.h" #import "UIFont+OWS.h" #import "UIUtil.h" -#import "UIViewController+OWS.h" #import <25519/Curve25519.h> #import #import @@ -179,8 +178,6 @@ static NSString *const OWSConversationSettingsTableViewControllerSegueShowGroupM self.listGroupMembersCell.textLabel.text = NSLocalizedString(@"LIST_GROUP_MEMBERS_ACTION", @"table cell label in conversation settings"); - [self useOWSBackButton]; - self.toggleDisappearingMessagesCell.selectionStyle = UITableViewCellSelectionStyleNone; self.disappearingMessagesDurationCell.selectionStyle = UITableViewCellSelectionStyleNone; @@ -212,9 +209,6 @@ static NSString *const OWSConversationSettingsTableViewControllerSegueShowGroupM { [super viewWillAppear:animated]; - // Since we're using a custom back button, we have to do some extra work to manage the interactivePopGestureRecognizer - self.navigationController.interactivePopGestureRecognizer.delegate = self; - // HACK to unselect rows when swiping back // http://stackoverflow.com/questions/19379510/uitableviewcell-doesnt-get-deselected-when-swiping-back-quickly [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:animated]; @@ -224,9 +218,6 @@ static NSString *const OWSConversationSettingsTableViewControllerSegueShowGroupM { [super viewWillDisappear:animated]; - // Since we're using a custom back button, we have to do some extra work to manage the interactivePopGestureRecognizer - self.navigationController.interactivePopGestureRecognizer.delegate = nil; - if (self.disappearingMessagesConfiguration.isNewRecord && !self.disappearingMessagesConfiguration.isEnabled) { // don't save defaults, else we'll unintentionally save the configuration and notify the contact. return; diff --git a/Signal/src/view controllers/OWSLinkDeviceViewController.m b/Signal/src/view controllers/OWSLinkDeviceViewController.m index cafbe294c..1203f9401 100644 --- a/Signal/src/view controllers/OWSLinkDeviceViewController.m +++ b/Signal/src/view controllers/OWSLinkDeviceViewController.m @@ -6,7 +6,6 @@ #import "OWSDeviceProvisioningURLParser.h" #import "OWSLinkedDevicesTableViewController.h" #import "SettingsTableViewController.h" -#import "UIViewController+OWS.h" #import #import #import @@ -28,8 +27,6 @@ NS_ASSUME_NONNULL_BEGIN { [super viewDidLoad]; - [self useOWSBackButton]; - // HACK to get full width preview layer CGRect oldFrame = self.qrScanningView.frame; self.qrScanningView.frame = CGRectMake( diff --git a/Signal/src/view controllers/OWSLinkedDevicesTableViewController.m b/Signal/src/view controllers/OWSLinkedDevicesTableViewController.m index 858ba284f..001deb86c 100644 --- a/Signal/src/view controllers/OWSLinkedDevicesTableViewController.m +++ b/Signal/src/view controllers/OWSLinkedDevicesTableViewController.m @@ -6,7 +6,6 @@ #import "OWSDeviceTableViewCell.h" #import "OWSLinkDeviceViewController.h" #import "UIViewController+CameraPermissions.h" -#import "UIViewController+OWS.h" #import #import #import @@ -41,8 +40,6 @@ int const OWSLinkedDevicesTableViewControllerSectionAddDevice = 1; [super viewDidLoad]; self.title = NSLocalizedString(@"LINKED_DEVICES_TITLE", @"Menu item and navbar title for the device manager"); - [self useOWSBackButton]; - self.isExpectingMoreDevices = NO; self.tableView.rowHeight = UITableViewAutomaticDimension; self.tableView.estimatedRowHeight = 70; diff --git a/Signal/src/view controllers/PrivacySettingsTableViewController.m b/Signal/src/view controllers/PrivacySettingsTableViewController.m index 473685d9a..442cbb0be 100644 --- a/Signal/src/view controllers/PrivacySettingsTableViewController.m +++ b/Signal/src/view controllers/PrivacySettingsTableViewController.m @@ -7,7 +7,6 @@ #import "Environment.h" #import "PropertyListPreferences.h" #import "UIUtil.h" -#import "UIViewController+OWS.h" #import "Signal-Swift.h" #import <25519/Curve25519.h> @@ -61,8 +60,6 @@ typedef NS_ENUM(NSInteger, PrivacySettingsTableViewControllerSectionIndex) { self.title = NSLocalizedString(@"SETTINGS_PRIVACY_TITLE", @""); - [self useOWSBackButton]; - // CallKit opt-out self.enableCallKitCell = [UITableViewCell new]; self.enableCallKitCell.textLabel.text = NSLocalizedString(@"SETTINGS_PRIVACY_CALLKIT_TITLE", @"Short table cell label"); diff --git a/Signal/src/view controllers/ShowGroupMembersViewController.m b/Signal/src/view controllers/ShowGroupMembersViewController.m index b2efc72bc..cdcd41353 100644 --- a/Signal/src/view controllers/ShowGroupMembersViewController.m +++ b/Signal/src/view controllers/ShowGroupMembersViewController.m @@ -8,7 +8,6 @@ #import "Environment.h" #import "GroupContactsResult.h" #import "UIUtil.h" -#import "UIViewController+OWS.h" #import NS_ASSUME_NONNULL_BEGIN @@ -59,8 +58,6 @@ static NSString *const kUnwindToMessagesViewSegue = @"UnwindToMessagesViewSegue" self.title = _thread.groupModel.groupName; - [self useOWSBackButton]; - [self initializeTableView]; self.groupContacts =