Skip to content

Commit f3ec03b

Browse files
authored
Fix HideSoftInputOnTapped Not Working Net9 (#28534)
* fix for 26792 * Update HideSoftInputOnTappedChangedManager.Platform.cs * Testcases added * Comments updated * Condition modification
1 parent 2dd0c47 commit f3ec03b

File tree

5 files changed

+72
-3
lines changed

5 files changed

+72
-3
lines changed

src/Controls/src/Core/ContentPage/HideSoftInputOnTappedChanged/HideSoftInputOnTappedChangedManager.Android.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void OnWindowDispatchedTouch(object? sender, MotionEvent? e)
2020

2121
foreach (var page in _contentPages)
2222
{
23-
if (page.HasNavigatedTo &&
23+
if ((page.HasNavigatedTo || page.Parent is Window) &&
2424
page.HideSoftInputOnTapped &&
2525
page.Handler is IPlatformViewHandler pvh &&
2626
pvh.MauiContext?.Context is not null)

src/Controls/src/Core/ContentPage/HideSoftInputOnTappedChanged/HideSoftInputOnTappedChangedManager.Platform.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ partial class HideSoftInputOnTappedChangedManager
1414

1515
internal void UpdatePage(ContentPage page)
1616
{
17-
if (page.HideSoftInputOnTapped && page.HasNavigatedTo)
17+
if (page.HideSoftInputOnTapped && (page.HasNavigatedTo || page.Parent is Window))
1818
{
1919
if (!_contentPages.Contains(page))
2020
{

src/Controls/src/Core/ContentPage/HideSoftInputOnTappedChanged/HideSoftInputOnTappedChangedManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ bool FeatureEnabled
1313
{
1414
foreach (var page in _contentPages)
1515
{
16-
if (page.HideSoftInputOnTapped && page.HasNavigatedTo)
16+
if (page.HideSoftInputOnTapped && (page.HasNavigatedTo || page.Parent is Window))
1717
return true;
1818
}
1919
return false;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
namespace Maui.Controls.Sample.Issues;
2+
3+
[Issue(IssueTracker.Github, 26792, "HideSoftInputOnTapped Not Working", PlatformAffected.Android)]
4+
public class Issue26792 : ContentPage
5+
{
6+
7+
VerticalStackLayout stackLayout;
8+
Button _button;
9+
10+
Entry _entry;
11+
public Issue26792()
12+
{
13+
this.HideSoftInputOnTapped = true;
14+
stackLayout = new VerticalStackLayout
15+
{
16+
HorizontalOptions = LayoutOptions.Center,
17+
VerticalOptions = LayoutOptions.Center,
18+
AutomationId = "Issue26792StackLayout",
19+
};
20+
_button = new Button
21+
{
22+
Text = "Click Me",
23+
AutomationId = "Issue26792Button",
24+
HorizontalOptions = LayoutOptions.Center,
25+
VerticalOptions = LayoutOptions.Center,
26+
};
27+
_entry = new Entry
28+
{
29+
Placeholder = "Enter text",
30+
AutomationId = "Issue26792Entry",
31+
HorizontalOptions = LayoutOptions.Center,
32+
VerticalOptions = LayoutOptions.Center,
33+
};
34+
35+
stackLayout.Children.Add(_button);
36+
stackLayout.Children.Add(_entry);
37+
Content = stackLayout;
38+
}
39+
}
40+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#if TEST_FAILS_ON_CATALYST && TEST_FAILS_ON_WINDOWS //As SoftKeyboard is not supported
2+
using NUnit.Framework;
3+
using UITest.Appium;
4+
using UITest.Core;
5+
6+
namespace Microsoft.Maui.TestCases.Tests.Issues;
7+
8+
public class Issue26792 : _IssuesUITest
9+
{
10+
public Issue26792(TestDevice testDevice) : base(testDevice)
11+
{
12+
}
13+
14+
public override string Issue => "HideSoftInputOnTapped Not Working";
15+
16+
[Test]
17+
[Category(UITestCategories.Page)]
18+
public void SoftInputShouldHiddenOnTap()
19+
{
20+
App.WaitForElement("Issue26792Entry");
21+
App.Tap("Issue26792Entry");
22+
App.WaitForElement("Issue26792Button");
23+
App.Tap("Issue26792Button");
24+
App.WaitForElement("Issue26792Entry");
25+
Assert.That(App.IsKeyboardShown(), Is.False);
26+
27+
}
28+
}
29+
#endif

0 commit comments

Comments
 (0)