Skip to content

Commit 3c540e3

Browse files
committed
feat!: switch InputExtensions.ReturnType to InputReturnType
BREAKING CHANGE: Uno dependency has been bumped to 6.0 and the InputExtensions.ReturnType has been changed to InputReturnType.
1 parent 5a6230b commit 3c540e3

File tree

6 files changed

+74
-87
lines changed

6 files changed

+74
-87
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

doc/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# ******************* Overview *******************
22
- name: Overview
33
href: getting-started.md
4+
- name: Upgrading Toolkit
5+
href: Toolkit.Migration.md
46
items:
57
# ***************** Material *******************
68
- name: Material

doc/uno-toolkit-migration.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
uid: Toolkit.Migration
3+
---
4+
5+
# Upgrading Uno Toolkit
6+
7+
## Upgrading to Uno Toolkit 7.1
8+
9+
1. Switch from `ReturnType` to `InputReturnType`
10+
11+
Version 7.1 of `Uno.Toolkit` now requires `Uno.UI v6.0`. The `InputExtensions` helper has been updated to use the built-in `InputReturnType` enum (provided by Uno.UI v6+) instead of the legacy `ReturnType` enum.
12+
13+
```csharp
14+
// No code changes required in XAML, but under the hood
15+
// the attached property now uses InputReturnType:
16+
public static DependencyProperty ReturnTypeProperty =
17+
DependencyProperty.RegisterAttached(
18+
"ReturnType",
19+
typeof(InputReturnType),
20+
typeof(InputExtensions),
21+
new PropertyMetadata(InputReturnType.Default, OnReturnTypeChanged));
22+
```

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: 47 additions & 84 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
@@ -27,43 +25,62 @@
2725
using Windows.UI.Xaml.Input;
2826
#endif
2927

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+
3045
namespace Uno.Toolkit.UI
3146
{
3247
public static class InputExtensions
3348
{
3449
private static readonly ILogger _logger = typeof(InputExtensions).Log();
3550

36-
public enum ReturnType {
37-
Default,
38-
Done,
39-
Go,
40-
Next,
41-
Search,
42-
Send
43-
}
44-
4551
#region DependencyProperty: ReturnType
4652

4753
/// <summary>
4854
/// Backing property for what type of return the soft keyboard will show.
4955
/// </summary>
5056
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));
5561

5662
[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);
5864
[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);
6066

6167
#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+
6279
#region DependencyProperty: AutoDismiss
6380

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>
6784
public static DependencyProperty AutoDismissProperty { [DynamicDependency(nameof(GetAutoDismiss))] get; } = DependencyProperty.RegisterAttached(
6885
"AutoDismiss",
6986
typeof(bool),
@@ -141,44 +158,14 @@ 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);
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);
182169

183170
private static void UpdateSubscription(DependencyObject sender)
184171
{
@@ -243,29 +230,5 @@ private static void OnUIElementKeyUp(object sender, KeyRoutedEventArgs e)
243230
_ => default,
244231
};
245232
}
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
270233
}
271234
}

src/Uno.Toolkit.UI/Controls/ExtendedSplashScreen/ExtendedSplashScreen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ internal object SplashScreenContent
5858
protected static ExtendedSplashScreen? Instance { get; private set; }
5959

6060
public
61-
#if __IOS__ || __MACOS__ // hides UIView.Window and NSView.Window
61+
#if __IOS__ || __MACOS__ && !HAS_UNO_WINUI // hides UIView.Window and NSView.Window
6262
new
6363
#endif
6464
Window? Window

0 commit comments

Comments
 (0)