diff --git a/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m b/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m index 7edcd0807..8b3956b5b 100644 --- a/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m +++ b/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m @@ -165,7 +165,7 @@ [accessoryLabel sizeToFit]; cell.accessoryView = accessoryLabel; cell.accessibilityIdentifier - = SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, @"network_status"); + = SUBVIEW_ACCESSIBILITY_IDENTIFIER(AppSettingsViewController, @"network_status"); return cell; } actionBlock:nil]]; diff --git a/Signal/src/ViewControllers/AppSettings/BlockListViewController.m b/Signal/src/ViewControllers/AppSettings/BlockListViewController.m index 9bc5b337c..549ca71cf 100644 --- a/Signal/src/ViewControllers/AppSettings/BlockListViewController.m +++ b/Signal/src/ViewControllers/AppSettings/BlockListViewController.m @@ -96,8 +96,8 @@ NS_ASSUME_NONNULL_BEGIN itemWithCustomCellBlock:^{ ContactTableViewCell *cell = [ContactTableViewCell new]; [cell configureWithRecipientId:phoneNumber]; - cell.accessibilityIdentifier - = SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, @"user"); + cell.accessibilityIdentifier = SUBVIEW_ACCESSIBILITY_IDENTIFIER( + BlockListViewController, @"user"); return cell; } customRowHeight:UITableViewAutomaticDimension diff --git a/Signal/src/ViewControllers/AppSettings/NotificationSettingsOptionsViewController.m b/Signal/src/ViewControllers/AppSettings/NotificationSettingsOptionsViewController.m index 2e7da11a3..02b099a94 100644 --- a/Signal/src/ViewControllers/AppSettings/NotificationSettingsOptionsViewController.m +++ b/Signal/src/ViewControllers/AppSettings/NotificationSettingsOptionsViewController.m @@ -40,8 +40,9 @@ if (selectedNotifType == notificationType) { cell.accessoryType = UITableViewCellAccessoryCheckmark; } - cell.accessibilityIdentifier = SUBVIEW_ACCESSIBILITY_IDENTIFIER( - self, NSStringForNotificationType(notificationType)); + cell.accessibilityIdentifier + = SUBVIEW_ACCESSIBILITY_IDENTIFIER(NotificationSettingsOptionsViewController, + NSStringForNotificationType(notificationType)); return cell; } actionBlock:^{ diff --git a/Signal/src/ViewControllers/AppSettings/OWSLinkedDevicesTableViewController.m b/Signal/src/ViewControllers/AppSettings/OWSLinkedDevicesTableViewController.m index 42e1da037..04b9d605a 100644 --- a/Signal/src/ViewControllers/AppSettings/OWSLinkedDevicesTableViewController.m +++ b/Signal/src/ViewControllers/AppSettings/OWSLinkedDevicesTableViewController.m @@ -327,7 +327,7 @@ int const OWSLinkedDevicesTableViewControllerSectionAddDevice = 1; cell.detailTextLabel.text = NSLocalizedString(@"LINK_NEW_DEVICE_SUBTITLE", @"Subheading for 'Link New Device' navigation"); cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; - cell.accessibilityIdentifier = SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, @"add"); + cell.accessibilityIdentifier = SUBVIEW_ACCESSIBILITY_IDENTIFIER(OWSLinkedDevicesTableViewController, @"add"); return cell; } else if (indexPath.section == OWSLinkedDevicesTableViewControllerSectionExistingDevices) { OWSDeviceTableViewCell *cell = diff --git a/Signal/src/ViewControllers/AppSettings/PrivacySettingsTableViewController.m b/Signal/src/ViewControllers/AppSettings/PrivacySettingsTableViewController.m index d820353df..53de5bd28 100644 --- a/Signal/src/ViewControllers/AppSettings/PrivacySettingsTableViewController.m +++ b/Signal/src/ViewControllers/AppSettings/PrivacySettingsTableViewController.m @@ -411,13 +411,13 @@ static NSString *const kSealedSenderInfoURL = @"https://signal.org/blog/sealed-s - (void)clearHistoryLogs { - UIAlertController *alertController = + UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:NSLocalizedString(@"SETTINGS_DELETE_HISTORYLOG_CONFIRMATION", @"Alert message before user confirms clearing history") preferredStyle:UIAlertControllerStyleAlert]; - [alertController addAction:[OWSAlerts cancelAction]]; + [alert addAction:[OWSAlerts cancelAction]]; UIAlertAction *deleteAction = [UIAlertAction actionWithTitle: @@ -428,13 +428,9 @@ static NSString *const kSealedSenderInfoURL = @"https://signal.org/blog/sealed-s handler:^(UIAlertAction *_Nonnull action) { [self deleteThreadsAndMessages]; }]; - [alertController addAction:deleteAction]; + [alert addAction:deleteAction]; - [self presentViewController:alertController - animated:true - completion:^{ - [alertController applyAccessibilityIdentifiers]; - }]; + [self presentAlert:alert animated:YES]; } - (void)deleteThreadsAndMessages @@ -552,7 +548,7 @@ static NSString *const kSealedSenderInfoURL = @"https://signal.org/blog/sealed-s { OWSLogInfo(@""); - UIAlertController *controller = [UIAlertController + UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"SETTINGS_SCREEN_LOCK_ACTIVITY_TIMEOUT", @"Label for the 'screen lock activity timeout' setting of the privacy settings.") message:nil @@ -568,15 +564,11 @@ static NSString *const kSealedSenderInfoURL = @"https://signal.org/blog/sealed-s [OWSScreenLock.sharedManager setScreenLockTimeout:screenLockTimeout]; }]; action.accessibilityIdentifier = [NSString stringWithFormat:@"settings.privacy.timeout.%@", timeoutValue]; - [controller addAction:action]; + [alert addAction:action]; } - [controller addAction:[OWSAlerts cancelAction]]; + [alert addAction:[OWSAlerts cancelAction]]; UIViewController *fromViewController = [[UIApplication sharedApplication] frontmostViewController]; - [fromViewController presentViewController:controller - animated:YES - completion:^{ - [controller applyAccessibilityIdentifiers]; - }]; + [fromViewController presentAlert:alert animated:YES]; } - (NSString *)formatScreenLockTimeout:(NSInteger)value useShortFormat:(BOOL)useShortFormat diff --git a/Signal/src/ViewControllers/ProfileViewController.m b/Signal/src/ViewControllers/ProfileViewController.m index 534394a28..692a20d88 100644 --- a/Signal/src/ViewControllers/ProfileViewController.m +++ b/Signal/src/ViewControllers/ProfileViewController.m @@ -297,7 +297,7 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat } __weak ProfileViewController *weakSelf = self; - UIAlertController *controller = [UIAlertController + UIAlertController *alert = [UIAlertController alertControllerWithTitle: NSLocalizedString(@"NEW_GROUP_VIEW_UNSAVED_CHANGES_TITLE", @"The alert title if user tries to exit the new group view without saving changes.") @@ -313,14 +313,10 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat [weakSelf profileCompletedOrSkipped]; }]; discardAction.accessibilityIdentifier = SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, @"discard"); - [controller addAction:discardAction]; - - [controller addAction:[OWSAlerts cancelAction]]; - [self presentViewController:controller - animated:YES - completion:^{ - [controller applyAccessibilityIdentifiers]; - }]; + [alert addAction:discardAction]; + + [alert addAction:[OWSAlerts cancelAction]]; + [self presentAlert:alert animated:YES]; } - (void)avatarTapped diff --git a/Signal/src/util/Pastelog.m b/Signal/src/util/Pastelog.m index c5e987cb5..00329126d 100644 --- a/Signal/src/util/Pastelog.m +++ b/Signal/src/util/Pastelog.m @@ -378,11 +378,7 @@ typedef void (^DebugLogUploadFailure)(DebugLogUploader *uploader, NSError *error [alert addAction:[OWSAlerts cancelAction]]; UIViewController *presentingViewController = UIApplication.sharedApplication.frontmostViewControllerIgnoringAlerts; - [presentingViewController presentViewController:alert - animated:NO - completion:^{ - [alert applyAccessibilityIdentifiers]; - }]; + [presentingViewController presentAlert:alert animated:NO]; }]; } @@ -523,11 +519,7 @@ typedef void (^DebugLogUploadFailure)(DebugLogUploader *uploader, NSError *error style:UIAlertActionStyleDefault handler:nil]]; UIViewController *presentingViewController = UIApplication.sharedApplication.frontmostViewControllerIgnoringAlerts; - [presentingViewController presentViewController:alert - animated:NO - completion:^{ - [alert applyAccessibilityIdentifiers]; - }]; + [presentingViewController presentAlert:alert animated:NO]; } #pragma mark Logs submission @@ -592,11 +584,7 @@ typedef void (^DebugLogUploadFailure)(DebugLogUploader *uploader, NSError *error completion(); }]]; UIViewController *presentingViewController = UIApplication.sharedApplication.frontmostViewControllerIgnoringAlerts; - [presentingViewController presentViewController:alert - animated:NO - completion:^{ - [alert applyAccessibilityIdentifiers]; - }]; + [presentingViewController presentAlert:alert animated:NO]; } - (void)sendToSelf:(NSURL *)url diff --git a/SignalMessaging/Views/OWSAlerts.swift b/SignalMessaging/Views/OWSAlerts.swift index a7bd25a2f..ec4e1687a 100644 --- a/SignalMessaging/Views/OWSAlerts.swift +++ b/SignalMessaging/Views/OWSAlerts.swift @@ -11,20 +11,17 @@ import Foundation public class func showNoMicrophonePermissionAlert() { let alertTitle = NSLocalizedString("CALL_AUDIO_PERMISSION_TITLE", comment: "Alert title when calling and permissions for microphone are missing") let alertMessage = NSLocalizedString("CALL_AUDIO_PERMISSION_MESSAGE", comment: "Alert message when calling and permissions for microphone are missing") - let alertController = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: .alert) + let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: .alert) let dismissAction = UIAlertAction(title: CommonStrings.dismissButton, style: .cancel) dismissAction.accessibilityIdentifier = "OWSAlerts.\("dismiss")" - alertController.addAction(dismissAction) + alert.addAction(dismissAction) if let settingsAction = CurrentAppContext().openSystemSettingsAction { settingsAction.accessibilityIdentifier = "OWSAlerts.\("settings")" - alertController.addAction(settingsAction) + alert.addAction(settingsAction) } - CurrentAppContext().frontmostViewController()?.present(alertController, animated: true, - completion: { - alertController.applyAccessibilityIdentifiers() - }) + CurrentAppContext().frontmostViewController()?.presentAlert(alert) } @objc @@ -33,10 +30,7 @@ import Foundation owsFailDebug("frontmostViewController was unexpectedly nil") return } - frontmostViewController.present(alert, animated: true, - completion: { - alert.applyAccessibilityIdentifiers() - }) + frontmostViewController.presentAlert(alert) } @objc @@ -67,10 +61,7 @@ import Foundation let okAction = UIAlertAction(title: actionTitle, style: .default, handler: buttonAction) okAction.accessibilityIdentifier = "OWSAlerts.\("ok")" alert.addAction(okAction) - fromViewController?.present(alert, animated: true, - completion: { - alert.applyAccessibilityIdentifiers() - }) + fromViewController?.presentAlert(alert) } @objc @@ -85,10 +76,7 @@ import Foundation okAction.accessibilityIdentifier = "OWSAlerts.\("ok")" alert.addAction(okAction) - CurrentAppContext().frontmostViewController()?.present(alert, animated: true, - completion: { - alert.applyAccessibilityIdentifiers() - }) + CurrentAppContext().frontmostViewController()?.presentAlert(alert) } @objc diff --git a/SignalMessaging/categories/UIView+OWS.swift b/SignalMessaging/categories/UIView+OWS.swift index a3d6ac960..82d48a014 100644 --- a/SignalMessaging/categories/UIView+OWS.swift +++ b/SignalMessaging/categories/UIView+OWS.swift @@ -13,6 +13,8 @@ public extension UIEdgeInsets { } } +// MARK: - + @objc public extension UINavigationController { @objc @@ -45,6 +47,8 @@ public extension UINavigationController { } } +// MARK: - + extension UIView { public func renderAsImage() -> UIImage? { return renderAsImage(opaque: false, scale: UIScreen.main.scale) @@ -124,6 +128,21 @@ extension UIView { } } +// MARK: - + +extension UIViewController { + @objc + public func presentAlert(_ alert: UIAlertController, animated: Bool = true) { + self.present(alert, + animated: animated, + completion: { + alert.applyAccessibilityIdentifiers() + }) + } +} + +// MARK: - + public extension CGFloat { public func clamp(_ minValue: CGFloat, _ maxValue: CGFloat) -> CGFloat { return CGFloatClamp(self, minValue, maxValue) @@ -155,6 +174,8 @@ public extension CGFloat { } } +// MARK: - + public extension Int { public func clamp(_ minValue: Int, _ maxValue: Int) -> Int { assert(minValue <= maxValue) @@ -163,6 +184,8 @@ public extension Int { } } +// MARK: - + public extension CGPoint { public func toUnitCoordinates(viewBounds: CGRect, shouldClamp: Bool) -> CGPoint { return CGPoint(x: (x - viewBounds.origin.x).inverseLerp(0, viewBounds.width, shouldClamp: shouldClamp), @@ -233,6 +256,8 @@ public extension CGPoint { } } +// MARK: - + public extension CGSize { var aspectRatio: CGFloat { guard self.height > 0 else { @@ -251,6 +276,8 @@ public extension CGSize { } } +// MARK: - + public extension CGRect { public var center: CGPoint { return CGPoint(x: midX, y: midY) @@ -273,6 +300,8 @@ public extension CGRect { } } +// MARK: - + public extension CGAffineTransform { public static func translate(_ point: CGPoint) -> CGAffineTransform { return CGAffineTransform(translationX: point.x, y: point.y) @@ -295,6 +324,8 @@ public extension CGAffineTransform { } } +// MARK: - + public extension UIBezierPath { public func addRegion(withPoints points: [CGPoint]) { guard let first = points.first else { diff --git a/SignalMessaging/utils/BlockListUIUtils.m b/SignalMessaging/utils/BlockListUIUtils.m index c8f71adaf..7deedd2c9 100644 --- a/SignalMessaging/utils/BlockListUIUtils.m +++ b/SignalMessaging/utils/BlockListUIUtils.m @@ -142,12 +142,7 @@ typedef void (^BlockAlertCompletionBlock)(UIAlertAction *action); }]; dismissAction.accessibilityIdentifier = SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, @"dismiss"); [actionSheetController addAction:dismissAction]; - - [fromViewController presentViewController:actionSheetController - animated:YES - completion:^{ - [actionSheetController applyAccessibilityIdentifiers]; - }]; + [fromViewController presentAlert:actionSheetController animated:YES]; } + (void)showBlockGroupActionSheet:(TSGroupThread *)groupThread @@ -198,12 +193,7 @@ typedef void (^BlockAlertCompletionBlock)(UIAlertAction *action); }]; dismissAction.accessibilityIdentifier = SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, @"dismiss"); [actionSheetController addAction:dismissAction]; - - [fromViewController presentViewController:actionSheetController - animated:YES - completion:^{ - [actionSheetController applyAccessibilityIdentifiers]; - }]; + [fromViewController presentAlert:actionSheetController animated:YES]; } + (void)blockPhoneNumbers:(NSArray *)phoneNumbers @@ -369,12 +359,7 @@ typedef void (^BlockAlertCompletionBlock)(UIAlertAction *action); }]; dismissAction.accessibilityIdentifier = SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, @"dismiss"); [actionSheetController addAction:dismissAction]; - - [fromViewController presentViewController:actionSheetController - animated:YES - completion:^{ - [actionSheetController applyAccessibilityIdentifiers]; - }]; + [fromViewController presentAlert:actionSheetController animated:YES]; } + (void)unblockPhoneNumbers:(NSArray *)phoneNumbers @@ -448,12 +433,7 @@ typedef void (^BlockAlertCompletionBlock)(UIAlertAction *action); }]; dismissAction.accessibilityIdentifier = SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, @"dismiss"); [actionSheetController addAction:dismissAction]; - - [fromViewController presentViewController:actionSheetController - animated:YES - completion:^{ - [actionSheetController applyAccessibilityIdentifiers]; - }]; + [fromViewController presentAlert:actionSheetController animated:YES]; } + (void)unblockGroup:(TSGroupModel *)groupModel @@ -490,19 +470,15 @@ typedef void (^BlockAlertCompletionBlock)(UIAlertAction *action); OWSAssertDebug(title.length > 0); OWSAssertDebug(fromViewController); - UIAlertController *controller = + UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleDefault handler:completionBlock]; okAction.accessibilityIdentifier = SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, @"ok"); - [controller addAction:okAction]; - [fromViewController presentViewController:controller - animated:YES - completion:^{ - [controller applyAccessibilityIdentifiers]; - }]; + [alert addAction:okAction]; + [fromViewController presentAlert:alert animated:YES]; } + (NSString *)formatDisplayNameForAlertTitle:(NSString *)displayName