Skip to content

Commit

Permalink
Merge branch 'IOS-962-AccessibilityIdentifier-refactor'
Browse files Browse the repository at this point in the history
  • Loading branch information
buggmagnet committed Dec 10, 2024
2 parents 3232f1b + bdf7473 commit 534866b
Show file tree
Hide file tree
Showing 69 changed files with 198 additions and 200 deletions.
20 changes: 10 additions & 10 deletions ios/MullvadVPN/Classes/AccessbilityIdentifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UIKit

public enum AccessibilityIdentifier: String {
public enum AccessibilityIdentifier: Equatable {
// Buttons
case addAccessMethodButton
case accessMethodAddButton
Expand Down Expand Up @@ -181,7 +181,7 @@ public enum AccessibilityIdentifier: String {
case wireGuardObfuscationOff
case wireGuardObfuscationUdpOverTcp
case wireGuardObfuscationShadowsocks
case wireGuardPort
case wireGuardPort(UInt16?)
case udpOverTcpObfuscationSettings

// Custom DNS
Expand Down Expand Up @@ -214,14 +214,14 @@ public enum AccessibilityIdentifier: String {
case unknown
}

extension AccessibilityIdentifier {
public var asString: String {
"\(self)"
}
}

extension UIAccessibilityIdentification {
var accessibilityIdentifier: AccessibilityIdentifier? {
get {
guard let accessibilityIdentifier else { return nil }
return AccessibilityIdentifier(rawValue: accessibilityIdentifier)
}
set {
accessibilityIdentifier = newValue?.rawValue
}
func setAccessibilityIdentifier(_ value: AccessibilityIdentifier?) {
accessibilityIdentifier = value.map(\.asString)
}
}
8 changes: 4 additions & 4 deletions ios/MullvadVPN/Containers/Root/HeaderBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class HeaderBarView: UIView {
label.font = UIFont.systemFont(ofSize: 14)
label.textColor = UIColor(white: 1.0, alpha: 0.8)
label.setContentHuggingPriority(.defaultHigh, for: .horizontal)
label.accessibilityIdentifier = .headerDeviceNameLabel
label.setAccessibilityIdentifier(.headerDeviceNameLabel)
return label
}()

Expand All @@ -58,7 +58,7 @@ class HeaderBarView: UIView {

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

let settingsButton: UIButton = {
let button = makeHeaderBarButton(with: UIImage(named: "IconSettings"))
button.accessibilityIdentifier = .settingsButton
button.setAccessibilityIdentifier(.settingsButton)
button.accessibilityLabel = NSLocalizedString(
"HEADER_BAR_SETTINGS_BUTTON_ACCESSIBILITY_LABEL",
tableName: "HeaderBar",
Expand Down Expand Up @@ -170,7 +170,7 @@ class HeaderBarView: UIView {
)

accessibilityContainerType = .semanticGroup
accessibilityIdentifier = .headerBarView
setAccessibilityIdentifier(.headerBarView)

let brandImageSize = brandNameImage?.size ?? .zero
let brandNameAspectRatio = brandImageSize.width / max(brandImageSize.height, 1)
Expand Down
2 changes: 1 addition & 1 deletion ios/MullvadVPN/Coordinators/ApplicationCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ final class ApplicationCoordinator: Coordinator, Presenting, RootContainerViewCo
)

let navigationController = CustomNavigationController()
navigationController.view.accessibilityIdentifier = .settingsContainerView
navigationController.view.setAccessibilityIdentifier(.settingsContainerView)

let configurationTester = ProxyConfigurationTester(transportProvider: configuredTransportProvider)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AddLocationsViewController: UIViewController {
tableView.separatorInset = .zero
tableView.rowHeight = 56
tableView.indicatorStyle = .white
tableView.accessibilityIdentifier = .editCustomListEditLocationsTableView
tableView.setAccessibilityIdentifier(.editCustomListEditLocationsTableView)
return tableView
}()

Expand All @@ -46,7 +46,7 @@ class AddLocationsViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
view.accessibilityIdentifier = .editCustomListEditLocationsView
view.setAccessibilityIdentifier(.editCustomListEditLocationsView)
tableView.backgroundColor = view.backgroundColor
view.backgroundColor = .secondaryColor
addConstraints()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct CustomListCellConfiguration {
contentConfiguration.maxLength = NameInputFormatter.maxLength
contentConfiguration.editingEvents.onChange = subject.bindTextAction(to: \.name)

cell.accessibilityIdentifier = AccessibilityIdentifier.customListEditNameFieldCell
cell.setAccessibilityIdentifier(.customListEditNameFieldCell)
cell.contentConfiguration = contentConfiguration
}

Expand All @@ -88,7 +88,7 @@ struct CustomListCellConfiguration {

contentConfiguration.text = itemIdentifier.text
cell.contentConfiguration = contentConfiguration
cell.accessibilityIdentifier = AccessibilityIdentifier.customListEditAddOrEditLocationCell
cell.setAccessibilityIdentifier(.customListEditAddOrEditLocationCell)

if let cell = cell as? CustomCellDisclosureHandling {
cell.disclosureType = .chevron
Expand All @@ -104,7 +104,7 @@ struct CustomListCellConfiguration {
onDelete?()
}

cell.accessibilityIdentifier = AccessibilityIdentifier.customListEditDeleteListCell
cell.setAccessibilityIdentifier(.customListEditDeleteListCell)
cell.contentConfiguration = contentConfiguration
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class CustomListViewController: UIViewController {
}
)
barButtonItem.style = .done
barButtonItem.accessibilityIdentifier = AccessibilityIdentifier.saveCreateCustomListButton
barButtonItem.setAccessibilityIdentifier(.saveCreateCustomListButton)

return barButtonItem
}()
Expand Down Expand Up @@ -87,7 +87,7 @@ class CustomListViewController: UIViewController {
navigationItem.rightBarButtonItem = saveBarButton
view.directionalLayoutMargins = UIMetrics.contentLayoutMargins
view.backgroundColor = .secondaryColor
view.accessibilityIdentifier = .newCustomListView
view.setAccessibilityIdentifier(.newCustomListView)
isModalInPresentation = true

addSubviews()
Expand All @@ -104,7 +104,7 @@ class CustomListViewController: UIViewController {
tableView.delegate = dataSourceConfiguration
tableView.backgroundColor = .secondaryColor
tableView.registerReusableViews(from: CustomListItemIdentifier.CellIdentifier.self)
tableView.accessibilityIdentifier = AccessibilityIdentifier.customListEditTableView
tableView.setAccessibilityIdentifier(.customListEditTableView)
}

private func configureDataSource() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ListCustomListViewController: UIViewController {
super.viewDidLoad()

view.backgroundColor = .secondaryColor
view.accessibilityIdentifier = .listCustomListsView
view.setAccessibilityIdentifier(.listCustomListsView)

addSubviews()
configureNavigationItem()
Expand Down Expand Up @@ -89,7 +89,7 @@ class ListCustomListViewController: UIViewController {
tableView.separatorStyle = .singleLine
tableView.rowHeight = UIMetrics.SettingsCell.customListsCellHeight
tableView.registerReusableViews(from: CellReuseIdentifier.self)
tableView.accessibilityIdentifier = .listCustomListsTableView
tableView.setAccessibilityIdentifier(.listCustomListsTableView)
}

private func configureNavigationItem() {
Expand All @@ -107,7 +107,7 @@ class ListCustomListViewController: UIViewController {
})
)

navigationItem.rightBarButtonItem?.accessibilityIdentifier = .listCustomListDoneButton
navigationItem.rightBarButtonItem?.setAccessibilityIdentifier(.listCustomListDoneButton)
}

private func configureDataSource() {
Expand Down
4 changes: 2 additions & 2 deletions ios/MullvadVPN/Coordinators/LocationCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ extension LocationCoordinator: LocationViewControllerWrapperDelegate {
self?.showAddCustomList(nodes: nodes)
}
)
addCustomListAction.accessibilityIdentifier = AccessibilityIdentifier.addNewCustomListButton
addCustomListAction.setAccessibilityIdentifier(.addNewCustomListButton)
actionSheet.addAction(addCustomListAction)

let editAction = UIAlertAction(
Expand All @@ -297,7 +297,7 @@ extension LocationCoordinator: LocationViewControllerWrapperDelegate {
}
)
editAction.isEnabled = !customListRepository.fetchAll().isEmpty
editAction.accessibilityIdentifier = AccessibilityIdentifier.editCustomListButton
editAction.setAccessibilityIdentifier(.editCustomListButton)
actionSheet.addAction(editAction)

actionSheet.addAction(UIAlertAction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class SwitchCellContentView: UIView, UIContentView, UITextFieldDelegate {
private func configureSwitch() {
switchContainer.control.isOn = actualConfiguration.isOn
switchContainer.transform = CGAffineTransform(scaleX: 0.85, y: 0.85)
switchContainer.accessibilityIdentifier = actualConfiguration.accessibilityIdentifier
switchContainer.setAccessibilityIdentifier(actualConfiguration.accessibilityIdentifier)
}

private func addSubviews() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct SocksSectionHandler {
contentConfiguration.inputText = subject.value.socks.server
contentConfiguration.textFieldProperties = .withSmartFeaturesDisabled()
contentConfiguration.editingEvents.onChange = subject.bindTextAction(to: \.socks.server)
cell.accessibilityIdentifier = .socks5ServerCell
cell.setAccessibilityIdentifier(.socks5ServerCell)
cell.contentConfiguration = contentConfiguration
}

Expand All @@ -51,7 +51,7 @@ struct SocksSectionHandler {
contentConfiguration.editingEvents.onChange = subject.bindTextAction(to: \.socks.port)
contentConfiguration.textFieldProperties = .withSmartFeaturesDisabled()
contentConfiguration.textFieldProperties.keyboardType = .numberPad
cell.accessibilityIdentifier = .socks5PortCell
cell.setAccessibilityIdentifier(.socks5PortCell)
cell.contentConfiguration = contentConfiguration
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class EditAccessMethodViewController: UIViewController {

view.backgroundColor = .secondaryColor

tableView.accessibilityIdentifier = .editAccessMethodView
tableView.setAccessibilityIdentifier(.editAccessMethodView)
tableView.backgroundColor = .secondaryColor
tableView.delegate = self

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class MethodSettingsCellConfiguration {
contentConfiguration.maxLength = NameInputFormatter.maxLength
contentConfiguration.editingEvents.onChange = subject.bindTextAction(to: \.name)

cell.accessibilityIdentifier = .accessMethodNameTextField
cell.setAccessibilityIdentifier(.accessMethodNameTextField)
cell.setDisabled(isTesting)
cell.contentConfiguration = contentConfiguration
}
Expand Down Expand Up @@ -156,7 +156,7 @@ class MethodSettingsCellConfiguration {
cell.disclosureType = .chevron
}

cell.accessibilityIdentifier = .accessMethodProtocolSelectionCell
cell.setAccessibilityIdentifier(.accessMethodProtocolSelectionCell)
cell.setDisabled(isTesting)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ class MethodSettingsViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()

view.accessibilityIdentifier = .addAccessMethodTableView
view.setAccessibilityIdentifier(.addAccessMethodTableView)
view.directionalLayoutMargins = UIMetrics.contentLayoutMargins
view.backgroundColor = .secondaryColor

navigationItem.rightBarButtonItem = saveBarButton
navigationItem.rightBarButtonItem?.accessibilityIdentifier = .accessMethodAddButton
navigationItem.rightBarButtonItem?.setAccessibilityIdentifier(.accessMethodAddButton)
navigationItem.rightBarButtonItem?.isAccessibilityElement = true
isModalInPresentation = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ class MethodTestingStatusCellContentView: UIView, UIContentView {
// Set accessibility identifier for the text label based on the status it is indicating
switch actualConfiguration.status {
case .reachable:
textLabel.accessibilityIdentifier = .addAccessMethodTestStatusReachableLabel
textLabel.setAccessibilityIdentifier(.addAccessMethodTestStatusReachableLabel)
case .unreachable:
textLabel.accessibilityIdentifier = .addAccessMethodTestStatusUnreachableLabel
textLabel.setAccessibilityIdentifier(.addAccessMethodTestStatusUnreachableLabel)
case .testing:
textLabel.accessibilityIdentifier = .addAccessMethodTestStatusTestingLabel
textLabel.setAccessibilityIdentifier(.addAccessMethodTestStatusTestingLabel)
}

// Text label is always the last one, so only add it into the stack if it's not there yet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ListAccessMethodViewController: UIViewController, UITableViewDelegate {

tableView.registerReusableViews(from: CellReuseIdentifier.self)

view.accessibilityIdentifier = .apiAccessView
view.setAccessibilityIdentifier(.apiAccessView)

let headerView = createHeaderView()
view.addConstrainedSubviews([headerView, tableView]) {
Expand Down Expand Up @@ -115,7 +115,7 @@ class ListAccessMethodViewController: UIViewController, UITableViewDelegate {
button.addAction(UIAction { [weak self] _ in
self?.sendAddNew()
}, for: .touchUpInside)
button.accessibilityIdentifier = .addAccessMethodButton
button.setAccessibilityIdentifier(.addAccessMethodButton)

let fontSize = button.titleLabel?.font.pointSize ?? 0
button.titleLabel?.font = UIFont.systemFont(ofSize: fontSize, weight: .regular)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct AccessMethodProtocolPicker {

let dataSource = AccessMethodProtocolPickerDataSource()
let controller = ListItemPickerViewController(dataSource: dataSource, selectedItemID: currentValue)
controller.view.accessibilityIdentifier = .accessMethodProtocolPickerView
controller.view.setAccessibilityIdentifier(.accessMethodProtocolPickerView)

controller.navigationItem.title = NSLocalizedString(
"SELECT_PROTOCOL_NAV_TITLE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ struct SettingsViewControllerFactory {
value: "Multihop",
comment: ""
)
host.view.accessibilityIdentifier = AccessibilityIdentifier.multihopView.rawValue
host.view.setAccessibilityIdentifier(.multihopView)

return .viewController(host)
}
Expand All @@ -129,7 +129,7 @@ struct SettingsViewControllerFactory {
value: "DAITA",
comment: ""
)
host.view.accessibilityIdentifier = AccessibilityIdentifier.daitaView.rawValue
host.view.setAccessibilityIdentifier(.daitaView)

return .viewController(host)
}
Expand Down
10 changes: 5 additions & 5 deletions ios/MullvadVPN/View controllers/Account/AccountContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import UIKit
class AccountContentView: UIView {
let purchaseButton: InAppPurchaseButton = {
let button = InAppPurchaseButton()
button.accessibilityIdentifier = .purchaseButton
button.setAccessibilityIdentifier(.purchaseButton)
return button
}()

let redeemVoucherButton: AppButton = {
let button = AppButton(style: .success)
button.accessibilityIdentifier = .redeemVoucherButton
button.setAccessibilityIdentifier(.redeemVoucherButton)
button.setTitle(NSLocalizedString(
"REDEEM_VOUCHER_BUTTON_TITLE",
tableName: "Account",
Expand All @@ -29,7 +29,7 @@ class AccountContentView: UIView {

let logoutButton: AppButton = {
let button = AppButton(style: .danger)
button.accessibilityIdentifier = .logoutButton
button.setAccessibilityIdentifier(.logoutButton)
button.setTitle(NSLocalizedString(
"LOGOUT_BUTTON_TITLE",
tableName: "Account",
Expand All @@ -41,7 +41,7 @@ class AccountContentView: UIView {

let deleteButton: AppButton = {
let button = AppButton(style: .danger)
button.accessibilityIdentifier = .deleteButton
button.setAccessibilityIdentifier(.deleteButton)
button.setTitle(NSLocalizedString(
"DELETE_BUTTON_TITLE",
tableName: "Account",
Expand Down Expand Up @@ -101,7 +101,7 @@ class AccountContentView: UIView {
super.init(frame: frame)

directionalLayoutMargins = UIMetrics.contentLayoutMargins
accessibilityIdentifier = .accountView
setAccessibilityIdentifier(.accountView)

addConstrainedSubviews([contentStackView, buttonStackView]) {
contentStackView.pinEdgesToSuperviewMargins(.all().excluding(.bottom))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AccountDeviceRow: UIView {
didSet {
deviceLabel.text = deviceName?.capitalized ?? ""
accessibilityValue = deviceName
accessibilityIdentifier = .accountPageDeviceNameLabel
setAccessibilityIdentifier(.accountPageDeviceNameLabel)
}
}

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

private let infoButton: UIButton = {
let button = IncreasedHitButton(type: .system)
button.accessibilityIdentifier = .infoButton
button.setAccessibilityIdentifier(.infoButton)
button.tintColor = .white
button.setImage(UIImage(named: "IconInfo"), for: .normal)
return button
Expand Down
Loading

0 comments on commit 534866b

Please sign in to comment.