|
| 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