1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-05 23:53:33 +00:00

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

This commit is contained in:
Federico Maccaroni
2023-11-13 21:30:56 -03:00
parent 5712639492
commit 5f12bb9747
7 changed files with 33 additions and 44 deletions

View File

@@ -10,8 +10,8 @@ namespace Bit.App.Pages
{ {
public class BaseContentPage : ContentPage public class BaseContentPage : ContentPage
{ {
private IStateService _stateService; private readonly LazyResolve<IStateService> _stateService = new LazyResolve<IStateService>();
private IDeviceActionService _deviceActionService; private readonly LazyResolve<IDeviceActionService> _deviceActionService = new LazyResolve<IDeviceActionService>();
protected int ShowModalAnimationDelay = 400; protected int ShowModalAnimationDelay = 400;
protected int ShowPageAnimationDelay = 100; protected int ShowPageAnimationDelay = 100;
@@ -122,41 +122,28 @@ namespace Bit.App.Pages
protected async Task<bool> ShowAccountSwitcherAsync() protected async Task<bool> ShowAccountSwitcherAsync()
{ {
return await _stateService.GetActiveUserIdAsync() != null; return await _stateService.Value.GetActiveUserIdAsync() != null;
} }
protected async Task<AvatarImageSource> GetAvatarImageSourceAsync(bool useCurrentActiveAccount = true) protected async Task<AvatarImageSource> GetAvatarImageSourceAsync(bool useCurrentActiveAccount = true)
{ {
if (useCurrentActiveAccount) 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(user.UserId, user.Name, user.Email, user.AvatarColor);
} }
return new AvatarImageSource(); return new AvatarImageSource();
} }
private void SetServices()
{
if (_stateService == null)
{
_stateService = ServiceContainer.Resolve<IStateService>("stateService");
}
if (_deviceActionService == null)
{
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
}
}
private async Task SaveActivityAsync() private async Task SaveActivityAsync()
{ {
SetServices(); if (await _stateService.Value.GetActiveUserIdAsync() == null)
if (await _stateService.GetActiveUserIdAsync() == null)
{ {
// Fresh install and/or all users logged out won't have an active user, skip saving last active time // Fresh install and/or all users logged out won't have an active user, skip saving last active time
return; return;
} }
await _stateService.SetLastActiveTimeAsync(_deviceActionService.GetActiveTime()); await _stateService.Value.SetLastActiveTimeAsync(_deviceActionService.Value.GetActiveTime());
} }
} }
} }

View File

