Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Plugin.Maui.KeyListener/KeyboardBehavior.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ protected override void OnDetachedFrom(VisualElement bindable, UIView platformVi

static Page? GetParentPage(VisualElement element)
{
if (element is Page)
return element as Page;
if (element is Page page)
return page;

Element currentElement = element;
Element currentElement = element.Parent;

while (currentElement != null && currentElement is not Page)
currentElement = currentElement.Parent;
Expand Down
9 changes: 2 additions & 7 deletions src/Plugin.Maui.KeyListener/KeyboardMarkupExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@ public sealed class KeyboardModifiersExtension : IMarkupExtension

public object ProvideValue(IServiceProvider serviceProvider)
{
if (Enum.TryParse(typeof(KeyboardModifiers), Modifiers, out var enumValue))
{
return enumValue;
}

var enumValues = Modifiers.Split(',').Select(flag => flag.Trim());
var combinedFlag = KeyboardModifiers.None;

foreach (var flag in enumValues)
foreach (var range in MemoryExtensions.Split(Modifiers, ','))
{
var flag = Modifiers.AsSpan()[range].Trim();
if (Enum.TryParse(typeof(KeyboardModifiers), flag, out var singleFlag))
combinedFlag |= (KeyboardModifiers)singleFlag;
}
Expand Down
17 changes: 8 additions & 9 deletions src/Plugin.Maui.KeyListener/MauiProgramExtension.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
using Plugin.Maui.KeyListener;
#if IOS || MACCATALYST
using Microsoft.Maui.Handlers;
#endif

namespace Plugin.Maui.KeyListener;

public static class MauiProgramExtensions
{
public static MauiAppBuilder UseKeyListener(this MauiAppBuilder builder)
{
builder.ConfigureMauiHandlers(handlers =>
{
#if IOS || MACCATALYST
#if IOS || MACCATALYST
PageHandler.PlatformViewFactory = (handler) =>
{
if (handler is not PageHandler pageHandler)
return null;

var vc = new KeyboardPageViewController(handler.VirtualView, handler.MauiContext);
handler.ViewController = vc;
return (Microsoft.Maui.Platform.ContentView)vc.View.Subviews[0];
if (handler is PageHandler pageHandler)
handler.ViewController = new KeyboardPageViewController(handler.VirtualView, handler.MauiContext);
return null; // Fall through to default view creation
};
#endif
#endif
});

return builder;
Expand Down