Skip to content

Commit c451130

Browse files
[Android] Fix: Prevent duplicate Completed event when setting ReturnType in Entry (#28018)
* fix * adding test * set handled true for specific cases only
1 parent 6b203c4 commit c451130

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="Controls.TestCases.HostApp.Issues.Issue27992"
5+
Title="Issue27992">
6+
<VerticalStackLayout Margin="10,30,10,0">
7+
<Entry AutomationId="MauiEntry" Completed="Entry_Completed"
8+
ReturnType="Search" />
9+
<Label AutomationId="MauiLabel" x:Name="label" FontSize="30" TextColor="Black" />
10+
</VerticalStackLayout>
11+
</ContentPage>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace Controls.TestCases.HostApp.Issues;
2+
3+
[Issue(IssueTracker.Github, 27992, "Entry Completed Event Triggered Twice", PlatformAffected.Android)]
4+
public partial class Issue27992 : ContentPage
5+
{
6+
public Issue27992()
7+
{
8+
InitializeComponent();
9+
}
10+
int i =0;
11+
private void Entry_Completed(object sender, EventArgs e)
12+
{
13+
i++;
14+
label.Text = $"Completed Invoked {i} times";
15+
}
16+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using NUnit.Framework;
3+
using UITest.Appium;
4+
using UITest.Core;
5+
6+
namespace Microsoft.Maui.TestCases.Tests.Tests.Issues;
7+
8+
public class Issue27992 : _IssuesUITest
9+
{
10+
public Issue27992(TestDevice device) : base(device)
11+
{
12+
}
13+
14+
public override string Issue => "Entry Completed Event Triggered Twice";
15+
16+
17+
[Test]
18+
[Category(UITestCategories.Entry)]
19+
public void EntryCompletedShouldOnlyFireOnce()
20+
{
21+
App.WaitForElement("MauiEntry");
22+
23+
App.Tap("MauiEntry");
24+
25+
App.PressEnter();
26+
27+
var text = App.WaitForElement("MauiLabel").GetText();
28+
Assert.That(text,Is.EqualTo("Completed Invoked 1 times"));
29+
}
30+
}

src/Core/src/Handlers/Entry/EntryHandler.Android.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,12 @@ void OnEditorAction(object? sender, EditorActionEventArgs e)
223223
else if (evt?.KeyCode is null && (actionId == ImeAction.Done || actionId == currentInputImeFlag))
224224
{
225225
VirtualView?.Completed();
226+
// In case of Search, Go, Send the EditorAction will be invoked for KeyEventActions which will cause Completed to inovke twice
227+
//So for these setting handled to true
228+
if (actionId == ImeAction.Search ||
229+
actionId == ImeAction.Go ||
230+
actionId == ImeAction.Send)
231+
handled = true;
226232
}
227233
}
228234

0 commit comments

Comments
 (0)