summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2023-08-03 12:24:34 +0200
committerAndrej Mihajlov <and@mullvad.net>2023-08-03 12:24:34 +0200
commit6ecd9e89262bd34632c72cbb9819576e1c9d0d02 (patch)
tree08b9245d659507b902124f1bb258d2ef59647125
parent81e35b29a29a1cf9ffc6c79c0f9a58b9092b2882 (diff)
downloadmullvadvpn-6ecd9e89262bd34632c72cbb9819576e1c9d0d02.tar.xz
mullvadvpn-6ecd9e89262bd34632c72cbb9819576e1c9d0d02.zip
Use UIAction based handlers for bar items
-rw-r--r--ios/MullvadVPN.xcodeproj/project.pbxproj4
-rw-r--r--ios/MullvadVPN/Extensions/UIBarButtonItem+Blocks.swift43
-rw-r--r--ios/MullvadVPN/View controllers/ProblemReport/ProblemReportReviewViewController.swift18
-rw-r--r--ios/MullvadVPN/View controllers/SelectLocation/SelectLocationViewController.swift9
-rw-r--r--ios/MullvadVPN/View controllers/Settings/SettingsViewController.swift11
5 files changed, 25 insertions, 60 deletions
diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj
index 5d7179f319..59d592d214 100644
--- a/ios/MullvadVPN.xcodeproj/project.pbxproj
+++ b/ios/MullvadVPN.xcodeproj/project.pbxproj
@@ -123,7 +123,6 @@
58607A4D2947287800BC467D /* AccountExpiryInAppNotificationProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58607A4C2947287800BC467D /* AccountExpiryInAppNotificationProvider.swift */; };
586168692976F6BD00EF8598 /* DisplayError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 586168682976F6BD00EF8598 /* DisplayError.swift */; };
5862805422428EF100F5A6E1 /* TranslucentButtonBlurView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5862805322428EF100F5A6E1 /* TranslucentButtonBlurView.swift */; };
- 5864211F29F04CED00822139 /* UIBarButtonItem+Blocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5864211E29F04CED00822139 /* UIBarButtonItem+Blocks.swift */; };
5864859929A0D028006C5743 /* FormsheetPresentationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5864859829A0D028006C5743 /* FormsheetPresentationController.swift */; };
5864859B29A0EAF2006C5743 /* SecondaryContextPresentationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5864859A29A0EAF2006C5743 /* SecondaryContextPresentationController.swift */; };
5864AF0729C78843005B0CD9 /* SettingsCellFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5864AF0029C7879B005B0CD9 /* SettingsCellFactory.swift */; };
@@ -960,7 +959,6 @@
58607A4C2947287800BC467D /* AccountExpiryInAppNotificationProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountExpiryInAppNotificationProvider.swift; sourceTree = "<group>"; };
586168682976F6BD00EF8598 /* DisplayError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayError.swift; sourceTree = "<group>"; };
5862805322428EF100F5A6E1 /* TranslucentButtonBlurView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TranslucentButtonBlurView.swift; sourceTree = "<group>"; };
- 5864211E29F04CED00822139 /* UIBarButtonItem+Blocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIBarButtonItem+Blocks.swift"; sourceTree = "<group>"; };
5864859829A0D028006C5743 /* FormsheetPresentationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormsheetPresentationController.swift; sourceTree = "<group>"; };
5864859A29A0EAF2006C5743 /* SecondaryContextPresentationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecondaryContextPresentationController.swift; sourceTree = "<group>"; };
5864AF0029C7879B005B0CD9 /* SettingsCellFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsCellFactory.swift; sourceTree = "<group>"; };
@@ -1739,7 +1737,6 @@
E158B35F285381C60002F069 /* String+AccountFormatting.swift */,
7A09C98029D99215000C2CAC /* String+FuzzyMatch.swift */,
5807E2BF2432038B00F5FF30 /* String+Split.swift */,
- 5864211E29F04CED00822139 /* UIBarButtonItem+Blocks.swift */,
5891BF5025E66B1E006D6FB0 /* UIBarButtonItem+KeyboardNavigation.swift */,
587CBFE222807F530028DED3 /* UIColor+Helpers.swift */,
7ABE318C2A1CDD4500DF4963 /* UIFont+Weight.swift */,
@@ -3198,7 +3195,6 @@
5867771429097BCD006F721F /* PaymentState.swift in Sources */,
F0C2AEFD2A0BB5CC00986207 /* NotificationProviderIdentifier.swift in Sources */,
587D96742886D87C00CD8F1C /* DeviceManagementContentView.swift in Sources */,
- 5864211F29F04CED00822139 /* UIBarButtonItem+Blocks.swift in Sources */,
58C3F4FB296C3AD500D72515 /* SettingsCoordinator.swift in Sources */,
5846227126E229F20035F7C2 /* StoreSubscription.swift in Sources */,
58421030282D8A3C00F24E46 /* UpdateAccountDataOperation.swift in Sources */,
diff --git a/ios/MullvadVPN/Extensions/UIBarButtonItem+Blocks.swift b/ios/MullvadVPN/Extensions/UIBarButtonItem+Blocks.swift
deleted file mode 100644
index 1d38a4c336..0000000000
--- a/ios/MullvadVPN/Extensions/UIBarButtonItem+Blocks.swift
+++ /dev/null
@@ -1,43 +0,0 @@
-//
-// UIBarButtonItem+Blocks.swift
-// MullvadVPN
-//
-// Created by pronebird on 19/04/2023.
-// Copyright © 2023 Mullvad VPN AB. All rights reserved.
-//
-
-import UIKit
-
-private var actionHandlerAssociatedKey = 0
-
-extension UIBarButtonItem {
- typealias ActionHandler = () -> Void
-
- /**
- Block handler assigned to bar button item.
- */
- var actionHandler: ActionHandler? {
- get {
- objc_getAssociatedObject(self, &actionHandlerAssociatedKey) as? ActionHandler
- }
- set {
- objc_setAssociatedObject(self, &actionHandlerAssociatedKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
-
- target = newValue == nil ? nil : self
- action = newValue == nil ? nil : #selector(handleAction)
- }
- }
-
- /**
- Initialize bar button item with block handler.
- */
- convenience init(systemItem: UIBarButtonItem.SystemItem, actionHandler: @escaping ActionHandler) {
- self.init(barButtonSystemItem: systemItem, target: nil, action: nil)
-
- self.actionHandler = actionHandler
- }
-
- @objc private func handleAction() {
- actionHandler?()
- }
-}
diff --git a/ios/MullvadVPN/View controllers/ProblemReport/ProblemReportReviewViewController.swift b/ios/MullvadVPN/View controllers/ProblemReport/ProblemReportReviewViewController.swift
index f796259d21..e3669aa3e0 100644
--- a/ios/MullvadVPN/View controllers/ProblemReport/ProblemReportReviewViewController.swift
+++ b/ios/MullvadVPN/View controllers/ProblemReport/ProblemReportReviewViewController.swift
@@ -31,14 +31,20 @@ class ProblemReportReviewViewController: UIViewController {
comment: ""
)
- navigationItem.rightBarButtonItem = UIBarButtonItem(systemItem: .done, actionHandler: { [weak self] in
- self?.dismiss(animated: true)
- })
+ navigationItem.rightBarButtonItem = UIBarButtonItem(
+ systemItem: .done,
+ primaryAction: UIAction(handler: { [weak self] _ in
+ self?.dismiss(animated: true)
+ })
+ )
#if DEBUG
- navigationItem.leftBarButtonItem = UIBarButtonItem(systemItem: .action, actionHandler: { [weak self] in
- self?.share()
- })
+ navigationItem.leftBarButtonItem = UIBarButtonItem(
+ systemItem: .action,
+ primaryAction: UIAction(handler: { [weak self] _ in
+ self?.share()
+ })
+ )
#endif
textView.translatesAutoresizingMaskIntoConstraints = false
diff --git a/ios/MullvadVPN/View controllers/SelectLocation/SelectLocationViewController.swift b/ios/MullvadVPN/View controllers/SelectLocation/SelectLocationViewController.swift
index 86163c96cd..e2f00c37ee 100644
--- a/ios/MullvadVPN/View controllers/SelectLocation/SelectLocationViewController.swift
+++ b/ios/MullvadVPN/View controllers/SelectLocation/SelectLocationViewController.swift
@@ -38,9 +38,12 @@ final class SelectLocationViewController: UIViewController {
value: "Select location",
comment: ""
)
- navigationItem.rightBarButtonItem = UIBarButtonItem(systemItem: .done, actionHandler: { [weak self] in
- self?.didFinish?()
- })
+ navigationItem.rightBarButtonItem = UIBarButtonItem(
+ systemItem: .done,
+ primaryAction: UIAction(handler: { [weak self] _ in
+ self?.didFinish?()
+ })
+ )
setupDataSource()
setupTableView()
diff --git a/ios/MullvadVPN/View controllers/Settings/SettingsViewController.swift b/ios/MullvadVPN/View controllers/Settings/SettingsViewController.swift
index 72369c16d4..0fa4479543 100644
--- a/ios/MullvadVPN/View controllers/Settings/SettingsViewController.swift
+++ b/ios/MullvadVPN/View controllers/Settings/SettingsViewController.swift
@@ -44,11 +44,14 @@ class SettingsViewController: UITableViewController, SettingsDataSourceDelegate
value: "Settings",
comment: ""
)
- navigationItem.rightBarButtonItem = UIBarButtonItem(systemItem: .done, actionHandler: { [weak self] in
- guard let self else { return }
+ navigationItem.rightBarButtonItem = UIBarButtonItem(
+ systemItem: .done,
+ primaryAction: UIAction(handler: { [weak self] _ in
+ guard let self else { return }
- delegate?.settingsViewControllerDidFinish(self)
- })
+ delegate?.settingsViewControllerDidFinish(self)
+ })
+ )
tableView.backgroundColor = .secondaryColor
tableView.separatorColor = .secondaryColor