Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new Keyboards for Prompt #20194

Merged
merged 9 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,63 @@
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;

namespace Microsoft.Maui.Controls.Platform
namespace Microsoft.Maui.Controls.Platform;

public sealed class PromptDialog : ContentDialog
{
public sealed class PromptDialog : ContentDialog
public PromptDialog()
{
public PromptDialog()
{
Title = "TITLE";
PrimaryButtonText = "Ok";
SecondaryButtonText = "Cancel";
Title = "TITLE";
PrimaryButtonText = "Ok";
SecondaryButtonText = "Cancel";

Initialize();
}
Initialize();
}

internal TextBlock TextBlockMessage { get; private set; }
internal TextBox TextBoxInput { get; private set; }

public string Message
{
get => TextBlockMessage.Text;
set => TextBlockMessage.Text = value;
}
internal TextBlock TextBlockMessage { get; private set; }
internal MauiPasswordTextBox TextBoxInput { get; private set; }

public string Input
{
get => TextBoxInput.Text;
set => TextBoxInput.Text = value;
}
public string Message
{
get => TextBlockMessage.Text;
set => TextBlockMessage.Text = value;
}

public string Input
{
get => TextBoxInput.Password;
set => TextBoxInput.Password = value;
}

public string Placeholder
{
get => TextBoxInput.PlaceholderText;
set => TextBoxInput.PlaceholderText = value;
}
public string Placeholder
{
get => TextBoxInput.PlaceholderText;
set => TextBoxInput.PlaceholderText = value;
}

public int MaxLength
{
get => TextBoxInput.MaxLength;
set => TextBoxInput.MaxLength = value;
}
public int MaxLength
{
get => TextBoxInput.MaxLength;
set => TextBoxInput.MaxLength = value;
}

public InputScope InputScope
{
get => TextBoxInput.InputScope;
set => TextBoxInput.InputScope = value;
}
public InputScope InputScope
{
get => TextBoxInput.InputScope;
set => TextBoxInput.InputScope = value;
}

void Initialize()
{
var layout = new StackPanel();
void Initialize()
{
var layout = new StackPanel();

TextBlockMessage = new TextBlock { Text = "Message", TextWrapping = UI.Xaml.TextWrapping.Wrap };
TextBoxInput = new TextBox();
TextBlockMessage = new TextBlock { Text = "Message", TextWrapping = UI.Xaml.TextWrapping.Wrap };
TextBoxInput = new MauiPasswordTextBox();

layout.Children.Add(TextBlockMessage);
layout.Children.Add(TextBoxInput);
layout.Children.Add(TextBlockMessage);
layout.Children.Add(TextBoxInput);

Content = layout;
}
Content = layout;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ Microsoft.Maui.Controls.PlatformPointerEventArgs.Sender.get -> Microsoft.UI.Xaml
~static readonly Microsoft.Maui.Controls.ContentPage.HideSoftInputOnTappedProperty -> Microsoft.Maui.Controls.BindableProperty
Microsoft.Maui.Controls.ContentPage.HideSoftInputOnTapped.get -> bool
Microsoft.Maui.Controls.ContentPage.HideSoftInputOnTapped.set -> void

*REMOVED*~Microsoft.Maui.Controls.Editor.FontFamily.get -> string
*REMOVED*~Microsoft.Maui.Controls.Editor.FontFamily.set -> void
*REMOVED*Microsoft.Maui.Controls.Editor.CursorPosition.get -> int
Expand All @@ -219,7 +218,6 @@ Microsoft.Maui.Controls.ContentPage.HideSoftInputOnTapped.set -> void
*REMOVED*Microsoft.Maui.Controls.Editor.FontSize.set -> void
*REMOVED*Microsoft.Maui.Controls.Editor.SelectionLength.get -> int
*REMOVED*Microsoft.Maui.Controls.Editor.SelectionLength.set -> void

*REMOVED*~Microsoft.Maui.Controls.SearchBar.FontFamily.get -> string
*REMOVED*~Microsoft.Maui.Controls.SearchBar.FontFamily.set -> void
*REMOVED*Microsoft.Maui.Controls.SearchBar.CursorPosition.get -> int
Expand All @@ -232,7 +230,6 @@ Microsoft.Maui.Controls.ContentPage.HideSoftInputOnTapped.set -> void
*REMOVED*Microsoft.Maui.Controls.SearchBar.FontSize.set -> void
*REMOVED*Microsoft.Maui.Controls.SearchBar.SelectionLength.get -> int
*REMOVED*Microsoft.Maui.Controls.SearchBar.SelectionLength.set -> void

*REMOVED*~Microsoft.Maui.Controls.Entry.FontFamily.get -> string
*REMOVED*~Microsoft.Maui.Controls.Entry.FontFamily.set -> void
*REMOVED*Microsoft.Maui.Controls.Entry.CursorPosition.get -> int
Expand Down
6 changes: 6 additions & 0 deletions src/Controls/tests/Core.UnitTests/KeyboardTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public void KeyboardTypesAreCorrect()
Assert.True(Keyboard.Telephone is TelephoneKeyboard);
Assert.True(Keyboard.Text is TextKeyboard);
Assert.True(Keyboard.Url is UrlKeyboard);
Assert.True(Keyboard.Date is DateKeyboard);
Assert.True(Keyboard.Time is TimeKeyboard);
Assert.True(Keyboard.Password is PasswordKeyboard);
}
}

