From 3617d07eda70953d0511b2de5ee4ede643bf27f9 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Tue, 7 Jun 2022 15:14:50 +0300 Subject: [PATCH] Prevent the Pin entry screen from being overlapped by other views --- Riot/Modules/Application/LegacyAppDelegate.m | 10 +++---- .../SetPinCoordinatorBridgePresenter.swift | 30 ++++++++++++------- changelog.d/pr-6249.bugfix | 1 + 3 files changed, 25 insertions(+), 16 deletions(-) create mode 100644 changelog.d/pr-6249.bugfix diff --git a/Riot/Modules/Application/LegacyAppDelegate.m b/Riot/Modules/Application/LegacyAppDelegate.m index 679da52481..e875d13381 100644 --- a/Riot/Modules/Application/LegacyAppDelegate.m +++ b/Riot/Modules/Application/LegacyAppDelegate.m @@ -563,7 +563,7 @@ - (void)applicationWillResignActive:(UIApplication *)application } self.setPinCoordinatorBridgePresenter = [[SetPinCoordinatorBridgePresenter alloc] initWithSession:mxSessionArray.firstObject viewMode:SetPinCoordinatorViewModeInactive]; self.setPinCoordinatorBridgePresenter.delegate = self; - [self.setPinCoordinatorBridgePresenter presentIn:self.window]; + [self.setPinCoordinatorBridgePresenter presentWithMainAppWindow:self.window]; } } @@ -663,12 +663,12 @@ - (void)configurePinCodeScreenFor:(UIApplication *)application { self.setPinCoordinatorBridgePresenter = [[SetPinCoordinatorBridgePresenter alloc] initWithSession:mxSessionArray.firstObject viewMode:SetPinCoordinatorViewModeUnlock]; self.setPinCoordinatorBridgePresenter.delegate = self; - [self.setPinCoordinatorBridgePresenter presentIn:self.window]; + [self.setPinCoordinatorBridgePresenter presentWithMainAppWindow:self.window]; } } else { - [self.setPinCoordinatorBridgePresenter dismiss]; + [self.setPinCoordinatorBridgePresenter dismissWithMainAppWindow:self.window]; self.setPinCoordinatorBridgePresenter = nil; [self afterAppUnlockedByPin:application]; } @@ -4611,7 +4611,7 @@ - (void)showMajorUpdate - (void)setPinCoordinatorBridgePresenterDelegateDidComplete:(SetPinCoordinatorBridgePresenter *)coordinatorBridgePresenter { - [coordinatorBridgePresenter dismiss]; + [coordinatorBridgePresenter dismissWithMainAppWindow:self.window]; self.setPinCoordinatorBridgePresenter = nil; [self afterAppUnlockedByPin:[UIApplication sharedApplication]]; } @@ -4625,7 +4625,7 @@ - (void)setPinCoordinatorBridgePresenterDelegateDidCompleteWithReset:(SetPinCoor } else { - [coordinatorBridgePresenter dismiss]; + [coordinatorBridgePresenter dismissWithMainAppWindow:self.window]; self.setPinCoordinatorBridgePresenter = nil; [self logoutWithConfirmation:NO completion:nil]; } diff --git a/Riot/Modules/SetPinCode/SetPinCoordinatorBridgePresenter.swift b/Riot/Modules/SetPinCode/SetPinCoordinatorBridgePresenter.swift index 99319c6b31..2351e5f619 100644 --- a/Riot/Modules/SetPinCode/SetPinCoordinatorBridgePresenter.swift +++ b/Riot/Modules/SetPinCode/SetPinCoordinatorBridgePresenter.swift @@ -17,6 +17,7 @@ */ import Foundation +import UIKit @objc enum SetPinCoordinatorViewMode: Int { case setPin @@ -49,6 +50,8 @@ final class SetPinCoordinatorBridgePresenter: NSObject { // MARK: Private + private var pinCoordinatorWindow: UIWindow? + private let session: MXSession? private var coordinator: SetPinCoordinator? var viewMode: SetPinCoordinatorViewMode { @@ -87,18 +90,23 @@ final class SetPinCoordinatorBridgePresenter: NSObject { self.coordinator = setPinCoordinator } - func present(in window: UIWindow) { + func presentWithMainAppWindow(_ window: UIWindow) { + let pinCoordinatorWindow = UIWindow(frame: window.bounds) + let setPinCoordinator = SetPinCoordinator(session: self.session, viewMode: self.viewMode, pinCodePreferences: .shared) setPinCoordinator.delegate = self guard let view = setPinCoordinator.toPresentable().view else { return } - window.addSubview(view) - view.leadingAnchor.constraint(equalTo: window.leadingAnchor, constant: 0).isActive = true - view.trailingAnchor.constraint(equalTo: window.trailingAnchor, constant: 0).isActive = true - view.topAnchor.constraint(equalTo: window.topAnchor, constant: 0).isActive = true - view.bottomAnchor.constraint(equalTo: window.bottomAnchor, constant: 0).isActive = true + pinCoordinatorWindow.addSubview(view) + view.leadingAnchor.constraint(equalTo: pinCoordinatorWindow.leadingAnchor, constant: 0).isActive = true + view.trailingAnchor.constraint(equalTo: pinCoordinatorWindow.trailingAnchor, constant: 0).isActive = true + view.topAnchor.constraint(equalTo: pinCoordinatorWindow.topAnchor, constant: 0).isActive = true + view.bottomAnchor.constraint(equalTo: pinCoordinatorWindow.bottomAnchor, constant: 0).isActive = true + + pinCoordinatorWindow.makeKeyAndVisible() setPinCoordinator.start() + self.pinCoordinatorWindow = pinCoordinatorWindow self.coordinator = setPinCoordinator } @@ -106,6 +114,7 @@ final class SetPinCoordinatorBridgePresenter: NSObject { guard let coordinator = self.coordinator else { return } + coordinator.toPresentable().dismiss(animated: animated) { self.coordinator = nil @@ -115,11 +124,10 @@ final class SetPinCoordinatorBridgePresenter: NSObject { } } - func dismiss() { - guard let coordinator = self.coordinator else { - return - } - coordinator.toPresentable().view.removeFromSuperview() + func dismissWithMainAppWindow(_ window: UIWindow) { + window.makeKeyAndVisible() + pinCoordinatorWindow = nil + coordinator = nil } } diff --git a/changelog.d/pr-6249.bugfix b/changelog.d/pr-6249.bugfix new file mode 100644 index 0000000000..400bbfcfb2 --- /dev/null +++ b/changelog.d/pr-6249.bugfix @@ -0,0 +1 @@ +Prevent the Pin entry screen from being overlapped by other views. \ No newline at end of file