Add contact modally and restore navbar style when dismssing contacts

// FREEBIE
pull/1/head
Michael Kirk 7 years ago
parent 4949ade274
commit 117d7319d2

@ -158,23 +158,18 @@ public class ContactShareViewHelper: NSObject, CNContactViewControllerDelegate {
contactViewController.delegate = self contactViewController.delegate = self
contactViewController.allowsActions = false contactViewController.allowsActions = false
contactViewController.allowsEditing = true contactViewController.allowsEditing = true
contactViewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title: CommonStrings.cancelButton, style: .plain, target: self, action: #selector(didFinishEditingContact))
contactViewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title: CommonStrings.cancelButton, contactViewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title: CommonStrings.cancelButton,
style: .plain, style: .plain,
target: self, target: self,
action: #selector(didFinishEditingContact)) action: #selector(didFinishEditingContact))
guard let navigationController = fromViewController.navigationController else {
owsFail("\(logTag) missing navigationController")
return
}
navigationController.pushViewController(contactViewController, animated: true)
// HACK otherwise CNContactViewController Navbar is shown as black. // HACK otherwise CNContactViewController Navbar is shown as black.
// RADAR rdar://28433898 http://www.openradar.me/28433898 // RADAR rdar://28433898 http://www.openradar.me/28433898
// CNContactViewController incompatible with opaque navigation bar // CNContactViewController incompatible with opaque navigation bar
UIUtil.applyDefaultSystemAppearence() UIUtil.applyDefaultSystemAppearence()
let modal = UINavigationController(rootViewController: contactViewController)
fromViewController.present(modal, animated: true)
} }
private func presentSelectAddToExistingContactView(contactShare: ContactShareViewModel, fromViewController: UIViewController) { private func presentSelectAddToExistingContactView(contactShare: ContactShareViewModel, fromViewController: UIViewController) {
@ -208,6 +203,7 @@ public class ContactShareViewHelper: NSObject, CNContactViewControllerDelegate {
return return
} }
UIUtil.applySignalAppearence()
delegate.didCreateOrEditContact() delegate.didCreateOrEditContact()
} }
@ -219,6 +215,7 @@ public class ContactShareViewHelper: NSObject, CNContactViewControllerDelegate {
return return
} }
UIUtil.applySignalAppearence()
delegate.didCreateOrEditContact() delegate.didCreateOrEditContact()
} }
} }

@ -39,8 +39,6 @@ class ContactViewController: OWSViewController, ContactShareViewHelperDelegate {
private var contactShareViewHelper: ContactShareViewHelper private var contactShareViewHelper: ContactShareViewHelper
private weak var postDismissNavigationController: UINavigationController?
// MARK: - Initializers // MARK: - Initializers
@available(*, unavailable, message: "use init(call:) constructor instead.") @available(*, unavailable, message: "use init(call:) constructor instead.")
@ -77,8 +75,11 @@ class ContactViewController: OWSViewController, ContactShareViewHelperDelegate {
override func viewWillAppear(_ animated: Bool) { override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated) super.viewWillAppear(animated)
// Use "dark" style navigation bar in this view. // Use "dark" style status bar in this view,
UIUtil.applyDefaultSystemAppearence() // But we don't apply the entire default system UI (UIUtil.applyDefaultSystemAppearence) because
// doing so while pushing onto an existing nav controller who's navbars are hidden corrupts the
// title label/navbar items elsewhere in the stack.
CurrentAppContext().setStatusBarStyle(.default)
guard let navigationController = self.navigationController else { guard let navigationController = self.navigationController else {
owsFail("\(logTag) in \(#function) navigationController was unexpectedly nil") owsFail("\(logTag) in \(#function) navigationController was unexpectedly nil")
@ -86,35 +87,26 @@ class ContactViewController: OWSViewController, ContactShareViewHelperDelegate {
} }
navigationController.isNavigationBarHidden = true navigationController.isNavigationBarHidden = true
// self.navigationController is nil in viewDidDisappear when transition via message/call buttons
// so we maintain our own reference.
self.postDismissNavigationController = navigationController
contactsManager.requestSystemContactsOnce(completion: { [weak self] _ in contactsManager.requestSystemContactsOnce(completion: { [weak self] _ in
guard let strongSelf = self else { return } guard let strongSelf = self else { return }
strongSelf.updateMode() strongSelf.updateMode()
}) })
} }
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// Use "dark" style navigation bar in this view.
UIUtil.applyDefaultSystemAppearence()
}
override func viewWillDisappear(_ animated: Bool) { override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated) super.viewWillDisappear(animated)
// We don't need to use UIUtil to restore appearance (e.g. of navigation bar). if self.presentedViewController == nil {
// This view is only presented from conversation view which will restore // No need to do this when we're disappearing due to a modal presentation.
// "Signal" appearance. // We'll eventually return to to this view and need to hide again. But also, there is a visible animation glitch where the navigation bar for this view controller starts to appear while the whole nav stack is about to be obscured by the modal we are presenting.
guard let strongNavigationController = postDismissNavigationController else { guard let navigationController = self.navigationController else {
owsFail("\(self.logTag) in \(#function) navigationController was unexpectedly nil") owsFail("\(logTag) in \(#function) navigationController was unexpectedly nil")
return return
}
navigationController.setNavigationBarHidden(false, animated: animated)
} }
strongNavigationController.isNavigationBarHidden = false
} }
override func loadView() { override func loadView() {
@ -675,13 +667,9 @@ class ContactViewController: OWSViewController, ContactShareViewHelperDelegate {
public func didCreateOrEditContact() { public func didCreateOrEditContact() {
Logger.info("\(logTag) \(#function)") Logger.info("\(logTag) \(#function)")
guard let navigationController = self.navigationController else {
owsFail("\(logTag) in \(#function) navigationController was unexpectedly nil")
return
}
navigationController.popToViewController(self, animated: true)
updateContent() updateContent()
UIUtil.applySignalAppearence()
self.dismiss(animated: true)
} }
} }

@ -5058,8 +5058,7 @@ interactionControllerForAnimationController:(id<UIViewControllerAnimatedTransiti
- (void)didCreateOrEditContact - (void)didCreateOrEditContact
{ {
DDLogInfo(@"%@ in %s", self.logTag, __PRETTY_FUNCTION__); DDLogInfo(@"%@ in %s", self.logTag, __PRETTY_FUNCTION__);
[self dismissViewControllerAnimated:YES completion:nil];
[self.navigationController popToViewController:self animated:true];
} }
@end @end

@ -720,12 +720,7 @@ class MessageDetailViewController: OWSViewController, MediaGalleryDataSourceDele
// MARK: - ContactShareViewHelperDelegate // MARK: - ContactShareViewHelperDelegate
public func didCreateOrEditContact() { public func didCreateOrEditContact() {
guard let navigationController = self.navigationController else {
owsFail("\(logTag) in \(#function) navigationController was unexpectedly nil")
return
}
navigationController.popToViewController(self, animated: true)
updateContent() updateContent()
self.dismiss(animated: true)
} }
} }

Loading…
Cancel
Save