Skip to content

Commit a162c97

Browse files
committed
feat: Initiate TextBox with keyboard and autofill integration
1 parent c5bbad3 commit a162c97

13 files changed

+418
-225
lines changed

src/Uno.UI.Runtime.Skia.Android/AndroidInvisibleTextBoxViewExtension.cs

Lines changed: 0 additions & 212 deletions
This file was deleted.

src/Uno.UI.Runtime.Skia.Android/AndroidKeyboardInputSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal bool OnNativeKeyEvent(KeyEvent e)
3535
try
3636
{
3737
var isDown = e.Action == KeyEventActions.Down;
38-
var args = new KeyEventArgs("keyboard", virtualKey, modifiers, default(CorePhysicalKeyStatus)/*TODO*/, unicodeKey: null/*TODO*/);
38+
var args = new KeyEventArgs("keyboard", virtualKey, modifiers, default(CorePhysicalKeyStatus)/*TODO*/, unicodeKey: (char)e.GetUnicodeChar(e.MetaState));
3939
if (isDown)
4040
{
4141
KeyDown?.Invoke(this, args);

src/Uno.UI.Runtime.Skia.Android/AndroidSkiaHost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public Task Run()
3434
ApiExtensibility.Register(typeof(INativeWindowFactoryExtension), o => new AndroidSkiaWindowFactory());
3535
ApiExtensibility.Register(typeof(IUnoCorePointerInputSource), o => AndroidCorePointerInputSource.Instance);
3636
ApiExtensibility.Register(typeof(IUnoKeyboardInputSource), o => AndroidKeyboardInputSource.Instance);
37-
ApiExtensibility.Register<TextBoxView>(typeof(IOverlayTextBoxViewExtension), o => new AndroidInvisibleTextBoxViewExtension(o));
37+
ApiExtensibility.Register(typeof(ITextBoxNotificationsProviderSingleton), _ => AndroidSkiaTextBoxNotificationsProviderSingleton.Instance);
3838
ApiExtensibility.Register<ContentPresenter>(typeof(ContentPresenter.INativeElementHostingExtension), o => new AndroidSkiaNativeElementHostingExtension(o));
3939
ApiExtensibility.Register<CoreWebView2>(typeof(INativeWebViewProvider), o => new AndroidNativeWebViewProvider(o));
4040
ApiExtensibility.Register(typeof(ISkiaNativeDatePickerProviderExtension), _ => new AndroidSkiaDatePickerProvider());
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System.Collections.Generic;
2+
using System.Runtime.InteropServices;
3+
using Android.Text;
4+
using Microsoft.UI.Xaml.Controls;
5+
using Uno.UI.Xaml.Controls.Extensions;
6+
7+
namespace Uno.UI.Runtime.Skia.Android;
8+
9+
internal sealed class AndroidSkiaTextBoxNotificationsProviderSingleton : ITextBoxNotificationsProviderSingleton
10+
{
11+
internal List<TextBox> LiveTextBoxes { get; } = new();
12+
internal Dictionary<int, TextBox> LiveTextBoxesMap { get; } = new();
13+
14+
public static AndroidSkiaTextBoxNotificationsProviderSingleton Instance { get; } = new AndroidSkiaTextBoxNotificationsProviderSingleton();
15+
16+
private AndroidSkiaTextBoxNotificationsProviderSingleton()
17+
{
18+
}
19+
20+
public void OnFocused(TextBox textBox)
21+
{
22+
if (UnoSKCanvasView.Instance is { } canvasView)
23+
{
24+
canvasView.TextInputPlugin.ShowTextInput(InputTypes.TextVariationNormal/*TODO: Properly provide this based on textBox.InputScope. This should also respect AcceptsReturn and IsSpellCheckEnabled*/);
25+
canvasView.TextInputPlugin.NotifyViewEntered(textBox, textBox.GetHashCode());
26+
}
27+
}
28+
29+
public void OnUnfocused(TextBox textBox)
30+
{
31+
if (UnoSKCanvasView.Instance is { } canvasView)
32+
{
33+
canvasView.TextInputPlugin.HideTextInput();
34+
canvasView.TextInputPlugin.NotifyViewExited(textBox.GetHashCode());
35+
}
36+
}
37+
38+
public void OnEnteredVisualTree(TextBox textBox)
39+
{
40+
LiveTextBoxes.Add(textBox);
41+
LiveTextBoxesMap.Add(textBox.GetHashCode(), textBox);
42+
}
43+
44+
public void OnLeaveVisualTree(TextBox textBox)
45+
{
46+
LiveTextBoxes.Remove(textBox);
47+
LiveTextBoxesMap.Remove(textBox.GetHashCode());
48+
}
49+
50+
public void FinishAutofillContext(bool shouldSave)
51+
{
52+
if (UnoSKCanvasView.Instance is { } canvasView)
53+
{
54+
canvasView.TextInputPlugin.FinishAutofillContext(shouldSave);
55+
}
56+
}
57+
58+
public void NotifyValueChanged(TextBox textBox)
59+
{
60+
if (UnoSKCanvasView.Instance is { } canvasView)
61+
{
62+
canvasView.TextInputPlugin.NotifyValueChanged(textBox.GetHashCode(), textBox.Text);
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)