Expand All @@ -39,6 +42,9 @@ public void ConversionConvert()
{"Keyboard.Url", Keyboard.Url},
{"Keyboard.Telephone", Keyboard.Telephone},
{"Keyboard.Chat", Keyboard.Chat},
{"Keyboard.Date", Keyboard.Date},
{"Keyboard.Time", Keyboard.Time},
{"Keyboard.Password", Keyboard.Password},
})
Assert.Same(kvp.Value, converter.ConvertFromInvariantString(kvp.Key));
}
Expand Down
6 changes: 6 additions & 0 deletions src/Core/src/Converters/KeyboardTypeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public override object ConvertTo(ITypeDescriptorContext? context, CultureInfo? c
return nameof(Keyboard.Text);
if (keyboard == Keyboard.Url)
return nameof(Keyboard.Url);
if (keyboard == Keyboard.Date)
return nameof(Keyboard.Date);
if (keyboard == Keyboard.Time)
return nameof(Keyboard.Time);
if (keyboard == Keyboard.Password)
return nameof(Keyboard.Password);

throw new NotSupportedException();
}
Expand Down
9 changes: 8 additions & 1 deletion src/Core/src/Platform/Android/KeyboardExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Android.Content;
using System.Xml.Schema;
using Android.Content;
using Android.Text;
using Android.Views;
using Android.Views.InputMethods;
Expand Down Expand Up @@ -26,6 +27,12 @@ public static InputTypes ToInputType(this Keyboard self)
result = InputTypes.ClassPhone;
else if (self == Keyboard.Url)
result = InputTypes.ClassText | InputTypes.TextVariationUri;
else if (self == Keyboard.Date)
result = InputTypes.ClassDatetime | InputTypes.DatetimeVariationNormal;
else if (self == Keyboard.Time)
result = InputTypes.ClassDatetime | InputTypes.DatetimeVariationTime;
else if (self == Keyboard.Password)
result = InputTypes.ClassText | InputTypes.TextVariationPassword;
else if (self is CustomKeyboard custom)
{
var capitalizedSentenceEnabled = (custom.Flags & KeyboardFlags.CapitalizeSentence) == KeyboardFlags.CapitalizeSentence;
Expand Down
8 changes: 8 additions & 0 deletions src/Core/src/Platform/Tizen/KeyboardExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ public static TKeyboard ToPlatform(this Keyboard keyboard)
{
return TKeyboard.Url;
}
else if (keyboard == Keyboard.Date || keyboard == Keyboard.Time)
{
return TKeyboard.DateTime;
}
else if (keyboard == Keyboard.Password)
{
return TKeyboard.Password;
}
else
{
return TKeyboard.Normal;
Expand Down
24 changes: 24 additions & 0 deletions src/Core/src/Platform/Windows/KeyboardExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ public static InputScopeName ToInputScopeName(this Keyboard self)
{
name.NameValue = InputScopeNameValue.Url;
}
else if (self == Keyboard.Password)
{
name.NameValue = InputScopeNameValue.Password;
}
else if (self == Keyboard.Date)
{
name.NameValue = InputScopeNameValue.DateDayNumber | InputScopeNameValue.DateMonthNumber | InputScopeNameValue.DateYear;
}
else if (self == Keyboard.Time)
{
name.NameValue = InputScopeNameValue.TimeHour | InputScopeNameValue.TimeMinutesOrSeconds;
}
else
{
var custom = (CustomKeyboard)self;
Expand Down Expand Up @@ -116,6 +128,18 @@ public static InputScope ToInputScope(this Keyboard self)
{
name.NameValue = InputScopeNameValue.Url;
}
else if (self == Keyboard.Password)
{
name.NameValue = InputScopeNameValue.Password;
}
else if (self == Keyboard.Date)
{
name.NameValue = InputScopeNameValue.DateDayNumber | InputScopeNameValue.DateMonthNumber | InputScopeNameValue.DateYear;
}
else if (self == Keyboard.Time)
{
name.NameValue = InputScopeNameValue.TimeHour | InputScopeNameValue.TimeMinutesOrSeconds;
}
else
{
var custom = (CustomKeyboard)self;
Expand Down
16 changes: 16 additions & 0 deletions src/Core/src/Platform/Windows/MauiPasswordTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,27 @@ static void OnPasswordPropertyChanged(DependencyObject dependencyObject, Depende
bool _internalChangeFlag;
int _cachedCursorPosition;
int _cachedTextLength;
readonly long _token;

public MauiPasswordTextBox()
{
TextChanging += OnNativeTextChanging;
TextChanged += OnNativeTextChanged;
_token = RegisterPropertyChangedCallback(TextBox.InputScopeProperty, OnInputScopePropertyChanged);
Unloaded += (s, e) =>
{
UnregisterPropertyChangedCallback(TextBox.InputScopeProperty, _token);
};
}

static void OnInputScopePropertyChanged(DependencyObject sender, DependencyProperty dp)
{
if (sender is not MauiPasswordTextBox mauiTxtBox || mauiTxtBox.IsPassword)
{
return;
}

mauiTxtBox.IsPassword = mauiTxtBox.InputScope?.Names?.Any(x => x.NameValue == InputScopeNameValue.Password) ?? false;
}

public bool IsPassword
Expand Down
10 changes: 10 additions & 0 deletions src/Core/src/Platform/iOS/KeyboardExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ public static void ApplyKeyboard(this IUITextInputTraits textInput, Keyboard key
textInput.SetKeyboardType(UIKeyboardType.PhonePad);
else if (keyboard == Keyboard.Url)
textInput.SetKeyboardType(UIKeyboardType.Url);
else if (keyboard == Keyboard.Date || keyboard == Keyboard.Time)
{
textInput.SetTextContentType(UITextContentType.DateTime);
textInput.SetKeyboardType(UIKeyboardType.NumbersAndPunctuation);
}
else if (keyboard == Keyboard.Password)
{
textInput.SetKeyboardType(UIKeyboardType.Default);
textInput.SetSecureTextEntry(true);
}
else if (keyboard is CustomKeyboard)
{
var custom = (CustomKeyboard)keyboard;
Expand Down
19 changes: 19 additions & 0 deletions src/Core/src/Primitives/DateTimeKeyboard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Microsoft.Maui;
sealed class DateKeyboard : Keyboard
{
}


sealed class PasswordKeyboard : Keyboard
{

}

sealed class TimeKeyboard : Keyboard
{

}
55 changes: 23 additions & 32 deletions src/Core/src/Primitives/Keyboard.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#nullable enable
using System.ComponentModel;
using Microsoft.Maui.Primitives;

namespace Microsoft.Maui
{
Expand All @@ -23,57 +24,47 @@ public class Keyboard

static Keyboard? s_chat;

static Keyboard? s_date;

static Keyboard? s_time;

static Keyboard? s_password;


internal Keyboard()
{
}

/// <include file="../../docs/Microsoft.Maui/Keyboard.xml" path="//Member[@MemberName='Plain']/Docs/*" />
public static Keyboard Plain
{
get { return s_plain ??= new CustomKeyboard(KeyboardFlags.None); }
}
public static Keyboard Plain => s_plain ??= new CustomKeyboard(KeyboardFlags.None);

/// <include file="../../docs/Microsoft.Maui/Keyboard.xml" path="//Member[@MemberName='Chat']/Docs/*" />
public static Keyboard Chat
{
get { return s_chat ??= new ChatKeyboard(); }
}
public static Keyboard Chat => s_chat ??= new ChatKeyboard();

/// <include file="../../docs/Microsoft.Maui/Keyboard.xml" path="//Member[@MemberName='Default']/Docs/*" />
public static Keyboard Default
{
get { return s_def ??= new Keyboard(); }
}
public static Keyboard Default => s_def ??= new Keyboard();

/// <include file="../../docs/Microsoft.Maui/Keyboard.xml" path="//Member[@MemberName='Email']/Docs/*" />
public static Keyboard Email
{
get { return s_email ??= new EmailKeyboard(); }
}
public static Keyboard Email => s_email ??= new EmailKeyboard();

/// <include file="../../docs/Microsoft.Maui/Keyboard.xml" path="//Member[@MemberName='Numeric']/Docs/*" />
public static Keyboard Numeric
{
get { return s_numeric ??= new NumericKeyboard(); }
}
public static Keyboard Numeric => s_numeric ??= new NumericKeyboard();

/// <include file="../../docs/Microsoft.Maui/Keyboard.xml" path="//Member[@MemberName='Telephone']/Docs/*" />
public static Keyboard Telephone
{
get { return s_telephone ??= new TelephoneKeyboard(); }
}
public static Keyboard Telephone => s_telephone ??= new TelephoneKeyboard();

/// <include file="../../docs/Microsoft.Maui/Keyboard.xml" path="//Member[@MemberName='Text']/Docs/*" />
public static Keyboard Text
{
get { return s_text ??= new TextKeyboard(); }
}
public static Keyboard Text => s_text ??= new TextKeyboard();

/// <include file="../../docs/Microsoft.Maui/Keyboard.xml" path="//Member[@MemberName='Url']/Docs/*" />
public static Keyboard Url
{
get { return s_url ??= new UrlKeyboard(); }
}
public static Keyboard Url => s_url ??= new UrlKeyboard();

public static Keyboard Date => s_date ??= new DateKeyboard();

public static Keyboard Password => s_password ??= new PasswordKeyboard();

public static Keyboard Time => s_time ??= new TimeKeyboard();


/// <include file="../../docs/Microsoft.Maui/Keyboard.xml" path="//Member[@MemberName='Create']/Docs/*" />
public static Keyboard Create(KeyboardFlags flags)
Expand Down