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
@@ -32,39 +30,45 @@ namespace Uno.Toolkit.UI
32
30
public static class InputExtensions
33
31
{
34
32
private static readonly ILogger _logger = typeof ( InputExtensions ) . Log ( ) ;
35
-
36
- public enum ReturnType {
37
- Default ,
38
- Done ,
39
- Go ,
40
- Next ,
41
- Search ,
42
- Send
43
- }
44
-
45
33
#region DependencyProperty: ReturnType
46
34
35
+ #if HAS_UNO_WINUI
47
36
/// <summary>
48
37
/// Backing property for what type of return the soft keyboard will show.
49
38
/// </summary>
50
- public static DependencyProperty ReturnTypeProperty { [ DynamicDependency ( nameof ( GetReturnType ) ) ] get ; } = DependencyProperty . RegisterAttached (
51
- "ReturnType" ,
52
- typeof ( ReturnType ) ,
53
- typeof ( InputExtensions ) ,
54
- new PropertyMetadata ( ReturnType . Default , OnReturnTypeChanged ) ) ;
39
+ public static DependencyProperty ReturnTypeProperty { get ; } =
40
+ DependencyProperty . RegisterAttached (
41
+ "ReturnType" ,
42
+ typeof ( InputReturnType ) ,
43
+ typeof ( InputExtensions ) ,
44
+ new PropertyMetadata ( InputReturnType . Default , OnReturnTypeChanged ) ) ;
45
+
46
+ public static InputReturnType GetReturnType ( DependencyObject obj ) =>
47
+ ( InputReturnType ) obj . GetValue ( ReturnTypeProperty ) ;
55
48
56
- [ DynamicDependency ( nameof ( SetReturnType ) ) ]
57
- public static ReturnType GetReturnType ( DependencyObject obj ) => ( ReturnType ) obj . GetValue ( ReturnTypeProperty ) ;
58
- [ DynamicDependency ( nameof ( GetReturnType ) ) ]
59
- public static void SetReturnType ( DependencyObject obj , ReturnType value ) => obj . SetValue ( ReturnTypeProperty , value ) ;
49
+ public static void SetReturnType ( DependencyObject obj , InputReturnType value ) =>
50
+ obj . SetValue ( ReturnTypeProperty , value ) ;
51
+
52
+ private static void OnReturnTypeChanged ( DependencyObject sender , DependencyPropertyChangedEventArgs e )
53
+ {
54
+ if ( sender is TextBox || sender is PasswordBox )
55
+ {
56
+ TextBoxExtensions . SetInputReturnType ( sender , ( InputReturnType ) e . NewValue ) ;
57
+ }
58
+ }
59
+ #endif
60
60
61
61
#endregion
62
62
#region DependencyProperty: AutoDismiss
63
63
64
64
/// <summary>
65
65
/// Backing property for whether the soft keyboard will be dismissed when the enter key is pressed.
66
66
/// </summary>
67
- public static DependencyProperty AutoDismissProperty { [ DynamicDependency ( nameof ( GetAutoDismiss ) ) ] get ; } = DependencyProperty . RegisterAttached (
67
+ public static DependencyProperty AutoDismissProperty
68
+ {
69
+ [ DynamicDependency ( nameof ( GetAutoDismiss ) ) ]
70
+ get ;
71
+ } = DependencyProperty . RegisterAttached (
68
72
"AutoDismiss" ,
69
73
typeof ( bool ) ,
70
74
typeof ( InputExtensions ) ,
@@ -85,16 +89,22 @@ public enum ReturnType {
85
89
/// Having either or both of the <see cref="AutoFocusNextProperty"/> and <see cref="AutoFocusNextElementProperty"/> set will enable the focus next behavior.
86
90
/// AutoFocusNextElement will take precedences over AutoFocusNext when both are set.
87
91
/// </remarks>
88
- public static DependencyProperty AutoFocusNextProperty { [ DynamicDependency ( nameof ( GetAutoFocusNext ) ) ] get ; } = DependencyProperty . RegisterAttached (
92
+ public static DependencyProperty AutoFocusNextProperty
93
+ {
94
+ [ DynamicDependency ( nameof ( GetAutoFocusNext ) ) ]
95
+ get ;
96
+ } = DependencyProperty . RegisterAttached (
89
97
"AutoFocusNext" ,
90
98
typeof ( bool ) ,
91
99
typeof ( InputExtensions ) ,
92
100
new PropertyMetadata ( default ( bool ) , OnAutoFocusNextChanged ) ) ;
93
101
94
102
[ DynamicDependency ( nameof ( SetAutoFocusNext ) ) ]
95
103
public static bool GetAutoFocusNext ( DependencyObject obj ) => ( bool ) obj . GetValue ( AutoFocusNextProperty ) ;
104
+
96
105
[ DynamicDependency ( nameof ( GetAutoFocusNext ) ) ]
97
- public static void SetAutoFocusNext ( DependencyObject obj , bool value ) => obj . SetValue ( AutoFocusNextProperty , value ) ;
106
+ public static void SetAutoFocusNext ( DependencyObject obj , bool value ) =>
107
+ obj . SetValue ( AutoFocusNextProperty , value ) ;
98
108
99
109
#endregion
100
110
#region DependencyProperty: AutoFocusNextElement
@@ -106,16 +116,23 @@ public enum ReturnType {
106
116
/// Having either or both of the <see cref="AutoFocusNextProperty"/> and <see cref="AutoFocusNextElementProperty"/> set will enable the focus next behavior.
107
117
/// AutoFocusNextElement will take precedences over AutoFocusNext when both are set.
108
118
/// </remarks>
109
- public static DependencyProperty AutoFocusNextElementProperty { [ DynamicDependency ( nameof ( GetAutoFocusNextElement ) ) ] get ; } = DependencyProperty . RegisterAttached (
119
+ public static DependencyProperty AutoFocusNextElementProperty
120
+ {
121
+ [ DynamicDependency ( nameof ( GetAutoFocusNextElement ) ) ]
122
+ get ;
123
+ } = DependencyProperty . RegisterAttached (
110
124
"AutoFocusNextElement" ,
111
125
typeof ( DependencyObject ) ,
112
126
typeof ( InputExtensions ) ,
113
127
new PropertyMetadata ( default ( Control ) , OnAutoFocusNextElementChanged ) ) ;
114
128
115
129
[ DynamicDependency ( nameof ( SetAutoFocusNextElement ) ) ]
116
- public static Control GetAutoFocusNextElement ( DependencyObject obj ) => ( Control ) obj . GetValue ( AutoFocusNextElementProperty ) ;
130
+ public static Control GetAutoFocusNextElement ( DependencyObject obj ) =>
131
+ ( Control ) obj . GetValue ( AutoFocusNextElementProperty ) ;
132
+
117
133
[ DynamicDependency ( nameof ( GetAutoFocusNextElement ) ) ]
118
- public static void SetAutoFocusNextElement ( DependencyObject obj , Control value ) => obj . SetValue ( AutoFocusNextElementProperty , value ) ;
134
+ public static void SetAutoFocusNextElement ( DependencyObject obj , Control value ) =>
135
+ obj . SetValue ( AutoFocusNextElementProperty , value ) ;
119
136
120
137
#endregion
121
138
#if false // The property is now forwarded from CommandExtensions.Command
@@ -141,44 +158,17 @@ 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 ) ;
161
+ private static void OnAutoDismissChanged ( DependencyObject sender , DependencyPropertyChangedEventArgs e )
162
+ => UpdateSubscription ( sender ) ;
154
163
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 ) ;
164
+ private static void OnAutoFocusNextChanged ( DependencyObject sender , DependencyPropertyChangedEventArgs e )
165
+ => UpdateSubscription ( sender ) ;
165
166
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
- }
167
+ private static void OnAutoFocusNextElementChanged ( DependencyObject sender , DependencyPropertyChangedEventArgs e )
168
+ => UpdateSubscription ( sender ) ;
177
169
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 ) ;
170
+ internal static void OnEnterCommandChanged ( DependencyObject sender , DependencyPropertyChangedEventArgs e )
171
+ => UpdateSubscription ( sender ) ;
182
172
183
173
private static void UpdateSubscription ( DependencyObject sender )
184
174
{
@@ -243,29 +233,5 @@ private static void OnUIElementKeyUp(object sender, KeyRoutedEventArgs e)
243
233
_ => default ,
244
234
} ;
245
235
}
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
236
}
271
237
}
0 commit comments