From fe62a6ac924bc90a4fb2042e733832a04d46b377 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Fri, 18 May 2018 16:17:45 -0400 Subject: [PATCH] CNContactController needs to be presented in a navcontroller with a translucent navbar. In cases where we were presenting modally, we can easily modify the modal to have a translucent navbar. In the one place we were pushing onto the SignalsNavigationController, rather than modifying the SNC.isTranslucent and having to clean it up, I've opted to convert to a modal presentation. // FREEBIE --- Signal/src/AppDelegate.m | 1 - ...ShareToExistingContactViewController.swift | 31 ++++++++++++++++--- .../ContactShareViewHelper.swift | 13 +++++--- SignalMessaging/Views/ContactsViewHelper.m | 22 +++++++------ 4 files changed, 48 insertions(+), 19 deletions(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 49e60c194..6a6cbe549 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -1099,7 +1099,6 @@ static NSTimeInterval launchStartedAt; // Resume lazy restore. [OWSBackupLazyRestoreJob runAsync]; #endif - } - (void)registrationStateDidChange diff --git a/Signal/src/ViewControllers/AddContactShareToExistingContactViewController.swift b/Signal/src/ViewControllers/AddContactShareToExistingContactViewController.swift index 327de07ab..0f5c1a3eb 100644 --- a/Signal/src/ViewControllers/AddContactShareToExistingContactViewController.swift +++ b/Signal/src/ViewControllers/AddContactShareToExistingContactViewController.swift @@ -74,11 +74,19 @@ class AddContactShareToExistingContactViewController: ContactsPicker, ContactsPi contactViewController.allowsEditing = true contactViewController.delegate = self - guard let navigationController = self.navigationController else { - owsFail("\(logTag) in \(#function) navigationController was unexpectedly nil") - return + let modal = OWSNavigationController(rootViewController: contactViewController) + + // HACK otherwise CNContactViewController Navbar is shows window background color. + // RADAR rdar://28433898 http://www.openradar.me/28433898 + // CNContactViewController incompatible with opaque navigation bar + modal.navigationBar.isTranslucent = true + if #available(iOS 10, *) { + // Contact navbar is blue in iOS9, so our white text works, + // but gray on iOS10+, in which case we want the system default black text. + UIUtil.applyDefaultSystemAppearence() } - navigationController.pushViewController(contactViewController, animated: true) + + self.present(modal, animated: true) } func contactsPicker(_: ContactsPicker, didSelectMultipleContacts contacts: [Contact]) { @@ -126,8 +134,21 @@ class AddContactShareToExistingContactViewController: ContactsPicker, ContactsPi return } + // HACK otherwise CNContactViewController Navbar is shows window background color. + // RADAR rdar://28433898 http://www.openradar.me/28433898 + // CNContactViewController incompatible with opaque navigation bar + navigationController.navigationBar.isTranslucent = false + if #available(iOS 10, *) { + // Contact navbar is blue in iOS9, so our white text works, + // but gray on iOS10+, in which case we want the system default black text. + UIUtil.applySignalAppearence() + } + let previousViewControllerIndex = navigationController.viewControllers.index(before: myIndex) let previousViewController = navigationController.viewControllers[previousViewControllerIndex] - navigationController.popToViewController(previousViewController, animated: true) + + self.dismiss(animated: false) { + navigationController.popToViewController(previousViewController, animated: true) + } } } diff --git a/Signal/src/ViewControllers/ContactShareViewHelper.swift b/Signal/src/ViewControllers/ContactShareViewHelper.swift index 0323f2006..c4c31b35b 100644 --- a/Signal/src/ViewControllers/ContactShareViewHelper.swift +++ b/Signal/src/ViewControllers/ContactShareViewHelper.swift @@ -163,12 +163,17 @@ public class ContactShareViewHelper: NSObject, CNContactViewControllerDelegate { target: self, action: #selector(didFinishEditingContact)) - // HACK otherwise CNContactViewController Navbar is shown as black. + let modal = OWSNavigationController(rootViewController: contactViewController) + // HACK otherwise CNContactViewController Navbar is shows window background color. // RADAR rdar://28433898 http://www.openradar.me/28433898 // CNContactViewController incompatible with opaque navigation bar - UIUtil.applyDefaultSystemAppearence() + modal.navigationBar.isTranslucent = true + if #available(iOS 10, *) { + // Contact navbar is blue in iOS9, so our white text works, + // but gray on iOS10+, in which case we want the system default black text. + UIUtil.applyDefaultSystemAppearence() + } - let modal = OWSNavigationController(rootViewController: contactViewController) fromViewController.present(modal, animated: true) } @@ -189,7 +194,7 @@ public class ContactShareViewHelper: NSObject, CNContactViewControllerDelegate { } let viewController = AddContactShareToExistingContactViewController(contactShare: contactShare) - + UIUtil.applySignalAppearence() navigationController.pushViewController(viewController, animated: true) } diff --git a/SignalMessaging/Views/ContactsViewHelper.m b/SignalMessaging/Views/ContactsViewHelper.m index dc444ec83..60820ae6a 100644 --- a/SignalMessaging/Views/ContactsViewHelper.m +++ b/SignalMessaging/Views/ContactsViewHelper.m @@ -392,19 +392,23 @@ NS_ASSUME_NONNULL_BEGIN target:fromViewController action:@selector(didFinishEditingContact)]; - OWSNavigationController *navigationController = - [[OWSNavigationController alloc] initWithRootViewController:contactViewController]; + OWSNavigationController *modal = [[OWSNavigationController alloc] initWithRootViewController:contactViewController]; + + // HACK otherwise CNContactViewController Navbar is shows window background color. + // RADAR rdar://28433898 http://www.openradar.me/28433898 + // CNContactViewController incompatible with opaque navigation bar + modal.navigationBar.translucent = YES; + if (@available(iOS 10, *)) { + // Contact navbar is blue in iOS9, so our white tex works, + // but gray on iOS10+, in which case we want the system default black text. + [UIUtil applyDefaultSystemAppearence]; + } // We want the presentation to imply a "replacement" in this case. if (shouldEditImmediately) { - navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; + modal.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; } - [fromViewController presentViewController:navigationController animated:YES completion:nil]; - - // HACK otherwise CNContactViewController Navbar is shown as black. - // RADAR rdar://28433898 http://www.openradar.me/28433898 - // CNContactViewController incompatible with opaque navigation bar - [UIUtil applyDefaultSystemAppearence]; + [fromViewController presentViewController:modal animated:YES completion:nil]; } @end