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 @@ -3,20 +3,15 @@
[ContentProperty(nameof(Modifiers))]
public sealed class KeyboardModifiersExtension : IMarkupExtension
{
public string Modifiers { get; set; }

Check warning on line 6 in src/Plugin.Maui.KeyListener/KeyboardMarkupExtensions.cs

View workflow job for this annotation

GitHub Actions / build-sample-ci

Non-nullable property 'Modifiers' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 6 in src/Plugin.Maui.KeyListener/KeyboardMarkupExtensions.cs

View workflow job for this annotation

GitHub Actions / build-plugin-ci

Non-nullable property 'Modifiers' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 6 in src/Plugin.Maui.KeyListener/KeyboardMarkupExtensions.cs

View workflow job for this annotation

GitHub Actions / build-plugin-ci

Non-nullable property 'Modifiers' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 6 in src/Plugin.Maui.KeyListener/KeyboardMarkupExtensions.cs

View workflow job for this annotation

GitHub Actions / build-plugin-ci

Non-nullable property 'Modifiers' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

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 All @@ -28,7 +23,7 @@
[ContentProperty(nameof(Keys))]
public sealed class KeyboardKeysExtension : IMarkupExtension
{
public string Keys { get; set; }

Check warning on line 26 in src/Plugin.Maui.KeyListener/KeyboardMarkupExtensions.cs

View workflow job for this annotation

GitHub Actions / build-sample-ci

Non-nullable property 'Keys' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 26 in src/Plugin.Maui.KeyListener/KeyboardMarkupExtensions.cs

View workflow job for this annotation

GitHub Actions / build-sample-ci

Non-nullable property 'Keys' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 26 in src/Plugin.Maui.KeyListener/KeyboardMarkupExtensions.cs

View workflow job for this annotation

GitHub Actions / build-plugin-ci

Non-nullable property 'Keys' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 26 in src/Plugin.Maui.KeyListener/KeyboardMarkupExtensions.cs

View workflow job for this annotation

GitHub Actions / build-plugin-ci

Non-nullable property 'Keys' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 26 in src/Plugin.Maui.KeyListener/KeyboardMarkupExtensions.cs

View workflow job for this annotation

GitHub Actions / build-plugin-ci

Non-nullable property 'Keys' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public object ProvideValue(IServiceProvider serviceProvider)
{
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);

Check warning on line 17 in src/Plugin.Maui.KeyListener/MauiProgramExtension.cs

View workflow job for this annotation

GitHub Actions / build-sample-ci

Possible null reference argument for parameter 'mauiContext' in 'KeyboardPageViewController.KeyboardPageViewController(IView page, IMauiContext mauiContext)'.

Check warning on line 17 in src/Plugin.Maui.KeyListener/MauiProgramExtension.cs

View workflow job for this annotation

GitHub Actions / build-sample-ci

Possible null reference argument for parameter 'mauiContext' in 'KeyboardPageViewController.KeyboardPageViewController(IView page, IMauiContext mauiContext)'.

Check warning on line 17 in src/Plugin.Maui.KeyListener/MauiProgramExtension.cs

View workflow job for this annotation

GitHub Actions / build-plugin-ci

Possible null reference argument for parameter 'mauiContext' in 'KeyboardPageViewController.KeyboardPageViewController(IView page, IMauiContext mauiContext)'.
return null; // Fall through to default view creation

Check warning on line 18 in src/Plugin.Maui.KeyListener/MauiProgramExtension.cs

View workflow job for this annotation

GitHub Actions / build-sample-ci

Possible null reference return.

Check warning on line 18 in src/Plugin.Maui.KeyListener/MauiProgramExtension.cs

View workflow job for this annotation

GitHub Actions / build-sample-ci

Possible null reference return.

Check warning on line 18 in src/Plugin.Maui.KeyListener/MauiProgramExtension.cs

View workflow job for this annotation

GitHub Actions / build-plugin-ci

Possible null reference return.
};
#endif
#endif
});

return builder;
Expand Down
Loading