1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-16 00:03:22 +00:00

PM-6077 Separated Android and iOS HybridWebViewHandler so that it can be used on iOS.Core (#2983)

This commit is contained in:
Dinis Vieira
2024-02-07 17:50:07 +00:00
committed by GitHub
parent b1a0801f9b
commit 759627b3c7
5 changed files with 23 additions and 29 deletions

View File

@@ -1,25 +0,0 @@
#if IOS || MACCATALYST
using PlatformView = WebKit.WKWebView;
#elif ANDROID
using PlatformView = Android.Webkit.WebView;
#elif (NETSTANDARD || !PLATFORM) || (NET6_0_OR_GREATER && !IOS && !ANDROID)
using PlatformView = System.Object;
#endif
using Bit.App.Controls;
using Microsoft.Maui.Handlers;
namespace Bit.App.Handlers
{
public partial class HybridWebViewHandler
{
public static PropertyMapper<HybridWebView, HybridWebViewHandler> PropertyMapper = new PropertyMapper<HybridWebView, HybridWebViewHandler>(ViewHandler.ViewMapper)
{
[nameof(HybridWebView.Uri)] = MapUri
};
public HybridWebViewHandler() : base(PropertyMapper)
{
}
}
}

View File

@@ -13,7 +13,6 @@
}, },
handlers => handlers =>
{ {
handlers.AddHandler(typeof(Bit.App.Controls.HybridWebView), typeof(Bit.App.Handlers.HybridWebViewHandler));
#if ANDROID #if ANDROID
Bit.App.Handlers.EntryHandlerMappings.Setup(); Bit.App.Handlers.EntryHandlerMappings.Setup();
Bit.App.Handlers.EditorHandlerMappings.Setup(); Bit.App.Handlers.EditorHandlerMappings.Setup();
@@ -28,6 +27,7 @@
Bit.App.Handlers.ButtonHandlerMappings.Setup(); Bit.App.Handlers.ButtonHandlerMappings.Setup();
Bit.App.Handlers.ToolbarHandlerMappings.Setup(); Bit.App.Handlers.ToolbarHandlerMappings.Setup();
handlers.AddHandler(typeof(Bit.App.Controls.HybridWebView), typeof(Bit.App.Handlers.HybridWebViewHandler));
handlers.AddHandler(typeof(Bit.App.Pages.TabsPage), typeof(Bit.App.Handlers.CustomTabbedPageHandler)); handlers.AddHandler(typeof(Bit.App.Pages.TabsPage), typeof(Bit.App.Handlers.CustomTabbedPageHandler));
handlers.AddHandler(typeof(Bit.App.Controls.ExtendedDatePicker), typeof(Bit.App.Handlers.ExtendedDatePickerHandler)); handlers.AddHandler(typeof(Bit.App.Controls.ExtendedDatePicker), typeof(Bit.App.Handlers.ExtendedDatePickerHandler));
#else #else

View File

@@ -6,10 +6,19 @@ using AWebkit = Android.Webkit;
namespace Bit.App.Handlers namespace Bit.App.Handlers
{ {
public partial class HybridWebViewHandler : ViewHandler<HybridWebView, AWebkit.WebView> public class HybridWebViewHandler : ViewHandler<HybridWebView, AWebkit.WebView>
{ {
private const string JSFunction = "function invokeCSharpAction(data){jsBridge.invokeAction(data);}"; private const string JSFunction = "function invokeCSharpAction(data){jsBridge.invokeAction(data);}";
public static PropertyMapper<HybridWebView, HybridWebViewHandler> PropertyMapper = new PropertyMapper<HybridWebView, HybridWebViewHandler>(ViewHandler.ViewMapper)
{
[nameof(HybridWebView.Uri)] = MapUri
};
public HybridWebViewHandler() : base(PropertyMapper)
{
}
public HybridWebViewHandler([NotNull] IPropertyMapper mapper, CommandMapper commandMapper = null) : base(mapper, commandMapper) public HybridWebViewHandler([NotNull] IPropertyMapper mapper, CommandMapper commandMapper = null) : base(mapper, commandMapper)
{ {
} }

View File

@@ -5,15 +5,24 @@ using Foundation;
using Microsoft.Maui.Handlers; using Microsoft.Maui.Handlers;
using WebKit; using WebKit;
namespace Bit.App.Handlers namespace Bit.iOS.Core.Handlers
{ {
public partial class HybridWebViewHandler : ViewHandler<HybridWebView, WebKit.WKWebView> public class HybridWebViewHandler : ViewHandler<HybridWebView, WebKit.WKWebView>
{ {
private const string JSFunction = private const string JSFunction =
"function invokeCSharpAction(data){window.webkit.messageHandlers.invokeAction.postMessage(data);}"; "function invokeCSharpAction(data){window.webkit.messageHandlers.invokeAction.postMessage(data);}";
private WKUserContentController _userController; private WKUserContentController _userController;
public static PropertyMapper<HybridWebView, HybridWebViewHandler> PropertyMapper = new PropertyMapper<HybridWebView, HybridWebViewHandler>(ViewHandler.ViewMapper)
{
[nameof(HybridWebView.Uri)] = MapUri
};
public HybridWebViewHandler() : base(PropertyMapper)
{
}
public HybridWebViewHandler([NotNull] IPropertyMapper mapper, CommandMapper commandMapper = null) : base(mapper, commandMapper) public HybridWebViewHandler([NotNull] IPropertyMapper mapper, CommandMapper commandMapper = null) : base(mapper, commandMapper)
{ {
} }

View File

@@ -48,6 +48,7 @@ namespace Bit.iOS.Core.Utilities
public static void ConfigureMAUIHandlers(IMauiHandlersCollection handlers) public static void ConfigureMAUIHandlers(IMauiHandlersCollection handlers)
{ {
handlers.AddHandler(typeof(HybridWebView), typeof(Handlers.HybridWebViewHandler));
handlers.AddHandler(typeof(TabsPage), typeof(Handlers.CustomTabbedHandler)); handlers.AddHandler(typeof(TabsPage), typeof(Handlers.CustomTabbedHandler));
handlers.AddHandler(typeof(NavigationPage), typeof(Handlers.CustomNavigationHandler)); handlers.AddHandler(typeof(NavigationPage), typeof(Handlers.CustomNavigationHandler));
handlers.AddHandler(typeof(ViewCell), typeof(Handlers.CustomViewCellHandler)); handlers.AddHandler(typeof(ViewCell), typeof(Handlers.CustomViewCellHandler));