From a5804df6a3bf02f291991b2037211f55f82bc1f2 Mon Sep 17 00:00:00 2001 From: Federico Maccaroni Date: Wed, 29 Nov 2023 18:42:39 -0300 Subject: [PATCH] PM-3350 iOS extensions TapGestureRecognizer try Window workaround --- src/App/App.csproj | 2 + src/Core/Pages/Accounts/HomePage.xaml.cs | 17 +++- src/Core/Services/EnvironmentService.cs | 2 +- .../CredentialProviderViewController.cs | 94 +++++++++++++------ ...edentialProviderViewController.designer.cs | 46 +++++---- src/iOS.Autofill/MainInterface.storyboard | 60 +++++++----- src/iOS.Core/Handlers/CustomWindowHandler.cs | 24 +++++ src/iOS.Core/Utilities/iOSCoreHelpers.cs | 7 +- 8 files changed, 174 insertions(+), 78 deletions(-) create mode 100644 src/iOS.Core/Handlers/CustomWindowHandler.cs diff --git a/src/App/App.csproj b/src/App/App.csproj index 80b73a531..5b1365918 100644 --- a/src/App/App.csproj +++ b/src/App/App.csproj @@ -29,6 +29,8 @@ 11.0 21.0 + + true $(DefineConstants);$(CustomConstants) diff --git a/src/Core/Pages/Accounts/HomePage.xaml.cs b/src/Core/Pages/Accounts/HomePage.xaml.cs index 61ddf4950..906dd8cd4 100644 --- a/src/Core/Pages/Accounts/HomePage.xaml.cs +++ b/src/Core/Pages/Accounts/HomePage.xaml.cs @@ -2,6 +2,7 @@ using Bit.App.Utilities; using Bit.Core.Abstractions; using Bit.Core.Utilities; +using Microsoft.Maui.Platform; namespace Bit.App.Pages { @@ -77,7 +78,21 @@ namespace Bit.App.Pages _logger.Value?.Exception(ex); } } - + + //protected override void OnHandlerChanged() + //{ + // base.OnHandlerChanged(); + + // if (!_appOptions.IosExtension) + // { + // return; + // } + + // var window = new Window(); + // window.ToHandler(this.Handler.MauiContext); + // window.Page = this; + //} + protected override void OnNavigatingFrom(NavigatingFromEventArgs args) { base.OnNavigatingFrom(args); diff --git a/src/Core/Services/EnvironmentService.cs b/src/Core/Services/EnvironmentService.cs index 5cbca7695..7cca163ba 100644 --- a/src/Core/Services/EnvironmentService.cs +++ b/src/Core/Services/EnvironmentService.cs @@ -72,7 +72,7 @@ namespace Bit.Core.Services var urls = await _stateService.GetEnvironmentUrlsAsync(); urls ??= await _stateService.GetPreAuthEnvironmentUrlsAsync(); - if (urls == null || urls.IsEmpty) + if (urls == null || urls.IsEmpty || region is null) { await SetRegionAsync(BwRegion.US); _conditionedAwaiterManager.SetAsCompleted(AwaiterPrecondition.EnvironmentUrlsInited); diff --git a/src/iOS.Autofill/CredentialProviderViewController.cs b/src/iOS.Autofill/CredentialProviderViewController.cs index a0cbd8711..ca46b5a24 100644 --- a/src/iOS.Autofill/CredentialProviderViewController.cs +++ b/src/iOS.Autofill/CredentialProviderViewController.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading.Tasks; using AuthenticationServices; using Bit.App.Abstractions; @@ -22,6 +22,30 @@ using UIKit; namespace Bit.iOS.Autofill { + public partial class NavigationPageFix : NavigationPage + { + public NavigationPageFix() + { + } + + public NavigationPageFix(Page root) : base(root) + { + } + + protected override void OnHandlerChanged() + { + base.OnHandlerChanged(); + + var window = new Window(this); + + //window.Page = this; + window.ToHandler(this.Handler.MauiContext); + + //window.Page = this; + //window.ToHandler(MauiContextSingleton.Instance.MauiContext); + } + } + public partial class CredentialProviderViewController : ASCredentialProviderViewController, IAccountsManagerHost { private Context _context; @@ -140,8 +164,10 @@ namespace Bit.iOS.Autofill } catch (Exception ex) { - LoggerHelper.LogEvenIfCantBeResolved(ex); - throw; + UIPasteboard.General.String = ex.ToString(); + _labelErr.Text = ex.ToString(); + //LoggerHelper.LogEvenIfCantBeResolved(ex); + //throw; } } @@ -408,26 +434,34 @@ namespace Bit.iOS.Autofill private void LaunchHomePage() { - var appOptions = new AppOptions { IosExtension = true }; - var homePage = new HomePage(appOptions); - var app = new App.App(appOptions); - ThemeManager.SetTheme(app.Resources); - ThemeManager.ApplyResourcesTo(homePage); - if (homePage.BindingContext is HomeViewModel vm) + try { - vm.StartLoginAction = () => DismissViewController(false, () => LaunchLoginFlow(vm.Email)); - vm.StartRegisterAction = () => DismissViewController(false, () => LaunchRegisterFlow()); - vm.StartSsoLoginAction = () => DismissViewController(false, () => LaunchLoginSsoFlow()); - vm.StartEnvironmentAction = () => DismissViewController(false, () => LaunchEnvironmentFlow()); - vm.CloseAction = () => CompleteRequest(); + var appOptions = new AppOptions { IosExtension = true }; + var homePage = new HomePage(appOptions); + var app = new App.App(appOptions); + ThemeManager.SetTheme(app.Resources); + ThemeManager.ApplyResourcesTo(homePage); + if (homePage.BindingContext is HomeViewModel vm) + { + vm.StartLoginAction = () => DismissViewController(false, () => LaunchLoginFlow(vm.Email)); + vm.StartRegisterAction = () => DismissViewController(false, () => LaunchRegisterFlow()); + vm.StartSsoLoginAction = () => DismissViewController(false, () => LaunchLoginSsoFlow()); + vm.StartEnvironmentAction = () => DismissViewController(false, () => LaunchEnvironmentFlow()); + vm.CloseAction = () => CompleteRequest(); + } + + var navigationPage = new NavigationPageFix(homePage); + var loginController = navigationPage.ToUIViewController(MauiContextSingleton.Instance.MauiContext); + loginController.ModalPresentationStyle = UIModalPresentationStyle.FullScreen; + PresentViewController(loginController, true, null); + + LogoutIfAuthed(); + } + catch (Exception ex) + { + UIPasteboard.General.String = ex.ToString(); + _labelErr.Text = ex.ToString(); } - - var navigationPage = new NavigationPage(homePage); - var loginController = navigationPage.ToUIViewController(MauiContextSingleton.Instance.MauiContext); - loginController.ModalPresentationStyle = UIModalPresentationStyle.FullScreen; - PresentViewController(loginController, true, null); - - LogoutIfAuthed(); } private void LaunchEnvironmentFlow() @@ -442,7 +476,7 @@ namespace Bit.iOS.Autofill vm.CloseAction = () => DismissViewController(false, () => LaunchHomePage()); } - var navigationPage = new NavigationPage(environmentPage); + var navigationPage = new NavigationPageFix(environmentPage); var loginController = navigationPage.ToUIViewController(MauiContextSingleton.Instance.MauiContext); loginController.ModalPresentationStyle = UIModalPresentationStyle.FullScreen; PresentViewController(loginController, true, null); @@ -460,7 +494,7 @@ namespace Bit.iOS.Autofill vm.CloseAction = () => DismissViewController(false, () => LaunchHomePage()); } - var navigationPage = new NavigationPage(registerPage); + var navigationPage = new NavigationPageFix(registerPage); var loginController = navigationPage.ToUIViewController(MauiContextSingleton.Instance.MauiContext); loginController.ModalPresentationStyle = UIModalPresentationStyle.FullScreen; PresentViewController(loginController, true, null); @@ -483,7 +517,7 @@ namespace Bit.iOS.Autofill vm.CloseAction = () => DismissViewController(false, () => LaunchHomePage()); } - var navigationPage = new NavigationPage(loginPage); + var navigationPage = new NavigationPageFix(loginPage); var loginController = navigationPage.ToUIViewController(MauiContextSingleton.Instance.MauiContext); loginController.ModalPresentationStyle = UIModalPresentationStyle.FullScreen; PresentViewController(loginController, true, null); @@ -506,7 +540,7 @@ namespace Bit.iOS.Autofill vm.CloseAction = () => DismissViewController(false, () => LaunchHomePage()); } - var navigationPage = new NavigationPage(loginWithDevicePage); + var navigationPage = new NavigationPageFix(loginWithDevicePage); var loginController = navigationPage.ToUIViewController(MauiContextSingleton.Instance.MauiContext); loginController.ModalPresentationStyle = UIModalPresentationStyle.FullScreen; PresentViewController(loginController, true, null); @@ -530,7 +564,7 @@ namespace Bit.iOS.Autofill vm.CloseAction = () => DismissViewController(false, () => LaunchHomePage()); } - var navigationPage = new NavigationPage(loginPage); + var navigationPage = new NavigationPageFix(loginPage); var loginController = navigationPage.ToUIViewController(MauiContextSingleton.Instance.MauiContext); loginController.ModalPresentationStyle = UIModalPresentationStyle.FullScreen; PresentViewController(loginController, true, null); @@ -560,7 +594,7 @@ namespace Bit.iOS.Autofill vm.UpdateTempPasswordAction = () => DismissViewController(false, () => LaunchUpdateTempPasswordFlow()); } - var navigationPage = new NavigationPage(twoFactorPage); + var navigationPage = new NavigationPageFix(twoFactorPage); var twoFactorController = navigationPage.ToUIViewController(MauiContextSingleton.Instance.MauiContext); twoFactorController.ModalPresentationStyle = UIModalPresentationStyle.FullScreen; PresentViewController(twoFactorController, true, null); @@ -579,7 +613,7 @@ namespace Bit.iOS.Autofill vm.CloseAction = () => DismissViewController(false, () => LaunchHomePage()); } - var navigationPage = new NavigationPage(setPasswordPage); + var navigationPage = new NavigationPageFix(setPasswordPage); var setPasswordController = navigationPage.ToUIViewController(MauiContextSingleton.Instance.MauiContext); setPasswordController.ModalPresentationStyle = UIModalPresentationStyle.FullScreen; PresentViewController(setPasswordController, true, null); @@ -597,7 +631,7 @@ namespace Bit.iOS.Autofill vm.LogOutAction = () => DismissViewController(false, () => LaunchHomePage()); } - var navigationPage = new NavigationPage(updateTempPasswordPage); + var navigationPage = new NavigationPageFix(updateTempPasswordPage); var updateTempPasswordController = navigationPage.ToUIViewController(MauiContextSingleton.Instance.MauiContext); updateTempPasswordController.ModalPresentationStyle = UIModalPresentationStyle.FullScreen; PresentViewController(updateTempPasswordController, true, null); @@ -616,7 +650,7 @@ namespace Bit.iOS.Autofill vm.LogInWithDeviceAction = () => DismissViewController(false, () => LaunchLoginWithDevice(AuthRequestType.AuthenticateAndUnlock, vm.Email, true)); } - var navigationPage = new NavigationPage(loginApproveDevicePage); + var navigationPage = new NavigationPageFix(loginApproveDevicePage); var loginApproveDeviceController = navigationPage.ToUIViewController(MauiContextSingleton.Instance.MauiContext); loginApproveDeviceController.ModalPresentationStyle = UIModalPresentationStyle.FullScreen; PresentViewController(loginApproveDeviceController, true, null); diff --git a/src/iOS.Autofill/CredentialProviderViewController.designer.cs b/src/iOS.Autofill/CredentialProviderViewController.designer.cs index ac62805d2..88a1680eb 100644 --- a/src/iOS.Autofill/CredentialProviderViewController.designer.cs +++ b/src/iOS.Autofill/CredentialProviderViewController.designer.cs @@ -1,29 +1,35 @@ // WARNING // -// This file has been generated automatically by Visual Studio from the outlets and -// actions declared in your storyboard file. -// Manual changes to this file will not be maintained. +// This file has been generated automatically by Visual Studio to store outlets and +// actions made in the UI designer. If it is removed, they will be lost. +// Manual changes to this file may not be handled correctly. // using Foundation; -using System; using System.CodeDom.Compiler; -using UIKit; namespace Bit.iOS.Autofill { - [Register ("CredentialProviderViewController")] - partial class CredentialProviderViewController - { - [Outlet] - [GeneratedCode ("iOS Designer", "1.0")] - UIKit.UIImageView Logo { get; set; } + [Register ("CredentialProviderViewController")] + partial class CredentialProviderViewController + { + [Outlet] + UIKit.UILabel _labelErr { get; set; } - void ReleaseDesignerOutlets () - { - if (Logo != null) { - Logo.Dispose (); - Logo = null; - } - } - } -} \ No newline at end of file + [Outlet] + [GeneratedCode ("iOS Designer", "1.0")] + UIKit.UIImageView Logo { get; set; } + + void ReleaseDesignerOutlets () + { + if (Logo != null) { + Logo.Dispose (); + Logo = null; + } + + if (_labelErr != null) { + _labelErr.Dispose (); + _labelErr = null; + } + } + } +} diff --git a/src/iOS.Autofill/MainInterface.storyboard b/src/iOS.Autofill/MainInterface.storyboard index c2da85eff..2c59ecd8c 100644 --- a/src/iOS.Autofill/MainInterface.storyboard +++ b/src/iOS.Autofill/MainInterface.storyboard @@ -1,9 +1,9 @@ - + - + @@ -18,18 +18,28 @@ - + + - + + + + + @@ -68,7 +78,7 @@ - + @@ -88,7 +98,7 @@ - + @@ -128,15 +138,15 @@ - + - + - + @@ -166,7 +176,7 @@ - + @@ -236,7 +246,7 @@ - + @@ -257,11 +267,11 @@ - + - + @@ -318,7 +328,7 @@ - + @@ -357,15 +367,15 @@ - + - + - + @@ -373,7 +383,7 @@ - + @@ -381,7 +391,7 @@ - + @@ -392,7 +402,7 @@ - + @@ -447,7 +457,7 @@ - +