diff --git a/src/Plugin.Maui.KeyListener/KeyboardBehavior.iOS.cs b/src/Plugin.Maui.KeyListener/KeyboardBehavior.iOS.cs index 9be1b1e..6ec3716 100644 --- a/src/Plugin.Maui.KeyListener/KeyboardBehavior.iOS.cs +++ b/src/Plugin.Maui.KeyListener/KeyboardBehavior.iOS.cs @@ -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; diff --git a/src/Plugin.Maui.KeyListener/KeyboardMarkupExtensions.cs b/src/Plugin.Maui.KeyListener/KeyboardMarkupExtensions.cs index 3d06734..d772663 100644 --- a/src/Plugin.Maui.KeyListener/KeyboardMarkupExtensions.cs +++ b/src/Plugin.Maui.KeyListener/KeyboardMarkupExtensions.cs @@ -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; } diff --git a/src/Plugin.Maui.KeyListener/MauiProgramExtension.cs b/src/Plugin.Maui.KeyListener/MauiProgramExtension.cs index c21b483..2df3c4c 100644 --- a/src/Plugin.Maui.KeyListener/MauiProgramExtension.cs +++ b/src/Plugin.Maui.KeyListener/MauiProgramExtension.cs @@ -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;