Skip to content

Commit 7c1ec70

Browse files
committed
feat: switch InputExtensions.ReturnType to InputReturnType
1 parent 5c11fc1 commit 7c1ec70

File tree

3 files changed

+56
-90
lines changed

3 files changed

+56
-90
lines changed

doc/helpers/Input-extensions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Provides various attached properties for _input controls_, such as `TextBox` and
1313
| `AutoDismiss` | `bool` | Whether the soft keyboard will be dismissed when the enter key is pressed. |
1414
| `AutoFocusNext` | `bool` | Whether the focus will move to the next focusable element when the enter key is pressed.\* |
1515
| `AutoFocusNextElement` | `Control` | Sets the next control to focus when the enter key is pressed.\* |
16-
| `ReturnType` | `ReturnType` | The type of return button on a soft keyboard for Android/iOS. It can be one of the following options: __Default, Done, Go, Next, Search, Send__. |
16+
| `ReturnType` | `InputReturnType` | The type of return button on a soft keyboard for Android/iOS. It can be one of the following options: __Default, Done, Go, Next, Search, Send__. |
1717

1818
`AutoFocusNext` and `AutoFocusNextElement`\*: Having either or both of the two properties set will enable the focus next behavior. `AutoFocusNextElement` will take precedence over `AutoFocusNext` when both are set.
1919

src/Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<PackageVersion Include="Uno.Material" Version="5.0.13" />
2424
<PackageVersion Include="Uno.Material.WinUI" Version="5.0.13" />
2525
<PackageVersion Include="Uno.UI" Version="5.4.22" />
26-
<PackageVersion Include="Uno.WinUI" Version="5.4.22" />
26+
<PackageVersion Include="Uno.WinUI" Version="6.0.465" />
2727
<PackageVersion Include="Uno.XamlMerge.Task" Version="1.32.0-dev.61" />
2828
<PackageVersion Include="FluentAssertions" Version="5.10.3" />
2929
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />

src/Uno.Toolkit.UI/Behaviors/InputExtensions.cs

Lines changed: 54 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
using Windows.System;
1212
using Windows.UI.ViewManagement;
1313

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;
1816
#endif
1917

2018
#if IS_WINUI
@@ -32,39 +30,45 @@ namespace Uno.Toolkit.UI
3230
public static class InputExtensions
3331
{
3432
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-
4533
#region DependencyProperty: ReturnType
4634

35+
#if HAS_UNO_WINUI
4736
/// <summary>
4837
/// Backing property for what type of return the soft keyboard will show.
4938
/// </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);
5548

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
6060

6161
#endregion
6262
#region DependencyProperty: AutoDismiss
6363

6464
/// <summary>
6565
/// Backing property for whether the soft keyboard will be dismissed when the enter key is pressed.
6666
/// </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(
6872
"AutoDismiss",
6973
typeof(bool),
7074
typeof(InputExtensions),
@@ -85,16 +89,22 @@ public enum ReturnType {
8589
/// Having either or both of the <see cref="AutoFocusNextProperty"/> and <see cref="AutoFocusNextElementProperty"/> set will enable the focus next behavior.
8690
/// AutoFocusNextElement will take precedences over AutoFocusNext when both are set.
8791
/// </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(
8997
"AutoFocusNext",
9098
typeof(bool),
9199
typeof(InputExtensions),
92100
new PropertyMetadata(default(bool), OnAutoFocusNextChanged));
93101

94102
[DynamicDependency(nameof(SetAutoFocusNext))]
95103
public static bool GetAutoFocusNext(DependencyObject obj) => (bool)obj.GetValue(AutoFocusNextProperty);
104+
96105
[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);
98108

99109
#endregion
100110
#region DependencyProperty: AutoFocusNextElement
@@ -106,16 +116,23 @@ public enum ReturnType {
106116
/// Having either or both of the <see cref="AutoFocusNextProperty"/> and <see cref="AutoFocusNextElementProperty"/> set will enable the focus next behavior.
107117
/// AutoFocusNextElement will take precedences over AutoFocusNext when both are set.
108118
/// </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(
110124
"AutoFocusNextElement",
111125
typeof(DependencyObject),
112126
typeof(InputExtensions),
113127
new PropertyMetadata(default(Control), OnAutoFocusNextElementChanged));
114128

115129
[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+
117133
[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);
119136

120137
#endregion
121138
#if false // The property is now forwarded from CommandExtensions.Command
@@ -141,44 +158,17 @@ internal static bool IsEnterCommandSupportedFor(DependencyObject host)
141158
return host is TextBox || host is PasswordBox;
142159
}
143160

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);
154163

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);
165166

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);
177169

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);
182172

183173
private static void UpdateSubscription(DependencyObject sender)
184174
{
@@ -243,29 +233,5 @@ private static void OnUIElementKeyUp(object sender, KeyRoutedEventArgs e)
243233
_ => default,
244234
};
245235
}
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
270236
}
271237
}

0 commit comments

Comments
 (0)