|
11 | 11 | using Windows.System;
|
12 | 12 | using Windows.UI.ViewManagement;
|
13 | 13 |
|
14 |
| -#if __ANDROID__ |
15 |
| -using Android.Views.InputMethods; |
16 |
| -#elif __IOS__ |
17 |
| -using UIKit; |
| 14 | +#if HAS_UNO_WINUI |
| 15 | +using Uno.UI.Xaml.Controls; |
18 | 16 | #endif
|
19 | 17 |
|
20 | 18 | #if IS_WINUI
|
|
27 | 25 | using Windows.UI.Xaml.Input;
|
28 | 26 | #endif
|
29 | 27 |
|
| 28 | +#if !HAS_UNO_WINUI |
| 29 | +namespace Uno.Toolkit.UI |
| 30 | +{ |
| 31 | + |
| 32 | + // Dummy enum for Uno.UI v5 so ReturnType DP compiles as InputReturnType is available for v6+. |
| 33 | + public enum InputReturnType |
| 34 | + { |
| 35 | + Default, |
| 36 | + Done, |
| 37 | + Go, |
| 38 | + Next, |
| 39 | + Search, |
| 40 | + Send |
| 41 | + } |
| 42 | +} |
| 43 | +#endif |
| 44 | + |
30 | 45 | namespace Uno.Toolkit.UI
|
31 | 46 | {
|
32 | 47 | public static class InputExtensions
|
33 | 48 | {
|
34 | 49 | private static readonly ILogger _logger = typeof(InputExtensions).Log();
|
35 | 50 |
|
36 |
| - public enum ReturnType { |
37 |
| - Default, |
38 |
| - Done, |
39 |
| - Go, |
40 |
| - Next, |
41 |
| - Search, |
42 |
| - Send |
43 |
| - } |
44 |
| - |
45 | 51 | #region DependencyProperty: ReturnType
|
46 | 52 |
|
47 | 53 | /// <summary>
|
48 | 54 | /// Backing property for what type of return the soft keyboard will show.
|
49 | 55 | /// </summary>
|
50 | 56 | public static DependencyProperty ReturnTypeProperty { [DynamicDependency(nameof(GetReturnType))] get; } = DependencyProperty.RegisterAttached(
|
51 |
| - "ReturnType", |
52 |
| - typeof(ReturnType), |
53 |
| - typeof(InputExtensions), |
54 |
| - new PropertyMetadata(ReturnType.Default, OnReturnTypeChanged)); |
| 57 | + "ReturnType", |
| 58 | + typeof(InputReturnType), |
| 59 | + typeof(InputExtensions), |
| 60 | + new PropertyMetadata(InputReturnType.Default, OnReturnTypeChanged)); |
55 | 61 |
|
56 | 62 | [DynamicDependency(nameof(SetReturnType))]
|
57 |
| - public static ReturnType GetReturnType(DependencyObject obj) => (ReturnType)obj.GetValue(ReturnTypeProperty); |
| 63 | + public static InputReturnType GetReturnType(DependencyObject obj) => (InputReturnType)obj.GetValue(ReturnTypeProperty); |
58 | 64 | [DynamicDependency(nameof(GetReturnType))]
|
59 |
| - public static void SetReturnType(DependencyObject obj, ReturnType value) => obj.SetValue(ReturnTypeProperty, value); |
| 65 | + public static void SetReturnType(DependencyObject obj, InputReturnType value) => obj.SetValue(ReturnTypeProperty, value); |
60 | 66 |
|
61 | 67 | #endregion
|
| 68 | + |
| 69 | + private static void OnReturnTypeChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
| 70 | + { |
| 71 | +#if HAS_UNO_WINUI |
| 72 | + if (sender is TextBox || sender is PasswordBox) |
| 73 | + { |
| 74 | + TextBoxExtensions.SetInputReturnType(sender, (InputReturnType)e.NewValue); |
| 75 | + } |
| 76 | +#endif |
| 77 | + } |
| 78 | + |
62 | 79 | #region DependencyProperty: AutoDismiss
|
63 | 80 |
|
64 |
| - /// <summary> |
65 |
| - /// Backing property for whether the soft keyboard will be dismissed when the enter key is pressed. |
66 |
| - /// </summary> |
| 81 | + /// <summary> |
| 82 | + /// Backing property for whether the soft keyboard will be dismissed when the enter key is pressed. |
| 83 | + /// </summary> |
67 | 84 | public static DependencyProperty AutoDismissProperty { [DynamicDependency(nameof(GetAutoDismiss))] get; } = DependencyProperty.RegisterAttached(
|
68 | 85 | "AutoDismiss",
|
69 | 86 | typeof(bool),
|
@@ -141,44 +158,14 @@ internal static bool IsEnterCommandSupportedFor(DependencyObject host)
|
141 | 158 | return host is TextBox || host is PasswordBox;
|
142 | 159 | }
|
143 | 160 |
|
144 |
| - private static void OnReturnTypeChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
145 |
| - { |
146 |
| - if (sender is TextBox || sender is PasswordBox) |
147 |
| - { |
148 |
| - if (e.NewValue is not ReturnType returnType) |
149 |
| - { |
150 |
| - returnType = ReturnType.Default; |
151 |
| - } |
152 |
| -#if __ANDROID__ |
153 |
| - ImeAction imeAction = GetImeActionFromReturnType(returnType); |
154 |
| - |
155 |
| - if (sender is TextBox textBox) |
156 |
| - { |
157 |
| - textBox.ImeOptions = imeAction; |
158 |
| - } |
159 |
| - else if (sender is PasswordBox passwordBox) |
160 |
| - { |
161 |
| - passwordBox.ImeOptions = imeAction; |
162 |
| - } |
163 |
| -#elif __IOS__ |
164 |
| - UIReturnKeyType returnKeyType = GetReturnKeyTypeFromReturnType(returnType); |
165 |
| - |
166 |
| - if (sender is TextBox textBox) |
167 |
| - { |
168 |
| - textBox.ReturnKeyType = returnKeyType; |
169 |
| - } |
170 |
| - else if (sender is PasswordBox passwordBox) |
171 |
| - { |
172 |
| - passwordBox.ReturnKeyType = returnKeyType; |
173 |
| - } |
174 |
| -#endif |
175 |
| - } |
176 |
| - } |
177 |
| - |
178 |
| - private static void OnAutoDismissChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) => UpdateSubscription(sender); |
179 |
| - private static void OnAutoFocusNextChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) => UpdateSubscription(sender); |
180 |
| - private static void OnAutoFocusNextElementChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) => UpdateSubscription(sender); |
181 |
| - internal static void OnEnterCommandChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) => UpdateSubscription(sender); |
| 161 | + private static void OnAutoDismissChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
| 162 | + => UpdateSubscription(sender); |
| 163 | + private static void OnAutoFocusNextChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
| 164 | + => UpdateSubscription(sender); |
| 165 | + private static void OnAutoFocusNextElementChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
| 166 | + => UpdateSubscription(sender); |
| 167 | + internal static void OnEnterCommandChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
| 168 | + => UpdateSubscription(sender); |
182 | 169 |
|
183 | 170 | private static void UpdateSubscription(DependencyObject sender)
|
184 | 171 | {
|
@@ -243,29 +230,5 @@ private static void OnUIElementKeyUp(object sender, KeyRoutedEventArgs e)
|
243 | 230 | _ => default,
|
244 | 231 | };
|
245 | 232 | }
|
246 |
| - |
247 |
| -#if __ANDROID__ |
248 |
| - private static ImeAction GetImeActionFromReturnType(ReturnType returnType) => returnType switch |
249 |
| - { |
250 |
| - ReturnType.Next => ImeAction.Next, |
251 |
| - ReturnType.Go => ImeAction.Go, |
252 |
| - ReturnType.Search => ImeAction.Search, |
253 |
| - ReturnType.Send => ImeAction.Send, |
254 |
| - ReturnType.Done => ImeAction.Done, |
255 |
| - ReturnType.Default or _ => ImeAction.Unspecified |
256 |
| - }; |
257 |
| -#endif |
258 |
| - |
259 |
| -#if __IOS__ |
260 |
| - private static UIReturnKeyType GetReturnKeyTypeFromReturnType(ReturnType returnType) => returnType switch |
261 |
| - { |
262 |
| - ReturnType.Next => UIReturnKeyType.Next, |
263 |
| - ReturnType.Go => UIReturnKeyType.Go, |
264 |
| - ReturnType.Search => UIReturnKeyType.Search, |
265 |
| - ReturnType.Send => UIReturnKeyType.Send, |
266 |
| - ReturnType.Done => UIReturnKeyType.Done, |
267 |
| - ReturnType.Default or _ => UIReturnKeyType.Default |
268 |
| - }; |
269 |
| -#endif |
270 | 233 | }
|
271 | 234 | }
|
0 commit comments