From bc30437ab0535611ca4ab52df3addbb4d3539574 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. --- Riot/Modules/Application/LegacyAppDelegate.m | 10 ++++---- .../SetPinCoordinatorBridgePresenter.swift | 25 +++++++++++++------ 2 files changed, 23 insertions(+), 12 deletions(-) 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..19ad2665c4 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 } @@ -115,11 +123,14 @@ final class SetPinCoordinatorBridgePresenter: NSObject { } } - func dismiss() { + func dismissWithMainAppWindow(_ window: UIWindow) { guard let coordinator = self.coordinator else { return } coordinator.toPresentable().view.removeFromSuperview() + + window.makeKeyAndVisible() + pinCoordinatorWindow = nil } }