-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
HideSoftInputOnTappedPage.cs
96 lines (84 loc) · 2.48 KB
/
HideSoftInputOnTappedPage.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Platform;
namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.None, 12003, "Hide Soft Input On Tapped Page",
PlatformAffected.iOS | PlatformAffected.Android)]
public class HideSoftInputOnTappedPage : TestContentPage
{
public HideSoftInputOnTappedPage()
{
}
protected override void Init()
{
Content = new VerticalStackLayout()
{
new Button()
{
Text = "Test HideSoftInputOnTapped: false",
Command = new Command(async () =>
{
await Navigation.PushAsync(new TestPage(false));
}),
AutomationId = "HideSoftInputOnTappedFalse"
},
new Button()
{
Text = "Test HideSoftInputOnTapped: true",
Command = new Command(async () =>
{
await Navigation.PushAsync(new TestPage(true));
}),
AutomationId = "HideSoftInputOnTappedTrue"
}
};
(Content as VerticalStackLayout).Spacing = 6;
}
public class TestPage : ContentPage
{
Label _isKeyboardOpen = new Label();
public TestPage(bool hideSoftInputOnTapped)
{
this.HideSoftInputOnTapped = hideSoftInputOnTapped;
Title = "Hide Soft Input On Tapped Page";
_isKeyboardOpen.Text = "Tap Page and Keyboard Should Close";
_isKeyboardOpen.AutomationId = "EmptySpace";
Entry entry = new Entry() { AutomationId = "Entry" };
var checkbox = new CheckBox();
checkbox.BindingContext = this;
checkbox.SetBinding(
CheckBox.IsCheckedProperty,
nameof(HideSoftInputOnTapped));
checkbox.AutomationId = "ToggleHideSoftInputOnTapped";
Entry dontHideKeyboardWhenTappingPage = new Entry()
{
Placeholder = "When this entry is focused tapping the page won't close the keyboard",
AutomationId = "DontHideKeyboardWhenTappingPage"
};
dontHideKeyboardWhenTappingPage
.Focused += (_, _) => checkbox.IsChecked = false;
Entry hideKeyboardWhenTappingPage = new Entry()
{
Placeholder = "When this entry is focused tapping the page will close the keyboard",
AutomationId = "HideKeyboardWhenTappingPage"
};
hideKeyboardWhenTappingPage
.Focused += (_, _) => checkbox.IsChecked = true;
Content = new VerticalStackLayout()
{
new HorizontalStackLayout()
{
checkbox,
_isKeyboardOpen
},
entry,
new Editor() { AutomationId = "Editor" },
new SearchBar() { AutomationId = "SearchBar" },
dontHideKeyboardWhenTappingPage,
hideKeyboardWhenTappingPage
};
}
}
}
}