1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-29 22:53:34 +00:00

PM-3350 MAUI Migration Fix iOS Autofill extension

This commit is contained in:
Federico Maccaroni
2023-10-04 12:35:43 -03:00
parent 87eebda55f
commit 90649d1c8b
8 changed files with 77 additions and 88 deletions

View File

@@ -1,8 +1,7 @@
using System;
using System.Threading.Tasks;
using Bit.App.Controls;
using Bit.App.Controls;
using Bit.Core.Abstractions;
using Bit.Core.Utilities;
using Microsoft.Maui.Platform;
using UIKit;
namespace Bit.iOS.Core.Utilities
@@ -72,17 +71,18 @@ namespace Bit.iOS.Core.Utilities
//renderer.SetElementSize(new Size(containerView.Frame.Size.Width, containerView.Frame.Size.Height));
//var view = renderer.NativeView;
//view.TranslatesAutoresizingMaskIntoConstraints = false;
var view = overlay.ToPlatform(MauiContextSingleton.Instance.MauiContext);
view.TranslatesAutoresizingMaskIntoConstraints = false;
//containerView.AddSubview(view);
//containerView.AddConstraints(new NSLayoutConstraint[]
//{
// NSLayoutConstraint.Create(containerView, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, view, NSLayoutAttribute.Trailing, 1f, 0f),
// NSLayoutConstraint.Create(containerView, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, view, NSLayoutAttribute.Leading, 1f, 0f),
// NSLayoutConstraint.Create(containerView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, view, NSLayoutAttribute.Top, 1f, 0f),
// NSLayoutConstraint.Create(containerView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, view, NSLayoutAttribute.Bottom, 1f, 0f)
//});
//containerView.Hidden = true;
containerView.AddSubview(view);
containerView.AddConstraints(new NSLayoutConstraint[]
{
NSLayoutConstraint.Create(containerView, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, view, NSLayoutAttribute.Trailing, 1f, 0f),
NSLayoutConstraint.Create(containerView, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, view, NSLayoutAttribute.Leading, 1f, 0f),
NSLayoutConstraint.Create(containerView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, view, NSLayoutAttribute.Top, 1f, 0f),
NSLayoutConstraint.Create(containerView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, view, NSLayoutAttribute.Bottom, 1f, 0f)
});
containerView.Hidden = true;
return overlay;
}

View File

@@ -0,0 +1,15 @@
namespace Bit.iOS.Core.Utilities
{
public class MauiContextSingleton
{
private static readonly Lazy<MauiContextSingleton> _instance = new Lazy<MauiContextSingleton>(() => new MauiContextSingleton());
public static MauiContextSingleton Instance => _instance.Value;
private MauiContextSingleton() { }
public MauiContext? MauiContext { get; private set; }
public void Init(MauiContext mauiContext) => MauiContext = mauiContext;
}
}

View File

@@ -1,21 +1,18 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Bit.App.Abstractions;
using Bit.App.Abstractions;
using Bit.App.Controls;
using Bit.App.Models;
using Bit.App.Pages;
using Bit.Core.Resources.Localization;
using Bit.App.Services;
using Bit.App.Utilities;
using Bit.App.Utilities.AccountManagement;
using Bit.Core.Abstractions;
using Bit.Core.Enums;
using Bit.Core.Resources.Localization;
using Bit.Core.Services;
using Bit.Core.Utilities;
using Bit.iOS.Core.Services;
using CoreNFC;
using Foundation;
using Microsoft.Maui.Embedding;
using UIKit;
namespace Bit.iOS.Core.Utilities
@@ -28,6 +25,37 @@ namespace Bit.iOS.Core.Utilities
public static string AppGroupId = "group.com.8bit.bitwarden";
public static string AccessGroup = "LTZ2PFU5D6.com.8bit.bitwarden";
public static void SetupMaui()
{
var builder = Bit.Core.MauiProgram.ConfigureBaseMauiAppBuilder(ConfigureMAUIEffects, ConfigureMAUIHandlers)
.UseMauiEmbedding<Application>();
// Register the Window
builder.Services.Add(new ServiceDescriptor(typeof(UIWindow), UIApplication.SharedApplication.KeyWindow));
var mauiApp = builder.Build();
MauiContextSingleton.Instance.Init(new MauiContext(mauiApp.Services));
}
public static void ConfigureMAUIEffects(IEffectsBuilder effects)
{
effects.Add<App.Effects.NoEmojiKeyboardEffect, Bit.iOS.Core.Effects.NoEmojiKeyboardEffect>();
effects.Add<App.Effects.ScrollEnabledEffect, App.Effects.ScrollEnabledPlatformEffect>();
effects.Add<App.Effects.ScrollViewContentInsetAdjustmentBehaviorEffect, Bit.App.Effects.ScrollViewContentInsetAdjustmentBehaviorPlatformEffect>();
}
public static void ConfigureMAUIHandlers(IMauiHandlersCollection handlers)
{
Handlers.ButtonHandlerMappings.Setup();
Handlers.DatePickerHandlerMappings.Setup();
Handlers.EditorHandlerMappings.Setup();
Handlers.EntryHandlerMappings.Setup();
//Handlers.LabelHandlerMappings.Setup();
Handlers.PickerHandlerMappings.Setup();
Handlers.SearchBarHandlerMappings.Setup();
Handlers.StepperHandlerMappings.Setup();
Handlers.TimePickerHandlerMappings.Setup();
}
public static void InitApp<T>(T rootController,
string clearCipherCacheKey,
NFCNdefReaderSession nfcSession,
@@ -35,6 +63,8 @@ namespace Bit.iOS.Core.Utilities
out IAccountsManager accountsManager)
where T : UIViewController, IAccountsManagerHost
{
SetupMaui();
if (ServiceContainer.RegisteredServices.Count > 0)
{
ServiceContainer.Reset();