Skip to content

Commit

Permalink
fix: Adjust InputScope on iOS and implement for Wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Sep 21, 2021
1 parent e5fea16 commit 7a28cd2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/InputScopeHelper.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal static class InputScopeHelper
{
public static UITextAutocapitalizationType ConvertInputScopeToCapitalization(InputScope value)
{
switch (GetInputScopeName(value))
switch (value.GetFirstInputScopeNameValue())
{
case InputScopeNameValue.PersonalFullName:
return UITextAutocapitalizationType.Sentences;
Expand All @@ -25,14 +25,21 @@ public static UITextAutocapitalizationType ConvertInputScopeToCapitalization(Inp

public static UIKeyboardType ConvertInputScopeToKeyboardType(InputScope value)
{
switch (GetInputScopeName(value) ?? InputScopeNameValue.Default)
switch (value.GetFirstInputScopeNameValue())
{
default:
return UIKeyboardType.Default;

case InputScopeNameValue.Number:
case InputScopeNameValue.DateDayNumber:
case InputScopeNameValue.DateMonthNumber:
case InputScopeNameValue.DateYear:
case InputScopeNameValue.Digits:
return UIKeyboardType.NumberPad;

case InputScopeNameValue.NameOrPhoneNumber:
return UIKeyboardType.NamePhonePad;

case InputScopeNameValue.NumberFullWidth:
case InputScopeNameValue.NumericPin:
return UIKeyboardType.NumbersAndPunctuation;
Expand All @@ -47,17 +54,14 @@ public static UIKeyboardType ConvertInputScopeToKeyboardType(InputScope value)
return UIKeyboardType.PhonePad;

case InputScopeNameValue.Search:
return UIKeyboardType.Default;
return UIKeyboardType.WebSearch;

case InputScopeNameValue.EmailNameOrAddress:
case InputScopeNameValue.EmailSmtpAddress:
return UIKeyboardType.EmailAddress;
}
}

private static InputScopeNameValue? GetInputScopeName(InputScope value)
=> value?.Names?.FirstOrDefault()?.NameValue;

public static InputScopeNameValue ConvertInputScope(UIKeyboardType keyboardType)
{
switch (keyboardType)
Expand Down
10 changes: 10 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,20 @@ partial void OnIsReadonlyChangedPartial(DependencyPropertyChangedEventArgs e)
}
}

partial void OnInputScopeChangedPartial(DependencyPropertyChangedEventArgs e)
{
if (e.NewValue is InputScope scope)
{
ApplyInputScope(scope);
}
}

private void ApplyEnabled(bool? isEnabled = null) => _textBoxView?.SetEnabled(isEnabled ?? IsEnabled);

private void ApplyIsReadonly(bool? isReadOnly = null) => _textBoxView?.SetIsReadOnly(isReadOnly ?? IsReadOnly);

private void ApplyInputScope(InputScope scope) => _textBoxView?.SetInputScope(scope);

partial void SelectPartial(int start, int length)
{
_textBoxView?.Select(start, length);
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Controls/TextBox/TextBoxView.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ internal void SetInputScope(InputScope scope)
InputScopeNameValue.Search => "search",
InputScopeNameValue.SearchIncremental => "search",

InputScopeNameValue.EmailNameOrAddresso => "email",
InputScopeNameValue.EmailNameOrAddress => "email",
InputScopeNameValue.EmailSmtpAddress => "email",

InputScopeNameValue.Url => "url",
Expand Down

0 comments on commit 7a28cd2

Please sign in to comment.