Ensure inputAccessory doesn't obscure the SN alert

This affects iOS 8, 9, and to a lesser degree iOS10.
On iOS11, presenting an alert causes the keyboard/inputAccessoryView to
temporarily dismiss.

// FREEBIE
This commit is contained in:
Michael Kirk 2018-02-20 19:52:49 -05:00
parent c0d1126394
commit d7f8c3e9d3
3 changed files with 47 additions and 10 deletions

View File

@ -1356,9 +1356,28 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
completion:(void (^)(BOOL didConfirmIdentity))completionHandler
{
return [SafetyNumberConfirmationAlert presentAlertIfNecessaryWithRecipientIds:self.thread.recipientIdentifiers
confirmationText:confirmationText
contactsManager:self.contactsManager
completion:completionHandler];
confirmationText:confirmationText
contactsManager:self.contactsManager
completion:^(BOOL didShowAlert) {
// Pre iOS-11, the keyboard and inputAccessoryView will obscure the alert if the keyboard is up when the
// alert is presented, so after hiding it, we regain first responder here.
if (@available(iOS 11.0, *)) {
// do nothing
} else {
[self becomeFirstResponder];
}
completionHandler(didShowAlert);
}
beforePresentationHandler:^(void) {
if (@available(iOS 11.0, *)) {
// do nothing
} else {
// Pre iOS-11, the keyboard and inputAccessoryView will obscure the alert if the keyboard is up when the
// alert is presented.
[self dismissKeyBoard];
[self resignFirstResponder];
}
}];
}
- (void)showFingerprintWithRecipientId:(NSString *)recipientId

View File

@ -18,13 +18,22 @@ class SafetyNumberConfirmationAlert: NSObject {
}
public class func presentAlertIfNecessary(recipientId: String, confirmationText: String, contactsManager: OWSContactsManager, completion: @escaping (Bool) -> Void) -> Bool {
return self.presentAlertIfNecessary(recipientIds: [recipientId], confirmationText: confirmationText, contactsManager: contactsManager, completion: completion)
return self.presentAlertIfNecessary(recipientIds: [recipientId], confirmationText: confirmationText, contactsManager: contactsManager, completion: completion, beforePresentationHandler: nil)
}
public class func presentAlertIfNecessary(recipientId: String, confirmationText: String, contactsManager: OWSContactsManager, completion: @escaping (Bool) -> Void, beforePresentationHandler: (() -> Void)? = nil) -> Bool {
return self.presentAlertIfNecessary(recipientIds: [recipientId], confirmationText: confirmationText, contactsManager: contactsManager, completion: completion, beforePresentationHandler: beforePresentationHandler)
}
public class func presentAlertIfNecessary(recipientIds: [String], confirmationText: String, contactsManager: OWSContactsManager, completion: @escaping (Bool) -> Void) -> Bool {
return self.presentAlertIfNecessary(recipientIds: recipientIds, confirmationText: confirmationText, contactsManager: contactsManager, completion: completion, beforePresentationHandler: nil)
}
public class func presentAlertIfNecessary(recipientIds: [String], confirmationText: String, contactsManager: OWSContactsManager, completion: @escaping (Bool) -> Void, beforePresentationHandler: (() -> Void)? = nil) -> Bool {
return SafetyNumberConfirmationAlert(contactsManager: contactsManager).presentIfNecessary(recipientIds: recipientIds,
confirmationText: confirmationText,
completion: completion)
completion: completion,
beforePresentationHandler: beforePresentationHandler)
}
/**
@ -33,7 +42,7 @@ class SafetyNumberConfirmationAlert: NSObject {
* @returns true if an alert was shown
* false if there were no unconfirmed identities
*/
public func presentIfNecessary(recipientIds: [String], confirmationText: String, completion: @escaping (Bool) -> Void) -> Bool {
public func presentIfNecessary(recipientIds: [String], confirmationText: String, completion: @escaping (Bool) -> Void, beforePresentationHandler: (() -> Void)? = nil) -> Bool {
guard let untrustedIdentity = untrustedIdentityForSending(recipientIds: recipientIds) else {
// No identities to confirm, no alert to present.
@ -75,7 +84,15 @@ class SafetyNumberConfirmationAlert: NSObject {
}
actionSheetController.addAction(showSafetyNumberAction)
actionSheetController.addAction(OWSAlerts.cancelAction)
// We can't use the default `OWSAlerts.cancelAction` because we need to specify that the completion
// handler is called.
let cancelAction = UIAlertAction(title: CommonStrings.cancelButton, style: .cancel) { _ in
Logger.info("\(self.logTag) user canceled.")
completion(false)
}
actionSheetController.addAction(cancelAction)
beforePresentationHandler?()
UIApplication.shared.frontmostViewController?.present(actionSheetController, animated: true)
return true

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
import Foundation
@ -55,11 +55,12 @@ import SignalMessaging
let showedAlert = SafetyNumberConfirmationAlert.presentAlertIfNecessary(recipientId: recipientId,
confirmationText: CallStrings.confirmAndCallButtonTitle,
contactsManager: self.contactsManager) { didConfirmIdentity in
contactsManager: self.contactsManager,
completion: { didConfirmIdentity in
if didConfirmIdentity {
_ = self.initiateCall(recipientId: recipientId)
}
}
})
guard !showedAlert else {
return false
}