Skip to content

Commit

Permalink
Merge branch 'export-identifiers-for-accessibility-elements-ios-127'
Browse files Browse the repository at this point in the history
  • Loading branch information
buggmagnet committed Dec 20, 2023
2 parents 0f6214d + 3fe502f commit ce7f4f7
Show file tree
Hide file tree
Showing 29 changed files with 221 additions and 128 deletions.
12 changes: 10 additions & 2 deletions ios/MullvadVPN.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@
58FF9FF42B07C61B00E4C97D /* AccessMethodValidationError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58FF9FF32B07C61B00E4C97D /* AccessMethodValidationError.swift */; };
7A02D4EB2A9CEC7A00C19E31 /* MullvadVPNScreenshots.xctestplan in Resources */ = {isa = PBXBuildFile; fileRef = 7A02D4EA2A9CEC7A00C19E31 /* MullvadVPNScreenshots.xctestplan */; };
7A09C98129D99215000C2CAC /* String+FuzzyMatch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A09C98029D99215000C2CAC /* String+FuzzyMatch.swift */; };
7A0B311E2B303A0D004B12E0 /* AccessbilityIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A0B311D2B303A0D004B12E0 /* AccessbilityIdentifier.swift */; };
7A0B311F2B303A11004B12E0 /* AccessbilityIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A0B311D2B303A0D004B12E0 /* AccessbilityIdentifier.swift */; };
7A0C0F632A979C4A0058EFCE /* Coordinator+Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A0C0F622A979C4A0058EFCE /* Coordinator+Router.swift */; };
7A11DD0B2A9495D400098CD8 /* AppRoutes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5802EBC42A8E44AC00E5CE4C /* AppRoutes.swift */; };
7A12D0762B062D5C00E9602D /* URLSessionProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A12D0752B062D5C00E9602D /* URLSessionProtocol.swift */; };
Expand Down Expand Up @@ -1630,6 +1632,8 @@
58FF9FF32B07C61B00E4C97D /* AccessMethodValidationError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccessMethodValidationError.swift; sourceTree = "<group>"; };
7A02D4EA2A9CEC7A00C19E31 /* MullvadVPNScreenshots.xctestplan */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = MullvadVPNScreenshots.xctestplan; sourceTree = "<group>"; };
7A09C98029D99215000C2CAC /* String+FuzzyMatch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+FuzzyMatch.swift"; sourceTree = "<group>"; };
7A0B31152B2B4BE7004B12E0 /* AccessbilityIdentifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccessbilityIdentifier.swift; sourceTree = "<group>"; };
7A0B311D2B303A0D004B12E0 /* AccessbilityIdentifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccessbilityIdentifier.swift; sourceTree = "<group>"; };
7A0C0F622A979C4A0058EFCE /* Coordinator+Router.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Coordinator+Router.swift"; sourceTree = "<group>"; };
7A12D0752B062D5C00E9602D /* URLSessionProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = URLSessionProtocol.swift; sourceTree = "<group>"; };
7A1A26422A2612AE00B978AA /* PaymentAlertPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentAlertPresenter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2019,15 +2023,16 @@
581943F228F8014500B0CB5E /* MullvadTypes */ = {
isa = PBXGroup;
children = (
7A0B31152B2B4BE7004B12E0 /* AccessbilityIdentifier.swift */,
584D26BE270C550B004EA533 /* AnyIPAddress.swift */,
586A951329013235007BAF2B /* AnyIPEndpoint.swift */,
06AC113628F83FD70037AF9A /* Cancellable.swift */,
A9A8A8EA2A262AB30086D569 /* FileCache.swift */,
58E511E328DDDE8900B0BCDE /* CustomErrorDescriptionProtocol.swift */,
586168682976F6BD00EF8598 /* DisplayError.swift */,
7A307AD82A8CD8DA0017618B /* Duration.swift */,
7A307ADA2A8F56DF0017618B /* Duration+Extensions.swift */,
58E511EA28DDE18400B0BCDE /* Error+Chain.swift */,
A9A8A8EA2A262AB30086D569 /* FileCache.swift */,
58900D0228BBDCC70094E4F0 /* FixedWidthInteger+Arithmetics.swift */,
06AC115628F848D00037AF9A /* IPAddress+Codable.swift */,
58561C98239A5D1500BD6B5E /* IPv4Endpoint.swift */,
Expand All @@ -2044,8 +2049,8 @@
5898D2AF2902A67C00EB5EBA /* RelayLocation.swift */,
581DA2722A1E227D0046ED47 /* RESTTypes.swift */,
58F1311427E0B2AB007AC5BC /* Result+Extensions.swift */,
58E511E028DDB7F100B0BCDE /* WrappingError.swift */,
A91614D02B108D1B00F416EB /* TransportLayer.swift */,
58E511E028DDB7F100B0BCDE /* WrappingError.swift */,
);
path = MullvadTypes;
sourceTree = "<group>";
Expand Down Expand Up @@ -2428,6 +2433,7 @@
583FE02829C1B079006E85F9 /* Classes */ = {
isa = PBXGroup;
children = (
7A0B311D2B303A0D004B12E0 /* AccessbilityIdentifier.swift */,
587988C628A2A01F00E3DF54 /* AccountDataThrottling.swift */,
F04FBE602A8379EE009278D7 /* AppPreferences.swift */,
5802EBC42A8E44AC00E5CE4C /* AppRoutes.swift */,
Expand Down Expand Up @@ -4661,6 +4667,7 @@
7A9CCCB82A96302800DD6A34 /* SetupAccountCompletedCoordinator.swift in Sources */,
58435AC229CB2A350099C71B /* LocationCellFactory.swift in Sources */,
58BFA5C622A7C97F00A6173D /* RelayCacheTracker.swift in Sources */,
7A0B311E2B303A0D004B12E0 /* AccessbilityIdentifier.swift in Sources */,
E158B360285381C60002F069 /* String+AccountFormatting.swift in Sources */,
7AC8A3AE2ABC6FBB00DC4939 /* SettingsHeaderView.swift in Sources */,
588D7EDC2AF3A55E005DF40A /* ListAccessMethodInteractorProtocol.swift in Sources */,
Expand Down Expand Up @@ -4958,6 +4965,7 @@
buildActionMask = 2147483647;
files = (
58D0C7A223F1CECF00FE9BA7 /* MullvadVPNScreenshots.swift in Sources */,
7A0B311F2B303A11004B12E0 /* AccessbilityIdentifier.swift in Sources */,
58D0C79E23F1CEBA00FE9BA7 /* SnapshotHelper.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
4 changes: 4 additions & 0 deletions ios/MullvadVPN/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
if ProcessInfo().arguments.contains("DisableAnimations") {
UIView.setAnimationsEnabled(false)
}

let containerURL = ApplicationConfiguration.containerURL

configureLogging()
Expand Down
77 changes: 77 additions & 0 deletions ios/MullvadVPN/Classes/AccessbilityIdentifier.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// RelayFilter.swift
// MullvadVPN
//
// Created by Jon Petersson on 2023-12-20.
// Copyright © 2023 Mullvad VPN AB. All rights reserved.
//

import UIKit

public enum AccessibilityIdentifier: String {
// Buttons
case accountButton
case agreeButton
case alertOkButton
case applyButton
case cancelButton
case collapseButton
case deleteButton
case disconnectButton
case infoButton
case learnAboutPrivacyButton
case loginBarButton
case logoutButton
case purchaseButton
case redeemVoucherButton
case selectLocationButton
case settingsButton
case startUsingTheAppButton

// Cells
case preferencesCell
case versionCell
case problemReportCell
case faqCell
case apiAccessCell
case relayFilterOwnershipCell
case relayFilterProviderCell

// Other UI elements
case loginTextField

// DNS settings
case dnsSettings
case wireGuardCustomPort
case wireGuardObfuscationAutomatic
case wireGuardObfuscationOff
case wireGuardObfuscationOn
case wireGuardPort

// Custom DNS
case blockAdvertising
case blockTracking
case blockMalware
case blockGambling
case blockAdultContent
case blockSocialMedia
case useCustomDNS
case addDNSServer
case dnsServer
case dnsServerInfo

// Error
case unknown
}

extension UIAccessibilityIdentification {
var accessibilityIdentifier: AccessibilityIdentifier? {
get {
guard let accessibilityIdentifier else { return nil }
return AccessibilityIdentifier(rawValue: accessibilityIdentifier)
}
set {
accessibilityIdentifier = newValue?.rawValue
}
}
}
5 changes: 2 additions & 3 deletions ios/MullvadVPN/Containers/Root/HeaderBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// Copyright © 2020 Mullvad VPN AB. All rights reserved.
//

import Foundation
import UIKit

class HeaderBarView: UIView {
Expand Down Expand Up @@ -58,7 +57,7 @@ class HeaderBarView: UIView {

let accountButton: UIButton = {
let button = makeHeaderBarButton(with: UIImage(named: "IconAccount"))
button.accessibilityIdentifier = "AccountButton"
button.accessibilityIdentifier = .accountButton
button.accessibilityLabel = NSLocalizedString(
"HEADER_BAR_ACCOUNT_BUTTON_ACCESSIBILITY_LABEL",
tableName: "HeaderBar",
Expand All @@ -72,7 +71,7 @@ class HeaderBarView: UIView {

let settingsButton: UIButton = {
let button = makeHeaderBarButton(with: UIImage(named: "IconSettings"))
button.accessibilityIdentifier = "SettingsButton"
button.accessibilityIdentifier = .settingsButton
button.accessibilityLabel = NSLocalizedString(
"HEADER_BAR_SETTINGS_BUTTON_ACCESSIBILITY_LABEL",
tableName: "HeaderBar",
Expand Down
1 change: 1 addition & 0 deletions ios/MullvadVPN/Coordinators/ChangeLogCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ final class ChangeLogCoordinator: Coordinator, Presentable {
comment: ""
),
style: .default,
accessibilityId: .alertOkButton,
handler: { [weak self] in
guard let self else { return }
didFinish?(self)
Expand Down
1 change: 0 additions & 1 deletion ios/MullvadVPN/Coordinators/WelcomeCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// Copyright © 2023 Mullvad VPN AB. All rights reserved.
//

import Foundation
import MullvadREST
import Routing
import StoreKit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AccountContentView: UIView {
let purchaseButton: InAppPurchaseButton = {
let button = InAppPurchaseButton()
button.translatesAutoresizingMaskIntoConstraints = false
button.accessibilityIdentifier = "PurchaseButton"
button.accessibilityIdentifier = .purchaseButton
return button
}()

Expand All @@ -31,7 +31,7 @@ class AccountContentView: UIView {
let redeemVoucherButton: AppButton = {
let button = AppButton(style: .success)
button.translatesAutoresizingMaskIntoConstraints = false
button.accessibilityIdentifier = "redeemVoucherButton"
button.accessibilityIdentifier = .redeemVoucherButton
button.setTitle(NSLocalizedString(
"REDEEM_VOUCHER_BUTTON_TITLE",
tableName: "Account",
Expand All @@ -44,7 +44,7 @@ class AccountContentView: UIView {
let logoutButton: AppButton = {
let button = AppButton(style: .danger)
button.translatesAutoresizingMaskIntoConstraints = false
button.accessibilityIdentifier = "LogoutButton"
button.accessibilityIdentifier = .logoutButton
button.setTitle(NSLocalizedString(
"LOGOUT_BUTTON_TITLE",
tableName: "Account",
Expand All @@ -57,7 +57,7 @@ class AccountContentView: UIView {
let deleteButton: AppButton = {
let button = AppButton(style: .danger)
button.translatesAutoresizingMaskIntoConstraints = false
button.accessibilityIdentifier = "DeleteButton"
button.accessibilityIdentifier = .deleteButton
button.setTitle(NSLocalizedString(
"DELETE_BUTTON_TITLE",
tableName: "Account",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// Copyright © 2023 Mullvad VPN AB. All rights reserved.
//

import Foundation
import UIKit

class AccountDeviceRow: UIView {
Expand Down Expand Up @@ -41,7 +40,7 @@ class AccountDeviceRow: UIView {

private let infoButton: UIButton = {
let button = IncreasedHitButton(type: .system)
button.accessibilityIdentifier = "InfoButton"
button.accessibilityIdentifier = .infoButton
button.tintColor = .white
button.setImage(UIImage(named: "IconInfo"), for: .normal)
return button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ class AccountDeletionContentView: UIView {
case failure(Error)
}

private enum Action: String {
case delete, cancel
}

private let scrollView: UIScrollView = {
let scrollView = UIScrollView()
return scrollView
Expand Down Expand Up @@ -103,7 +99,7 @@ class AccountDeletionContentView: UIView {

private let deleteButton: AppButton = {
let button = AppButton(style: .danger)
button.accessibilityIdentifier = Action.delete.rawValue
button.accessibilityIdentifier = .deleteButton
button.setTitle(NSLocalizedString(
"OK_BUTTON_TITLE",
tableName: "Account",
Expand All @@ -115,7 +111,7 @@ class AccountDeletionContentView: UIView {

private let cancelButton: AppButton = {
let button = AppButton(style: .default)
button.accessibilityIdentifier = Action.cancel.rawValue
button.accessibilityIdentifier = .cancelButton
button.setTitle(NSLocalizedString(
"CANCEL_BUTTON_TITLE",
tableName: "Account",
Expand Down Expand Up @@ -376,10 +372,10 @@ class AccountDeletionContentView: UIView {
}

@objc private func didPress(button: AppButton) {
switch Action(rawValue: button.accessibilityIdentifier ?? "") {
case .delete:
switch AccessibilityIdentifier(rawValue: button.accessibilityIdentifier ?? "") {
case .deleteButton:
delegate?.didTapDeleteButton(contentView: self, button: button)
case .cancel:
case .cancelButton:
delegate?.didTapCancelButton(contentView: self, button: button)
default: return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct AlertMetadata {
struct AlertAction {
let title: String
let style: AlertActionStyle
var accessibilityID: String?
var accessibilityId: AccessibilityIdentifier?
var handler: (() -> Void)?
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class AlertViewController: UIViewController {
addAction(
title: action.title,
style: action.style,
accessibilityId: action.accessibilityId,
handler: action.handler
)
}
Expand Down Expand Up @@ -251,10 +252,16 @@ class AlertViewController: UIViewController {
contentView.addArrangedSubview(iconView)
}

private func addAction(title: String, style: AlertActionStyle, handler: (() -> Void)? = nil) {
private func addAction(
title: String,
style: AlertActionStyle,
accessibilityId: AccessibilityIdentifier?,
handler: (() -> Void)? = nil
) {
let button = AppButton(style: style.buttonStyle)

button.setTitle(title, for: .normal)
button.accessibilityIdentifier = accessibilityId
button.addTarget(self, action: #selector(didTapButton), for: .touchUpInside)

buttonView.addArrangedSubview(button)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ protocol SetupAccountCompletedContentViewDelegate: AnyObject {
}

class SetupAccountCompletedContentView: UIView {
private enum Action: String {
case learnAboutPrivacy, startUsingTheApp
}

private let titleLabel: UILabel = {
let label = UILabel()
label.font = .preferredFont(forTextStyle: .largeTitle, weight: .bold)
Expand Down Expand Up @@ -57,7 +53,7 @@ class SetupAccountCompletedContentView: UIView {

private let privacyButton: AppButton = {
let button = AppButton(style: .success)
button.accessibilityIdentifier = Action.learnAboutPrivacy.rawValue
button.accessibilityIdentifier = .learnAboutPrivacyButton
let localizedString = NSLocalizedString(
"LEARN_ABOUT_PRIVACY_BUTTON",
tableName: "CreatedAccountConfirmation",
Expand All @@ -71,7 +67,7 @@ class SetupAccountCompletedContentView: UIView {

private let startButton: AppButton = {
let button = AppButton(style: .success)
button.accessibilityIdentifier = Action.startUsingTheApp.rawValue
button.accessibilityIdentifier = .startUsingTheAppButton
button.setTitle(NSLocalizedString(
"START_USING_THE_APP_BUTTON",
tableName: "CreatedAccountConfirmation",
Expand Down Expand Up @@ -142,10 +138,10 @@ class SetupAccountCompletedContentView: UIView {
}

@objc private func tapped(button: AppButton) {
switch button.accessibilityIdentifier {
case Action.learnAboutPrivacy.rawValue:
switch AccessibilityIdentifier(rawValue: button.accessibilityIdentifier ?? "") {
case .learnAboutPrivacyButton:
delegate?.didTapPrivacyButton(view: self, button: button)
case Action.startUsingTheApp.rawValue:
case .startUsingTheAppButton:
delegate?.didTapStartingAppButton(view: self, button: button)
default: return
}
Expand Down
Loading

0 comments on commit ce7f4f7

Please sign in to comment.