-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android] Allow custom handler with key listener #22546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue21109.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #if ANDROID | ||
| using NUnit.Framework; | ||
| using NUnit.Framework.Legacy; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues | ||
| { | ||
| public class Issue21109 : _IssuesUITest | ||
| { | ||
| public Issue21109(TestDevice device) : base(device) { } | ||
|
|
||
| public override string Issue => "[Android] MAUI 8.0.3 -> 8.0.6 regression: custom handler with key listener no longer works"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.Entry)] | ||
| public void EntryReturnTypeWorks() | ||
| { | ||
| App.WaitForElement("WaitForStubControl"); | ||
|
|
||
| // Verify that ReturnType works as expected. | ||
| if (App.IsKeyboardShown()) | ||
| App.DismissKeyboard(); | ||
|
|
||
| var returnType1 = App.FindElement("ReturnTypeResult").GetText(); | ||
| App.Tap("ReturnTypeEntry"); | ||
| App.EnterText("ReturnTypeEntry", "a"); | ||
| var returnType2 = App.FindElement("ReturnTypeResult").GetText(); | ||
| ClassicAssert.AreNotEqual(returnType1, returnType2); | ||
| } | ||
| } | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
| x:Class="Maui.Controls.Sample.Issues.Issue21109" | ||
| xmlns:controls="clr-namespace:Maui.Controls.Sample.Issues"> | ||
| <VerticalStackLayout | ||
| Padding="30,0" | ||
| Spacing="25"> | ||
| <Label | ||
| AutomationId="WaitForStubControl" | ||
| Text="ReturnType (Search)" /> | ||
| <Entry | ||
| AutomationId="SearchEntry" | ||
| ReturnType="Search" /> | ||
| <Label | ||
| Text="Update the ReturnType just typing" /> | ||
| <Entry | ||
| x:Name="ReturnTypeEntry" | ||
| AutomationId="ReturnTypeEntry" | ||
| TextChanged="OnReturnTypeEntryTextChanged"/> | ||
| <Label | ||
| x:Name="ReturnTypeResult" | ||
| AutomationId="ReturnTypeResult"/> | ||
| <Label | ||
| Text="Custom DecimalEntry" /> | ||
| <controls:Issue21109DecimalEntry | ||
| AutomationId="CustomDecimalEntry"/> | ||
| </VerticalStackLayout> | ||
| </ContentPage> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| using System; | ||
| using Microsoft.Maui; | ||
| using Microsoft.Maui.Controls; | ||
| using Microsoft.Maui.Controls.Xaml; | ||
| using Microsoft.Maui.Hosting; | ||
|
|
||
| namespace Maui.Controls.Sample.Issues | ||
| { | ||
| [XamlCompilation(XamlCompilationOptions.Compile)] | ||
| [Issue(IssueTracker.Github, 21109, "[Android] MAUI 8.0.3 -> 8.0.6 regression: custom handler with key listener no longer works", PlatformAffected.All)] | ||
| public partial class Issue21109 : ContentPage | ||
| { | ||
| public Issue21109() | ||
| { | ||
| InitializeComponent(); | ||
|
|
||
| ReturnTypeResult.Text = $"ReturnType: {ReturnTypeEntry.ReturnType}"; | ||
| } | ||
|
|
||
| void OnReturnTypeEntryTextChanged(object sender, TextChangedEventArgs e) | ||
| { | ||
| Random rnd = new Random(); | ||
| var returnTypeCount = Enum.GetNames(typeof(ReturnType)).Length; | ||
|
|
||
| ReturnType returnType = ReturnType.Default; | ||
|
|
||
| do | ||
| { | ||
| returnType = (ReturnType)rnd.Next(0, returnTypeCount); | ||
| } while (returnType == ReturnTypeEntry.ReturnType); | ||
|
|
||
| ReturnTypeEntry.ReturnType = returnType; | ||
| ReturnTypeResult.Text = $"ReturnType: {returnType}"; | ||
| } | ||
| } | ||
|
|
||
| public class Issue21109DecimalEntry : Entry | ||
| { | ||
| public Issue21109DecimalEntry() | ||
| { | ||
| Keyboard = Keyboard.Numeric; | ||
| } | ||
| } | ||
|
|
||
| public static class Issue21109Extensions | ||
| { | ||
| public static MauiAppBuilder Issue21109AddMappers(this MauiAppBuilder builder) | ||
| { | ||
| builder.ConfigureMauiHandlers(handlers => | ||
| { | ||
| Microsoft.Maui.Handlers.EntryHandler.Mapper.AppendToMapping(nameof(Issue21109DecimalEntry), (handler, view) => | ||
| { | ||
| if (view is Issue21109DecimalEntry) | ||
| { | ||
| #if ANDROID | ||
| handler.PlatformView.KeyListener = new Platform.Issue21109NumericKeyListener(handler.PlatformView.InputType); | ||
| #endif | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| return builder; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/Controls/tests/TestCases/Platforms/Android/Issue21109NumericKeyListener.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| using Android.Text; | ||
| using Android.Text.Method; | ||
| using Android.Views; | ||
| using Microsoft.Maui.Controls; | ||
| using AView = Android.Views.View; | ||
|
|
||
| namespace Maui.Controls.Sample.Platform; | ||
|
|
||
| public class Issue21109NumericKeyListener : NumberKeyListener | ||
| { | ||
| public override InputTypes InputType { get; } | ||
|
|
||
| protected override char[] GetAcceptedChars() => "0123456789-,.".ToCharArray(); | ||
|
|
||
| public Issue21109NumericKeyListener(InputTypes inputType) | ||
| { | ||
| InputType = inputType; | ||
| } | ||
|
|
||
| public override bool OnKeyDown(AView view, IEditable content, Keycode keyCode, KeyEvent e) | ||
| { | ||
| Application.Current.MainPage.DisplayAlert("OnKeyDown", string.Empty, "Ok"); | ||
| return base.OnKeyDown(view, content, keyCode, e); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.