diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj index 1345a4e32d46..7aab178ca5fe 100644 --- a/ios/MullvadVPN.xcodeproj/project.pbxproj +++ b/ios/MullvadVPN.xcodeproj/project.pbxproj @@ -495,6 +495,7 @@ F09A297D2A9F8A9B00EA3B6F /* RedeemVoucherContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F09A297A2A9F8A9B00EA3B6F /* RedeemVoucherContentView.swift */; }; F09A29822A9F8AD200EA3B6F /* RedeemVoucherInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = F09A297F2A9F8AD200EA3B6F /* RedeemVoucherInteractor.swift */; }; F0C2AEFD2A0BB5CC00986207 /* NotificationProviderIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0C2AEFC2A0BB5CC00986207 /* NotificationProviderIdentifier.swift */; }; + F0C6A8432AB08E54000777A8 /* RedeemVoucherViewConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0C6A8422AB08E54000777A8 /* RedeemVoucherViewConfiguration.swift */; }; F0C6FA812A66E23300F521F0 /* DeleteAccountOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0C6FA802A66E23300F521F0 /* DeleteAccountOperation.swift */; }; F0C6FA852A6A733700F521F0 /* InAppPurchaseInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0C6FA842A6A733700F521F0 /* InAppPurchaseInteractor.swift */; }; F0DA87472A9CB9A2006044F1 /* AccountExpiryRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0DA87462A9CB9A2006044F1 /* AccountExpiryRow.swift */; }; @@ -1392,6 +1393,7 @@ F09A297A2A9F8A9B00EA3B6F /* RedeemVoucherContentView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RedeemVoucherContentView.swift; sourceTree = ""; }; F09A297F2A9F8AD200EA3B6F /* RedeemVoucherInteractor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RedeemVoucherInteractor.swift; sourceTree = ""; }; F0C2AEFC2A0BB5CC00986207 /* NotificationProviderIdentifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationProviderIdentifier.swift; sourceTree = ""; }; + F0C6A8422AB08E54000777A8 /* RedeemVoucherViewConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RedeemVoucherViewConfiguration.swift; sourceTree = ""; }; F0C6FA802A66E23300F521F0 /* DeleteAccountOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteAccountOperation.swift; sourceTree = ""; }; F0C6FA822A6A729500F521F0 /* InAppPurchaseCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InAppPurchaseCoordinator.swift; sourceTree = ""; }; F0C6FA842A6A733700F521F0 /* InAppPurchaseInteractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InAppPurchaseInteractor.swift; sourceTree = ""; }; @@ -2623,6 +2625,7 @@ F09A29782A9F8A9B00EA3B6F /* LogoutDialogueView.swift */, F09A297A2A9F8A9B00EA3B6F /* RedeemVoucherContentView.swift */, F09A297F2A9F8AD200EA3B6F /* RedeemVoucherInteractor.swift */, + F0C6A8422AB08E54000777A8 /* RedeemVoucherViewConfiguration.swift */, F028A5692A34D4E700C0CAA3 /* RedeemVoucherViewController.swift */, F09A29792A9F8A9B00EA3B6F /* VoucherTextField.swift */, ); @@ -3931,6 +3934,7 @@ F0E8CC0A2A4EE127007ED3B4 /* SetupAccountCompletedContentView.swift in Sources */, 581DA2752A1E283E0046ED47 /* WgKeyRotation.swift in Sources */, 7A83C4022A57FAA800DFB83A /* SettingsDNSInfoCell.swift in Sources */, + F0C6A8432AB08E54000777A8 /* RedeemVoucherViewConfiguration.swift in Sources */, 06410DFE292CE18F00AFC18C /* KeychainSettingsStore.swift in Sources */, 58FB865526E8BF3100F188BC /* StorePaymentManagerError.swift in Sources */, 58FD5BF42428C67600112C88 /* InAppPurchaseButton.swift in Sources */, diff --git a/ios/MullvadVPN/Coordinators/CreateAccountVoucherCoordinator.swift b/ios/MullvadVPN/Coordinators/CreateAccountVoucherCoordinator.swift index 2234af0b0338..1407c61808e3 100644 --- a/ios/MullvadVPN/Coordinators/CreateAccountVoucherCoordinator.swift +++ b/ios/MullvadVPN/Coordinators/CreateAccountVoucherCoordinator.swift @@ -25,7 +25,11 @@ public class CreateAccountVoucherCoordinator: Coordinator { ) { self.navigationController = navigationController self.interactor = interactor - viewController = RedeemVoucherViewController(interactor: interactor) + + viewController = RedeemVoucherViewController( + configuration: RedeemVoucherViewConfiguration(adjustViewWhenKeyboardAppears: true), + interactor: interactor + ) } func start() { diff --git a/ios/MullvadVPN/Coordinators/ProfileVoucherCoordinator.swift b/ios/MullvadVPN/Coordinators/ProfileVoucherCoordinator.swift index 02aed1dea22e..8e166985b900 100644 --- a/ios/MullvadVPN/Coordinators/ProfileVoucherCoordinator.swift +++ b/ios/MullvadVPN/Coordinators/ProfileVoucherCoordinator.swift @@ -23,7 +23,10 @@ final class ProfileVoucherCoordinator: Coordinator, Presentable { interactor: RedeemVoucherInteractor ) { self.navigationController = navigationController - viewController = RedeemVoucherViewController(interactor: interactor) + viewController = RedeemVoucherViewController( + configuration: RedeemVoucherViewConfiguration(adjustViewWhenKeyboardAppears: false), + interactor: interactor + ) } var presentedViewController: UIViewController { diff --git a/ios/MullvadVPN/View controllers/AccountDeletion/AccountDeletionContentView.swift b/ios/MullvadVPN/View controllers/AccountDeletion/AccountDeletionContentView.swift index e3fce9f69b31..05ef64925aa2 100644 --- a/ios/MullvadVPN/View controllers/AccountDeletion/AccountDeletionContentView.swift +++ b/ios/MullvadVPN/View controllers/AccountDeletion/AccountDeletionContentView.swift @@ -359,7 +359,7 @@ class AccountDeletionContentView: UIView { targetView: self, handler: { [weak self] _, offset in guard let self else { return } - self.bottomsOfButtonsConstraint?.constant = self.accountTextField.isFirstResponder ? -offset : 0 + self.bottomsOfButtonsConstraint?.constant = isEditing ? -offset : 0 self.layoutIfNeeded() self.scrollView.flashScrollIndicators() } diff --git a/ios/MullvadVPN/View controllers/RedeemVoucher/RedeemVoucherContentView.swift b/ios/MullvadVPN/View controllers/RedeemVoucher/RedeemVoucherContentView.swift index 650ced232ba9..f5061d570d26 100644 --- a/ios/MullvadVPN/View controllers/RedeemVoucher/RedeemVoucherContentView.swift +++ b/ios/MullvadVPN/View controllers/RedeemVoucher/RedeemVoucherContentView.swift @@ -197,6 +197,7 @@ final class RedeemVoucherContentView: UIView { private var keyboardResponder: AutomaticKeyboardResponder? private var bottomsOfButtonsConstraint: NSLayoutConstraint? + private let configuration: RedeemVoucherViewConfiguration // MARK: - public @@ -230,12 +231,14 @@ final class RedeemVoucherContentView: UIView { } } - init() { + init(configuration: RedeemVoucherViewConfiguration) { + self.configuration = configuration super.init(frame: .zero) commonInit() } required init?(coder: NSCoder) { + self.configuration = RedeemVoucherViewConfiguration(adjustViewWhenKeyboardAppears: true) super.init(coder: coder) commonInit() } @@ -245,7 +248,7 @@ final class RedeemVoucherContentView: UIView { configureUI() addButtonHandlers() updateUI() - addKeyboardResponder() + addKeyboardResponderIfNeeded() addObservers() } @@ -331,13 +334,13 @@ final class RedeemVoucherContentView: UIView { updateUI() } - private func addKeyboardResponder() { + private func addKeyboardResponderIfNeeded() { + guard configuration.adjustViewWhenKeyboardAppears else { return } keyboardResponder = AutomaticKeyboardResponder( targetView: self, handler: { [weak self] _, offset in guard let self else { return } - guard self.textField.isFirstResponder else { return } - self.bottomsOfButtonsConstraint?.constant = -offset + self.bottomsOfButtonsConstraint?.constant = isEditing ? -offset : 0 self.layoutIfNeeded() } ) diff --git a/ios/MullvadVPN/View controllers/RedeemVoucher/RedeemVoucherViewConfiguration.swift b/ios/MullvadVPN/View controllers/RedeemVoucher/RedeemVoucherViewConfiguration.swift new file mode 100644 index 000000000000..32052230da23 --- /dev/null +++ b/ios/MullvadVPN/View controllers/RedeemVoucher/RedeemVoucherViewConfiguration.swift @@ -0,0 +1,12 @@ +// +// RedeemVoucherViewConfiguration.swift +// MullvadVPN +// +// Created by Mojgan on 2023-09-12. +// Copyright © 2023 Mullvad VPN AB. All rights reserved. +// + +import Foundation +struct RedeemVoucherViewConfiguration { + let adjustViewWhenKeyboardAppears: Bool +} diff --git a/ios/MullvadVPN/View controllers/RedeemVoucher/RedeemVoucherViewController.swift b/ios/MullvadVPN/View controllers/RedeemVoucher/RedeemVoucherViewController.swift index f7921f2c6e4b..9195e5c5d4e1 100644 --- a/ios/MullvadVPN/View controllers/RedeemVoucher/RedeemVoucherViewController.swift +++ b/ios/MullvadVPN/View controllers/RedeemVoucher/RedeemVoucherViewController.swift @@ -19,12 +19,16 @@ protocol RedeemVoucherViewControllerDelegate: AnyObject { } class RedeemVoucherViewController: UIViewController, UINavigationControllerDelegate, RootContainment { - private let contentView = RedeemVoucherContentView() + private let contentView: RedeemVoucherContentView private var interactor: RedeemVoucherInteractor weak var delegate: RedeemVoucherViewControllerDelegate? - init(interactor: RedeemVoucherInteractor) { + init( + configuration: RedeemVoucherViewConfiguration, + interactor: RedeemVoucherInteractor + ) { + self.contentView = RedeemVoucherContentView(configuration: configuration) self.interactor = interactor super.init(nibName: nil, bundle: nil) }