From 898d64ae1c0fd5295597f07ac65e08e3cc09fe30 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Fri, 13 Jul 2018 13:19:17 -0600 Subject: [PATCH] Fix compose picker content scrolls behind navbar // FREEBIE --- .../NewContactThreadViewController.m | 54 +++++++++++-------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/Signal/src/ViewControllers/NewContactThreadViewController.m b/Signal/src/ViewControllers/NewContactThreadViewController.m index 855397520..880d7dc7f 100644 --- a/Signal/src/ViewControllers/NewContactThreadViewController.m +++ b/Signal/src/ViewControllers/NewContactThreadViewController.m @@ -54,7 +54,6 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) UILocalizedIndexedCollation *collation; @property (nonatomic, readonly) UISearchBar *searchBar; -@property (nonatomic, readonly) NSLayoutConstraint *hideContactsPermissionReminderViewConstraint; // A list of possible phone numbers parsed from the search text as // E164 values. @@ -82,18 +81,6 @@ NS_ASSUME_NONNULL_BEGIN _nonContactAccountSet = [NSMutableSet set]; _collation = [UILocalizedIndexedCollation currentCollation]; - ReminderView *contactsPermissionReminderView = - [ReminderView nagWithText:NSLocalizedString(@"COMPOSE_SCREEN_MISSING_CONTACTS_PERMISSION", - @"Multi-line label explaining why compose-screen contact picker is empty.") - tapAction:^{ - [[UIApplication sharedApplication] openSystemSettings]; - }]; - [self.view addSubview:contactsPermissionReminderView]; - [contactsPermissionReminderView autoPinWidthToSuperview]; - [contactsPermissionReminderView autoPinEdgeToSuperviewMargin:ALEdgeTop]; - _hideContactsPermissionReminderViewConstraint = - [contactsPermissionReminderView autoSetDimension:ALDimensionHeight toSize:0]; - self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop target:self @@ -121,13 +108,19 @@ NS_ASSUME_NONNULL_BEGIN _tableViewController = [OWSTableViewController new]; _tableViewController.delegate = self; _tableViewController.tableViewStyle = UITableViewStylePlain; - [self.view addSubview:self.tableViewController.view]; + + // To automatically adjust our content inset appropriately on iOS9/10 + // 1. the tableViewController must be a childView + // 2. the scrollable view (tableView in this case) must be at index 0. + [self addChildViewController:self.tableViewController]; + [self.view insertSubview:self.tableViewController.view atIndex:0]; + [_tableViewController.view autoPinWidthToSuperview]; + [_tableViewController.view autoPinEdgeToSuperviewEdge:ALEdgeTop]; self.tableViewController.tableView.rowHeight = UITableViewAutomaticDimension; self.tableViewController.tableView.estimatedRowHeight = 60; - [_tableViewController.view autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:contactsPermissionReminderView]; [self autoPinViewToBottomOfViewControllerOrKeyboard:self.tableViewController.view]; _tableViewController.tableView.tableHeaderView = searchBar; @@ -161,11 +154,6 @@ NS_ASSUME_NONNULL_BEGIN }]; } -- (void)showContactsPermissionReminder:(BOOL)isVisible -{ - _hideContactsPermissionReminderViewConstraint.active = !isVisible; -} - - (void)showSearchBar:(BOOL)isVisible { if (isVisible) { @@ -295,6 +283,30 @@ NS_ASSUME_NONNULL_BEGIN __weak NewContactThreadViewController *weakSelf = self; + if (self.contactsViewHelper.contactsManager.isSystemContactsDenied) { + OWSTableItem *contactReminderItem = [OWSTableItem + itemWithCustomCellBlock:^{ + UITableViewCell *newCell = [OWSTableItem newCell]; + + ReminderView *reminderView = [ReminderView + nagWithText:NSLocalizedString(@"COMPOSE_SCREEN_MISSING_CONTACTS_PERMISSION", + @"Multi-line label explaining why compose-screen contact picker is empty.") + tapAction:^{ + [[UIApplication sharedApplication] openSystemSettings]; + }]; + [newCell.contentView addSubview:reminderView]; + [reminderView autoPinEdgesToSuperviewEdges]; + + return newCell; + } + customRowHeight:UITableViewAutomaticDimension + actionBlock:nil]; + + OWSTableSection *reminderSection = [OWSTableSection new]; + [reminderSection addItem:contactReminderItem]; + [contents addSection:reminderSection]; + } + OWSTableSection *staticSection = [OWSTableSection new]; // Find Non-Contacts by Phone Number @@ -672,12 +684,10 @@ NS_ASSUME_NONNULL_BEGIN self.isNoContactsModeActive = NO; } - [self showContactsPermissionReminder:NO]; [self showSearchBar:YES]; } else { // don't show "no signal contacts", show "no contact access" self.isNoContactsModeActive = NO; - [self showContactsPermissionReminder:YES]; [self showSearchBar:NO]; } }