Skip to content

Commit 22fab2d

Browse files
drasticactionsPureWeenrachelkang
authored
Import Keyboard Extension APIs (#16572)
* Import Keyboard Extension APIs * Tizen... * Test * Fix API * API * Fix original tests * Add Soft Input buttons to entry page * Start adding tests * Update test * Update src/Core/src/Platform/KeyboardExtensions.cs Co-authored-by: Shane Neuville <[email protected]> * Apply suggestions from code review Co-authored-by: Rachel Kang <[email protected]> * Apply suggestions from code review Co-authored-by: Rachel Kang <[email protected]> * Move namespaces/files * API * Internal Compatibility update * More fixes --------- Co-authored-by: Shane Neuville <[email protected]> Co-authored-by: Rachel Kang <[email protected]>
1 parent 86b71e1 commit 22fab2d

File tree

33 files changed

+481
-142
lines changed

33 files changed

+481
-142
lines changed

src/Compatibility/Core.LegacyRenderers/Android/Cells/EntryCellView.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ bool TextView.IOnEditorActionListener.OnEditorAction(TextView v, ImeAction actio
8282
{
8383
OnKeyboardDoneButtonPressed(EditText, EventArgs.Empty);
8484
EditText.ClearFocus();
85-
v.HideKeyboard();
85+
v.HideSoftInput();
8686
}
8787

8888
// Fire Completed and dismiss keyboard for hardware / physical keyboards
8989
if (actionId == ImeAction.ImeNull && e.KeyCode == Keycode.Enter)
9090
{
9191
OnKeyboardDoneButtonPressed(EditText, EventArgs.Empty);
9292
EditText.ClearFocus();
93-
v.HideKeyboard();
93+
v.HideSoftInput();
9494
}
9595

9696
return true;

src/Compatibility/Core/src/Android/AppCompat/FormsAppCompatActivity.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ protected override void OnNewIntent(Intent intent)
294294

295295
protected override void OnPause()
296296
{
297-
_layout.HideKeyboard();
297+
_layout.HideSoftInput();
298298

299299
// Stop animations or other ongoing actions that could consume CPU
300300
// Commit unsaved changes, build only if users expect such changes to be permanently saved when thy leave such as a draft email
@@ -327,7 +327,7 @@ protected override void OnResume()
327327

328328
if (_application != null && CurrentFocus != null && _application.OnThisPlatform().GetShouldPreserveKeyboardOnResume())
329329
{
330-
CurrentFocus.ShowKeyboard();
330+
CurrentFocus.ShowSoftInput();
331331
}
332332

333333
_previousState = _currentState;

src/Compatibility/Core/src/Android/PickerManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void OnClick(global::Android.Views.View v)
7979
{
8080
if (v is AView picker)
8181
{
82-
picker.HideKeyboard();
82+
picker.HideSoftInput();
8383
if (picker?.Parent is IPickerRenderer renderer1)
8484
renderer1.OnClick();
8585
else if (picker?.Parent?.Parent?.Parent is IPickerRenderer renderer2)

src/Compatibility/Core/src/Android/Renderers/EditorRenderer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ protected override void OnFocusChangeRequested(object sender, VisualElement.Focu
9393
{
9494
if (!e.Focus)
9595
{
96-
EditText.HideKeyboard();
96+
EditText.HideSoftInput();
9797
}
9898

9999
base.OnFocusChangeRequested(sender, e);
@@ -103,7 +103,7 @@ protected override void OnFocusChangeRequested(object sender, VisualElement.Focu
103103
// Post this to the main looper queue so it doesn't happen until the other focus stuff has resolved
104104
// Otherwise, ShowKeyboard will be called before this control is truly focused, and we will potentially
105105
// be displaying the wrong keyboard
106-
EditText?.PostShowKeyboard();
106+
EditText?.PostShowSoftInput();
107107
}
108108
}
109109

src/Compatibility/Core/src/Android/Renderers/EntryRenderer.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ bool TextView.IOnEditorActionListener.OnEditorAction(TextView v, ImeAction actio
9898
nextFocus.RequestFocus();
9999
if (!nextFocus.OnCheckIsTextEditor())
100100
{
101-
v.HideKeyboard();
101+
v.HideSoftInput();
102102
}
103103
}
104104
else
105105
{
106106
EditText.ClearFocus();
107-
v.HideKeyboard();
107+
v.HideSoftInput();
108108
}
109109

110110
((IEntryController)Element).SendCompleted();
@@ -132,7 +132,7 @@ protected override void OnFocusChangeRequested(object sender, VisualElement.Focu
132132
{
133133
if (!e.Focus)
134134
{
135-
EditText.HideKeyboard();
135+
EditText.HideSoftInput();
136136
}
137137

138138
base.OnFocusChangeRequested(sender, e);
@@ -142,7 +142,7 @@ protected override void OnFocusChangeRequested(object sender, VisualElement.Focu
142142
// Post this to the main looper queue so it doesn't happen until the other focus stuff has resolved
143143
// Otherwise, ShowKeyboard will be called before this control is truly focused, and we will potentially
144144
// be displaying the wrong keyboard
145-
EditText?.PostShowKeyboard();
145+
EditText?.PostShowSoftInput();
146146
}
147147
}
148148

@@ -229,7 +229,7 @@ protected virtual void UpdatePlaceHolderText()
229229
EditText.Hint = Element.Placeholder;
230230
if (EditText.IsFocused)
231231
{
232-
EditText.ShowKeyboard();
232+
EditText.ShowSoftInput();
233233
}
234234
}
235235

@@ -551,7 +551,7 @@ void UpdateText()
551551
if (EditText.IsFocused)
552552
{
553553
EditText.SetSelection(text.Length);
554-
EditText.ShowKeyboard();
554+
EditText.ShowSoftInput();
555555
}
556556
}
557557
}

src/Compatibility/Core/src/Android/Renderers/FormsEditText.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public override bool OnKeyPreIme(Keycode keyCode, KeyEvent e)
2323
return base.OnKeyPreIme(keyCode, e);
2424
}
2525

26-
this.HideKeyboard();
26+
this.HideSoftInput();
2727

2828
_onKeyboardBackPressed?.Invoke(this, EventArgs.Empty);
2929
return true;

src/Compatibility/Core/src/Android/Renderers/SearchBarRenderer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected override void OnFocusChangeRequested(object sender, VisualElement.Focu
6767
{
6868
if (!e.Focus)
6969
{
70-
Control.HideKeyboard();
70+
Control.HideSoftInput();
7171
}
7272

7373
base.OnFocusChangeRequested(sender, e);
@@ -77,7 +77,7 @@ protected override void OnFocusChangeRequested(object sender, VisualElement.Focu
7777
// Post this to the main looper queue so it doesn't happen until the other focus stuff has resolved
7878
// Otherwise, ShowKeyboard will be called before this control is truly focused, and we will potentially
7979
// be displaying the wrong keyboard
80-
Control?.PostShowKeyboard();
80+
Control?.PostShowSoftInput();
8181
}
8282
}
8383

src/Compatibility/Material/src/Android/MaterialFormsEditText.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public override bool OnKeyPreIme(Keycode keyCode, KeyEvent e)
3535
return base.OnKeyPreIme(keyCode, e);
3636
}
3737

38-
this.HideKeyboard();
38+
this.HideSoftInput();
3939

4040
_onKeyboardBackPressed?.Invoke(this, EventArgs.Empty);
4141
return true;
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#nullable enable
2+
using System;
3+
using System.Linq;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
using Microsoft.Maui;
7+
using Microsoft.Maui.Controls;
8+
using Microsoft.Maui.Graphics;
9+
using Microsoft.Maui.Platform;
10+
11+
namespace Maui.Controls.Sample.Issues
12+
{
13+
[Issue(IssueTracker.Github, 11565, "Soft Input Extension Methods", PlatformAffected.All)]
14+
public class SoftInputExtensionsPage : TestContentPage
15+
{
16+
private Entry? basicEntry;
17+
18+
public SoftInputExtensionsPage()
19+
{
20+
}
21+
22+
protected override void Init()
23+
{
24+
Title = "Soft Input Extension Methods";
25+
this.basicEntry = new Entry() { AutomationId = "BasicEntry", Placeholder = "Basic Entry" };
26+
var resultLabel = new Label() { AutomationId = "Result" };
27+
Content = new VerticalStackLayout()
28+
{
29+
new Button()
30+
{
31+
Text = "Show Keyboard",
32+
AutomationId = "ShowKeyboard",
33+
Command = new Command(() => {
34+
this.basicEntry.ShowSoftInputAsync(CancellationToken.None);
35+
SetResultLabel(resultLabel, basicEntry);
36+
})
37+
},
38+
new Button()
39+
{
40+
Text = "Hide Keyboard",
41+
AutomationId = "HideKeyboard",
42+
Command = new Command(() => {
43+
this.basicEntry.HideSoftInputAsync(CancellationToken.None);
44+
SetResultLabel(resultLabel, basicEntry);
45+
})
46+
},
47+
this.basicEntry,
48+
resultLabel
49+
};
50+
}
51+
52+
private async void SetResultLabel(Label resultLabel, ITextInput input)
53+
{
54+
await Task.Delay(1000).ContinueWith(t =>
55+
{
56+
this.Dispatcher.Dispatch(() => {
57+
58+
var isSoftInputShowing = input.IsSoftInputShowing();
59+
60+
#if WINDOWS || MACCATALYST
61+
// Windows has an optional soft keyboard, which may or may not be enabled in CI.
62+
// Catalyst does not have a soft keyboard.
63+
// But the SoftInput extensions still select or deselect the entry.
64+
isSoftInputShowing = ((View)input).IsFocused;
65+
#endif
66+
67+
resultLabel.Text = $"{isSoftInputShowing}";
68+
});
69+
});
70+
}
71+
}
72+
}

src/Controls/samples/Controls.Sample/Pages/Controls/EntryPage.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
<views:BasePage.Content>
4141
<ScrollView>
4242
<VerticalStackLayout Padding="12">
43+
<Button Margin="5" x:Name="ShowSoftInputAsyncButton" Clicked="ShowSoftInputAsyncButton_Clicked" Text="Show Soft Input for Placeholder Button" />
44+
<Button Margin="5" x:Name="HideSoftInputAsyncButton" Clicked="HideSoftInputAsyncButton_Clicked" Text="Hide Soft Input" />
4345
<Label
4446
Text="Basic"
4547
Style="{StaticResource Headline}" />
@@ -66,6 +68,7 @@
6668
Text="With Placeholder"
6769
Style="{StaticResource Headline}" />
6870
<Entry
71+
x:Name="PlaceholderEntryItem"
6972
Placeholder="Placeholder"/>
7073
<Label
7174
Text="Using PlaceholderColor"

0 commit comments

Comments
 (0)