From 5f12bb9747d15739eeea02ef2704da9705191ee9 Mon Sep 17 00:00:00 2001 From: Federico Maccaroni Date: Mon, 13 Nov 2023 21:30:56 -0300 Subject: [PATCH] PM-3350 Fixed iOS Share extension lazy views loading and an issue with the avatar loading. Also discovered issue with TapGestureRecognizer not working on MAUI Embedding --- src/Core/Pages/BaseContentPage.cs | 25 +++++------------- .../Pages/Send/SendAddOnlyOptionsView.xaml.cs | 12 ++------- src/Core/Pages/Send/SendAddOnlyPage.xaml | 1 + src/Core/Pages/Send/SendAddOnlyPage.xaml.cs | 26 ++++++++++++------- .../Handlers/EditorHandlerMappings.cs | 3 ++- src/iOS.Core/Handlers/EntryHandlerMappings.cs | 9 ++++--- .../iOS.ShareExtension.csproj | 1 - 7 files changed, 33 insertions(+), 44 deletions(-) diff --git a/src/Core/Pages/BaseContentPage.cs b/src/Core/Pages/BaseContentPage.cs index 52077d8ed..4fed7a050 100644 --- a/src/Core/Pages/BaseContentPage.cs +++ b/src/Core/Pages/BaseContentPage.cs @@ -10,8 +10,8 @@ namespace Bit.App.Pages { public class BaseContentPage : ContentPage { - private IStateService _stateService; - private IDeviceActionService _deviceActionService; + private readonly LazyResolve _stateService = new LazyResolve(); + private readonly LazyResolve _deviceActionService = new LazyResolve(); protected int ShowModalAnimationDelay = 400; protected int ShowPageAnimationDelay = 100; @@ -122,41 +122,28 @@ namespace Bit.App.Pages protected async Task ShowAccountSwitcherAsync() { - return await _stateService.GetActiveUserIdAsync() != null; + return await _stateService.Value.GetActiveUserIdAsync() != null; } protected async Task GetAvatarImageSourceAsync(bool useCurrentActiveAccount = true) { if (useCurrentActiveAccount) { - var user = await _stateService.GetActiveUserCustomDataAsync(a => (a?.Profile?.UserId, a?.Profile?.Name, a?.Profile?.Email, a?.Profile?.AvatarColor)); + var user = await _stateService.Value.GetActiveUserCustomDataAsync(a => (a?.Profile?.UserId, a?.Profile?.Name, a?.Profile?.Email, a?.Profile?.AvatarColor)); return new AvatarImageSource(user.UserId, user.Name, user.Email, user.AvatarColor); } return new AvatarImageSource(); } - private void SetServices() - { - if (_stateService == null) - { - _stateService = ServiceContainer.Resolve("stateService"); - } - if (_deviceActionService == null) - { - _deviceActionService = ServiceContainer.Resolve("deviceActionService"); - } - } - private async Task SaveActivityAsync() { - SetServices(); - if (await _stateService.GetActiveUserIdAsync() == null) + if (await _stateService.Value.GetActiveUserIdAsync() == null) { // Fresh install and/or all users logged out won't have an active user, skip saving last active time return; } - await _stateService.SetLastActiveTimeAsync(_deviceActionService.GetActiveTime()); + await _stateService.Value.SetLastActiveTimeAsync(_deviceActionService.Value.GetActiveTime()); } } } diff --git a/src/Core/Pages/Send/SendAddOnlyOptionsView.xaml.cs b/src/Core/Pages/Send/SendAddOnlyOptionsView.xaml.cs index 93535cf00..ee6848f35 100644 --- a/src/Core/Pages/Send/SendAddOnlyOptionsView.xaml.cs +++ b/src/Core/Pages/Send/SendAddOnlyOptionsView.xaml.cs @@ -1,13 +1,5 @@ using System.Runtime.CompilerServices; -using System.Threading.Tasks; using Bit.App.Behaviors; -using Microsoft.Maui.Controls; -using Microsoft.Maui; -using CommunityToolkit.Maui.Converters; -using CommunityToolkit.Maui.ImageSources; -using CommunityToolkit.Maui; -using CommunityToolkit.Maui.Core; -using CommunityToolkit.Maui.Layouts; using CommunityToolkit.Maui.Views; namespace Bit.App.Pages @@ -60,7 +52,7 @@ namespace Bit.App.Pages private void ViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { - if (!_lazyDeletionDateTimePicker.IsLoaded + if (!_lazyDeletionDateTimePicker.HasLazyViewLoaded && e.PropertyName == nameof(SendAddEditPageViewModel.ShowDeletionCustomPickers) && @@ -69,7 +61,7 @@ namespace Bit.App.Pages _lazyDeletionDateTimePicker.LoadViewAsync(); } - if (!_lazyExpirationDateTimePicker.IsLoaded + if (!_lazyExpirationDateTimePicker.HasLazyViewLoaded && e.PropertyName == nameof(SendAddEditPageViewModel.ShowExpirationCustomPickers) && diff --git a/src/Core/Pages/Send/SendAddOnlyPage.xaml b/src/Core/Pages/Send/SendAddOnlyPage.xaml index 8dd6d6d02..d4b34b05e 100644 --- a/src/Core/Pages/Send/SendAddOnlyPage.xaml +++ b/src/Core/Pages/Send/SendAddOnlyPage.xaml @@ -150,6 +150,7 @@ InputTransparent="False" Spacing="0" SemanticProperties.Description="{Binding OptionsAccessilibityText}"> + diff --git a/src/Core/Pages/Send/SendAddOnlyPage.xaml.cs b/src/Core/Pages/Send/SendAddOnlyPage.xaml.cs index 75401f4db..125e2fa92 100644 --- a/src/Core/Pages/Send/SendAddOnlyPage.xaml.cs +++ b/src/Core/Pages/Send/SendAddOnlyPage.xaml.cs @@ -16,7 +16,7 @@ namespace Bit.App.Pages public partial class SendAddOnlyPage : BaseContentPage { private readonly IVaultTimeoutService _vaultTimeoutService; - private readonly LazyResolve _logger = new LazyResolve("logger"); + private readonly LazyResolve _logger = new LazyResolve(); private AppOptions _appOptions; private SendAddEditPageViewModel _vm; @@ -61,6 +61,7 @@ namespace Bit.App.Pages { return; } + await _vm.InitAsync(); if (!await _vm.LoadAsync()) @@ -70,7 +71,7 @@ namespace Bit.App.Pages } _accountAvatar?.OnAppearing(); - await Device.InvokeOnMainThreadAsync(async () => _vm.AvatarImageSource = await GetAvatarImageSourceAsync()); + await MainThread.InvokeOnMainThreadAsync(async () => _vm.AvatarImageSource = await GetAvatarImageSourceAsync()); await HandleCreateRequest(); if (string.IsNullOrWhiteSpace(_vm.Send?.Name)) @@ -86,10 +87,10 @@ namespace Bit.App.Pages } } - protected override void OnNavigatingFrom(NavigatingFromEventArgs args) { base.OnNavigatingFrom(args); + _accountAvatar?.OnDisappearing(); } @@ -160,14 +161,21 @@ namespace Bit.App.Pages return Task.CompletedTask; } - void OptionsHeader_Tapped(object sender, EventArgs e) + async void OptionsHeader_Tapped(object sender, EventArgs e) { - _vm.ToggleOptionsCommand.Execute(null); - - if (!_lazyOptionsView.IsLoaded) + try { - _lazyOptionsView.MainScrollView = _scrollView; - _lazyOptionsView.LoadViewAsync(); + _vm.ToggleOptionsCommand.Execute(null); + + if (!_lazyOptionsView.HasLazyViewLoaded) + { + _lazyOptionsView.MainScrollView = _scrollView; + await _lazyOptionsView.LoadViewAsync(); + } + } + catch (Exception ex) + { + _logger.Value.Exception(ex); } } } diff --git a/src/iOS.Core/Handlers/EditorHandlerMappings.cs b/src/iOS.Core/Handlers/EditorHandlerMappings.cs index 3cd846ec7..2b7b72c98 100644 --- a/src/iOS.Core/Handlers/EditorHandlerMappings.cs +++ b/src/iOS.Core/Handlers/EditorHandlerMappings.cs @@ -28,7 +28,8 @@ namespace Bit.iOS.Core.Handlers private static void UpdateTintColor(IEditorHandler handler, IEditor editor) { - handler.PlatformView.TintColor = editor.TextColor.ToPlatform(); + // Note: the default black value is to avoid an error on the iOS extensions while lazy loading a view + handler.PlatformView.TintColor = editor.TextColor.ToPlatform(Colors.Black); } } } diff --git a/src/iOS.Core/Handlers/EntryHandlerMappings.cs b/src/iOS.Core/Handlers/EntryHandlerMappings.cs index ccfffd2c8..30da744e2 100644 --- a/src/iOS.Core/Handlers/EntryHandlerMappings.cs +++ b/src/iOS.Core/Handlers/EntryHandlerMappings.cs @@ -9,10 +9,10 @@ namespace Bit.iOS.Core.Handlers { public static void Setup() { - EntryHandler.Mapper.AppendToMapping("CustomEntryHandler", (handler, editor) => + EntryHandler.Mapper.AppendToMapping("CustomEntryHandler", (handler, entry) => { handler.PlatformView.ClearButtonMode = UITextFieldViewMode.WhileEditing; - UpdateTintColor(handler, editor); + UpdateTintColor(handler, entry); iOSHelpers.SetBottomBorder(handler.PlatformView); if (!ThemeHelpers.LightTheme) @@ -24,9 +24,10 @@ namespace Bit.iOS.Core.Handlers EntryHandler.Mapper.AppendToMapping(nameof(IEntry.TextColor), UpdateTintColor); } - private static void UpdateTintColor(IEntryHandler handler, IEntry editor) + private static void UpdateTintColor(IEntryHandler handler, IEntry entry) { - handler.PlatformView.TintColor = editor.TextColor.ToPlatform(); + // Note: the default black value is to avoid an error on the iOS extensions while lazy loading a view + handler.PlatformView.TintColor = entry.TextColor.ToPlatform(Colors.Black); } } } diff --git a/src/iOS.ShareExtension/iOS.ShareExtension.csproj b/src/iOS.ShareExtension/iOS.ShareExtension.csproj index 0f72037a3..9d697ee1d 100644 --- a/src/iOS.ShareExtension/iOS.ShareExtension.csproj +++ b/src/iOS.ShareExtension/iOS.ShareExtension.csproj @@ -59,7 +59,6 @@ ExtensionNavigationController.cs -