@@ -1,13 +1,5 @@
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Bit.App.Behaviors; 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; using CommunityToolkit.Maui.Views;
namespace Bit.App.Pages namespace Bit.App.Pages
@@ -60,7 +52,7 @@ namespace Bit.App.Pages
private void ViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) private void ViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{ {
if (!_lazyDeletionDateTimePicker.IsLoaded if (!_lazyDeletionDateTimePicker.HasLazyViewLoaded
&& &&
e.PropertyName == nameof(SendAddEditPageViewModel.ShowDeletionCustomPickers) e.PropertyName == nameof(SendAddEditPageViewModel.ShowDeletionCustomPickers)
&& &&
@@ -69,7 +61,7 @@ namespace Bit.App.Pages
_lazyDeletionDateTimePicker.LoadViewAsync(); _lazyDeletionDateTimePicker.LoadViewAsync();
} }
if (!_lazyExpirationDateTimePicker.IsLoaded if (!_lazyExpirationDateTimePicker.HasLazyViewLoaded
&& &&
e.PropertyName == nameof(SendAddEditPageViewModel.ShowExpirationCustomPickers) e.PropertyName == nameof(SendAddEditPageViewModel.ShowExpirationCustomPickers)
&& &&

View File

@@ -150,6 +150,7 @@
InputTransparent="False" InputTransparent="False"
Spacing="0" Spacing="0"
SemanticProperties.Description="{Binding OptionsAccessilibityText}"> SemanticProperties.Description="{Binding OptionsAccessilibityText}">
<!-- TODO: TapGestureRecognizer not working https://github.com/dotnet/maui/issues/17948 -->
<StackLayout.GestureRecognizers> <StackLayout.GestureRecognizers>
<TapGestureRecognizer Tapped="OptionsHeader_Tapped" /> <TapGestureRecognizer Tapped="OptionsHeader_Tapped" />
</StackLayout.GestureRecognizers> </StackLayout.GestureRecognizers>

View File

@@ -16,7 +16,7 @@ namespace Bit.App.Pages
public partial class SendAddOnlyPage : BaseContentPage public partial class SendAddOnlyPage : BaseContentPage
{ {
private readonly IVaultTimeoutService _vaultTimeoutService; private readonly IVaultTimeoutService _vaultTimeoutService;
private readonly LazyResolve<ILogger> _logger = new LazyResolve<ILogger>("logger"); private readonly LazyResolve<ILogger> _logger = new LazyResolve<ILogger>();
private AppOptions _appOptions; private AppOptions _appOptions;
private SendAddEditPageViewModel _vm; private SendAddEditPageViewModel _vm;
@@ -61,6 +61,7 @@ namespace Bit.App.Pages
{ {
return; return;
} }
await _vm.InitAsync(); await _vm.InitAsync();
if (!await _vm.LoadAsync()) if (!await _vm.LoadAsync())
@@ -70,7 +71,7 @@ namespace Bit.App.Pages
} }
_accountAvatar?.OnAppearing(); _accountAvatar?.OnAppearing();
await Device.InvokeOnMainThreadAsync(async () => _vm.AvatarImageSource = await GetAvatarImageSourceAsync()); await MainThread.InvokeOnMainThreadAsync(async () => _vm.AvatarImageSource = await GetAvatarImageSourceAsync());
await HandleCreateRequest(); await HandleCreateRequest();
if (string.IsNullOrWhiteSpace(_vm.Send?.Name)) if (string.IsNullOrWhiteSpace(_vm.Send?.Name))
@@ -86,10 +87,10 @@ namespace Bit.App.Pages
} }
} }
protected override void OnNavigatingFrom(NavigatingFromEventArgs args) protected override void OnNavigatingFrom(NavigatingFromEventArgs args)
{ {
base.OnNavigatingFrom(args); base.OnNavigatingFrom(args);
_accountAvatar?.OnDisappearing(); _accountAvatar?.OnDisappearing();
} }
@@ -160,14 +161,21 @@ namespace Bit.App.Pages
return Task.CompletedTask; return Task.CompletedTask;
} }
void OptionsHeader_Tapped(object sender, EventArgs e) async void OptionsHeader_Tapped(object sender, EventArgs e)
{ {
_vm.ToggleOptionsCommand.Execute(null); try
if (!_lazyOptionsView.IsLoaded)
{ {
_lazyOptionsView.MainScrollView = _scrollView; _vm.ToggleOptionsCommand.Execute(null);
_lazyOptionsView.LoadViewAsync();
if (!_lazyOptionsView.HasLazyViewLoaded)
{
_lazyOptionsView.MainScrollView = _scrollView;
await _lazyOptionsView.LoadViewAsync();
}
}
catch (Exception ex)
{
_logger.Value.Exception(ex);
} }
} }
} }

View File

@@ -28,7 +28,8 @@ namespace Bit.iOS.Core.Handlers
private static void UpdateTintColor(IEditorHandler handler, IEditor editor) 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);
} }
} }
} }

View File

@@ -9,10 +9,10 @@ namespace Bit.iOS.Core.Handlers
{ {
public static void Setup() public static void Setup()
{ {
EntryHandler.Mapper.AppendToMapping("CustomEntryHandler", (handler, editor) => EntryHandler.Mapper.AppendToMapping("CustomEntryHandler", (handler, entry) =>
{ {
handler.PlatformView.ClearButtonMode = UITextFieldViewMode.WhileEditing; handler.PlatformView.ClearButtonMode = UITextFieldViewMode.WhileEditing;
UpdateTintColor(handler, editor); UpdateTintColor(handler, entry);
iOSHelpers.SetBottomBorder(handler.PlatformView); iOSHelpers.SetBottomBorder(handler.PlatformView);
if (!ThemeHelpers.LightTheme) if (!ThemeHelpers.LightTheme)
@@ -24,9 +24,10 @@ namespace Bit.iOS.Core.Handlers
EntryHandler.Mapper.AppendToMapping(nameof(IEntry.TextColor), UpdateTintColor); 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);
} }
} }
} }

View File

@@ -59,7 +59,6 @@
<Compile Include="ExtensionNavigationController.designer.cs"> <Compile Include="ExtensionNavigationController.designer.cs">
<DependentUpon>ExtensionNavigationController.cs</DependentUpon> <DependentUpon>ExtensionNavigationController.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="MainViewController.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<BundleResource Include="..\iOS\Resources\logo_white%403x.png"> <BundleResource Include="..\iOS\Resources\logo_white%403x.png">