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

Entry keyboard handler #507

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5e2c75f
Base code for handlers.
bkaankose Mar 12, 2021
c53ac07
Platform specific extension parts in the handlers and partially imple…
bkaankose Mar 12, 2021
84d43aa
Test code in sample for numeric keyboard input type.
bkaankose Mar 12, 2021
ab7c3f7
iOS Handler port.
bkaankose Mar 13, 2021
505020d
KeyListener implementation for Android handler.
bkaankose Mar 13, 2021
6339569
Keyboard added for EntryStub.
bkaankose Mar 13, 2021
3795b0a
fix for wrong property name mapping
bkaankose Mar 14, 2021
407d314
better property summary
bkaankose Mar 14, 2021
3e7b632
bindable proeprty added to Entry
bkaankose Mar 14, 2021
e80c407
Device tests for all non custom keyboard types are implemented for bo…
bkaankose Mar 14, 2021
27595c5
MapKeyboard order changed in order to prevent unwanted changes to oth…
bkaankose Mar 14, 2021
bc5daa5
Numeric entry to samples with placeholder.
bkaankose Mar 14, 2021
d6891f7
Merge remote-tracking branch 'upstream/main' into entry-keyboard-handler
bkaankose Mar 14, 2021
0fa4eaa
Fixed merging error with namespaces.
bkaankose Mar 15, 2021
220d27d
Better PortHandler for UpdateInputType in Android renderer.
bkaankose Mar 15, 2021
37eba9a
pattern matching usage in keyboard extensions for android.
bkaankose Mar 15, 2021
a38ab4c
Moved LocalizedDigitsKeyListener to Core.Android project
bkaankose Mar 15, 2021
a473775
Delete KeyboardExtensions in Android Compatibility.
bkaankose Mar 15, 2021
a8e0983
Possible iOS Compatibility for Extensions.
bkaankose Mar 15, 2021
42f0326
Missing SearchBarRenderer usings.
bkaankose Mar 15, 2021
05dad63
Added missing usings for iOS renderers.
bkaankose Mar 15, 2021
83183ca
more missing references in iOS renderers...
bkaankose Mar 15, 2021
a4c8c3d
Merge branch 'main' into entry-keyboard-handler
mattleibow Mar 15, 2021
c4de573
Removed already ported extension methods in iOS and changed the usage…
bkaankose Mar 15, 2021
3551d17
Merge branch 'entry-keyboard-handler' of https://github.com/bkaankose…
bkaankose Mar 15, 2021
7b57f0a
Inverted LogaliczedDigitKeyListener return logic to better one.
bkaankose Mar 15, 2021
020f597
Merge remote-tracking branch 'upstream/main' into entry-keyboard-handler
bkaankose Mar 19, 2021
8b52d74
Merged main.
bkaankose Mar 19, 2021
9f18522
Merge remote-tracking branch 'upstream/main' into entry-keyboard-handler
bkaankose Mar 23, 2021
82af140
Merge branch 'main' into entry-keyboard-handler
bkaankose Mar 23, 2021
d7ba5a9
Merge branch 'main' into entry-keyboard-handler
rmarinho Mar 24, 2021
3b1bfc4
Merge branch 'main' into entry-keyboard-handler
jsuarezruiz Apr 6, 2021
5555ab7
Fix build errors
jsuarezruiz Apr 6, 2021
85d6ee1
Added TODO
jsuarezruiz Apr 6, 2021
fef77f6
- fix compile errors
PureWeen Apr 6, 2021
04f8ed5
Merge branch 'dev/handlers' into pr/507
mattleibow Apr 7, 2021
c3385ba
Fix tests for Android
mattleibow Apr 7, 2021
4232070
Fix iOS tests
mattleibow Apr 7, 2021
e46da29
Fix tests properly
mattleibow Apr 7, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Android.Text;
using Android.Text.Method;
using Android.Views;
using Microsoft.Maui.Platform.Android;

namespace Microsoft.Maui.Controls.Compatibility.Platform.Android
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Remove="AppCompat\Resource.cs" />
<Compile Remove="Renderers\LocalizedDigitsKeyListener.cs" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\anim\enterfromleft.xml" />
Expand Down
1 change: 1 addition & 0 deletions src/Compatibility/Core/src/Android/PopupManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Android.Views;
using Android.Widget;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Platform.Android;
using AppCompatActivity = AndroidX.AppCompat.App.AppCompatActivity;
using AppCompatAlertDialog = AndroidX.AppCompat.App.AlertDialog;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Android.Views.InputMethods;
using Android.Widget;
using Java.Lang;
using Microsoft.Maui.Platform.Android;

namespace Microsoft.Maui.Controls.Compatibility.Platform.Android
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using AndroidX.Core.Content;
using Java.Lang;
using Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;
using Microsoft.Maui.Platform.Android;

namespace Microsoft.Maui.Controls.Compatibility.Platform.Android
{
Expand Down Expand Up @@ -318,7 +319,8 @@ protected virtual void UpdateFont()
EditText.SetTextSize(ComplexUnitType.Sp, (float)Element.FontSize);
}

[PortHandler("Partially ported")]
[PortHandler("IsSpellCheckEnabled is missing.")]
[PortHandler("No override for GetDigitsKeyListener")]
void UpdateInputType()
{
Entry model = Element;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Android.Util;
using Android.Views;
using Android.Widget;
using Microsoft.Maui.Platform.Android;

namespace Microsoft.Maui.Controls.Compatibility.Platform.Android
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Android.Views;
using Android.Widget;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Platform.Android;
using AImageButton = Android.Widget.ImageButton;
using AView = Android.Views.View;

Expand Down
1 change: 1 addition & 0 deletions src/Compatibility/Core/src/iOS/Cells/EntryCellRenderer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.ComponentModel;
using Foundation;
using Microsoft.Maui.Platform.iOS;
using UIKit;
using RectangleF = CoreGraphics.CGRect;

Expand Down
150 changes: 1 addition & 149 deletions src/Compatibility/Core/src/iOS/Extensions/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,77 +6,9 @@

namespace Microsoft.Maui.Controls.Compatibility.Platform.iOS
{
[PortHandler("Following methods still need to be ported.")]
public static class Extensions
{
public static void ApplyKeyboard(this IUITextInput textInput, Keyboard keyboard)
{
if(textInput is IUITextInputTraits traits)
ApplyKeyboard(traits, keyboard);
}

public static void ApplyKeyboard(this IUITextInputTraits textInput, Keyboard keyboard)
{
textInput.AutocapitalizationType = UITextAutocapitalizationType.None;
textInput.AutocorrectionType = UITextAutocorrectionType.No;
textInput.SpellCheckingType = UITextSpellCheckingType.No;
textInput.KeyboardType = UIKeyboardType.Default;

if (keyboard == Keyboard.Default)
{
textInput.AutocapitalizationType = UITextAutocapitalizationType.Sentences;
textInput.AutocorrectionType = UITextAutocorrectionType.Default;
textInput.SpellCheckingType = UITextSpellCheckingType.Default;
}
else if (keyboard == Keyboard.Chat)
{
textInput.AutocapitalizationType = UITextAutocapitalizationType.Sentences;
textInput.AutocorrectionType = UITextAutocorrectionType.Yes;
}
else if (keyboard == Keyboard.Email)
textInput.KeyboardType = UIKeyboardType.EmailAddress;
else if (keyboard == Keyboard.Numeric)
textInput.KeyboardType = UIKeyboardType.DecimalPad;
else if (keyboard == Keyboard.Telephone)
textInput.KeyboardType = UIKeyboardType.PhonePad;
else if (keyboard == Keyboard.Text)
{
textInput.AutocapitalizationType = UITextAutocapitalizationType.Sentences;
textInput.AutocorrectionType = UITextAutocorrectionType.Yes;
textInput.SpellCheckingType = UITextSpellCheckingType.Yes;
}
else if (keyboard == Keyboard.Url)
textInput.KeyboardType = UIKeyboardType.Url;
else if (keyboard is CustomKeyboard)
{
var custom = (CustomKeyboard)keyboard;

var capitalizedSentenceEnabled = (custom.Flags & KeyboardFlags.CapitalizeSentence) == KeyboardFlags.CapitalizeSentence;
var capitalizedWordsEnabled = (custom.Flags & KeyboardFlags.CapitalizeWord) == KeyboardFlags.CapitalizeWord;
var capitalizedCharacterEnabled = (custom.Flags & KeyboardFlags.CapitalizeCharacter) == KeyboardFlags.CapitalizeCharacter;
var capitalizedNone = (custom.Flags & KeyboardFlags.None) == KeyboardFlags.None;

var spellcheckEnabled = (custom.Flags & KeyboardFlags.Spellcheck) == KeyboardFlags.Spellcheck;
var suggestionsEnabled = (custom.Flags & KeyboardFlags.Suggestions) == KeyboardFlags.Suggestions;


UITextAutocapitalizationType capSettings = UITextAutocapitalizationType.None;

// Sentence being first ensures that the behavior of ALL is backwards compatible
if (capitalizedSentenceEnabled)
capSettings = UITextAutocapitalizationType.Sentences;
else if (capitalizedWordsEnabled)
capSettings = UITextAutocapitalizationType.Words;
else if (capitalizedCharacterEnabled)
capSettings = UITextAutocapitalizationType.AllCharacters;
else if (capitalizedNone)
capSettings = UITextAutocapitalizationType.None;

textInput.AutocapitalizationType = capSettings;
textInput.AutocorrectionType = suggestionsEnabled ? UITextAutocorrectionType.Yes : UITextAutocorrectionType.No;
textInput.SpellCheckingType = spellcheckEnabled ? UITextSpellCheckingType.Yes : UITextSpellCheckingType.No;
}
}

public static UIModalPresentationStyle ToNativeModalPresentationStyle(this PlatformConfiguration.iOSSpecific.UIModalPresentationStyle style)
{
switch (style)
Expand Down Expand Up @@ -110,28 +42,6 @@ internal static UISearchBarStyle ToNativeSearchBarStyle(this PlatformConfigurati
throw new ArgumentOutOfRangeException(nameof(style));
}
}

internal static UIReturnKeyType ToUIReturnKeyType(this ReturnType returnType)
{
switch (returnType)
{
case ReturnType.Go:
return UIReturnKeyType.Go;
case ReturnType.Next:
return UIReturnKeyType.Next;
case ReturnType.Send:
return UIReturnKeyType.Send;
case ReturnType.Search:
return UIReturnKeyType.Search;
case ReturnType.Done:
return UIReturnKeyType.Done;
case ReturnType.Default:
return UIReturnKeyType.Default;
default:
throw new System.NotImplementedException($"ReturnType {returnType} not supported");
}
}

internal static DeviceOrientation ToDeviceOrientation(this UIDeviceOrientation orientation)
{
switch (orientation)
Expand All @@ -149,64 +59,6 @@ internal static DeviceOrientation ToDeviceOrientation(this UIDeviceOrientation o
}
}

[PortHandler]
internal static NSMutableAttributedString AddCharacterSpacing(this NSAttributedString attributedString, string text, double characterSpacing)
{
if (attributedString == null && characterSpacing == 0)
return null;

NSMutableAttributedString mutableAttributedString = attributedString as NSMutableAttributedString;
if (attributedString == null || attributedString.Length == 0)
{
mutableAttributedString = text == null ? new NSMutableAttributedString() : new NSMutableAttributedString(text);
}
else
{
mutableAttributedString = new NSMutableAttributedString(attributedString);

if (!mutableAttributedString.MutableString.ToString().Equals(text))
{
mutableAttributedString.MutableString.SetString(new NSString(text));
}
}

AddKerningAdjustment(mutableAttributedString, text, characterSpacing);

return mutableAttributedString;
}

[PortHandler]
internal static bool HasCharacterAdjustment(this NSMutableAttributedString mutableAttributedString)
{
if (mutableAttributedString == null)
return false;

NSRange removalRange;
var attributes = mutableAttributedString.GetAttributes(0, out removalRange);

for (uint i = 0; i < attributes.Count; i++)
if (attributes.Keys[i] is NSString nSString && nSString == UIStringAttributeKey.KerningAdjustment)
return true;

return false;
}

[PortHandler]
internal static void AddKerningAdjustment(NSMutableAttributedString mutableAttributedString, string text, double characterSpacing)
{
if (!string.IsNullOrEmpty(text))
{
if (characterSpacing == 0 && !mutableAttributedString.HasCharacterAdjustment())
return;

mutableAttributedString.AddAttribute
(
UIStringAttributeKey.KerningAdjustment,
NSObject.FromObject(characterSpacing), new NSRange(0, text.Length - 1)
);
}
}

internal static bool IsHorizontal(this Button.ButtonContentLayout layout) =>
layout.Position == Button.ButtonContentLayout.ImagePosition.Left ||
layout.Position == Button.ButtonContentLayout.ImagePosition.Right;
Expand Down
1 change: 1 addition & 0 deletions src/Compatibility/Core/src/iOS/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using RectangleF = CoreGraphics.CGRect;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;
using Microsoft.Maui.Platform.iOS;

namespace Microsoft.Maui.Controls.Compatibility.Platform.iOS
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading.Tasks;
using CoreGraphics;
using Foundation;
using Microsoft.Maui.Platform.iOS;
using UIKit;

namespace Microsoft.Maui.Controls.Compatibility.Platform.iOS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using Foundation;
using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;
using Microsoft.Maui.Platform.iOS;
using UIKit;
using RectangleF = CoreGraphics.CGRect;

Expand Down
1 change: 1 addition & 0 deletions src/Compatibility/Core/src/iOS/Renderers/EditorRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.ComponentModel;
using CoreGraphics;
using Foundation;
using Microsoft.Maui.Platform.iOS;
using UIKit;
using RectangleF = CoreGraphics.CGRect;

Expand Down
1 change: 1 addition & 0 deletions src/Compatibility/Core/src/iOS/Renderers/EntryRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using UIKit;
using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;
using Specifics = Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.Entry;
using Microsoft.Maui.Platform.iOS;

namespace Microsoft.Maui.Controls.Compatibility.Platform.iOS
{
Expand Down
1 change: 1 addition & 0 deletions src/Compatibility/Core/src/iOS/Renderers/LabelRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Foundation;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.Maui.Platform.iOS;

#if __MOBILE__
using UIKit;
Expand Down
1 change: 1 addition & 0 deletions src/Compatibility/Core/src/iOS/Renderers/PickerRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using UIKit;
using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;
using RectangleF = CoreGraphics.CGRect;
using Microsoft.Maui.Platform.iOS;

namespace Microsoft.Maui.Controls.Compatibility.Platform.iOS
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Foundation;
using UIKit;
using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;
using Microsoft.Maui.Platform.iOS;

namespace Microsoft.Maui.Controls.Compatibility.Platform.iOS
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using CoreGraphics;
using Foundation;
using Microsoft.Maui.Platform.iOS;
using UIKit;

namespace Microsoft.Maui.Controls.Compatibility.Platform.iOS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using UIKit;
using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;
using RectangleF = CoreGraphics.CGRect;
using Microsoft.Maui.Platform.iOS;

namespace Microsoft.Maui.Controls.Compatibility.Platform.iOS
{
Expand Down
6 changes: 6 additions & 0 deletions src/Controls/samples/Controls.Sample/Pages/MainPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ void SetupMauiLayout()
verticalStack.Add(underlineLabel);


var passwordEntry = new Entry() { IsPassword = true };
var numericEntry = new Entry() { Keyboard = Keyboard.Numeric, Placeholder = "Numeric Entry" };

verticalStack.Add(passwordEntry);
verticalStack.Add(numericEntry);

var button = new Button() { Text = _viewModel.Text, WidthRequest = 200 };
var button2 = new Button()
{
Expand Down
1 change: 1 addition & 0 deletions src/Controls/src/Core/Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public partial class Entry : InputView, IFontElement, ITextAlignmentElement, IEn
public new static readonly BindableProperty TextProperty = InputView.TextProperty;

public new static readonly BindableProperty TextColorProperty = InputView.TextColorProperty;
public new static readonly BindableProperty KeyboardProperty = InputView.KeyboardProperty;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this never here before? Do we really need to add this for derived controls @PureWeen?


public new static readonly BindableProperty CharacterSpacingProperty = InputView.CharacterSpacingProperty;

Expand Down
5 changes: 5 additions & 0 deletions src/Core/src/Core/ITextInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ public interface ITextInput : IText, IPlaceholder
/// Gets a value indicating whether or not the view is read-only.
/// </summary>
bool IsReadOnly { get; }

/// <summary>
/// Gets the keyboard input type.
/// </summary>
Keyboard Keyboard { get; }
}
}
5 changes: 5 additions & 0 deletions src/Core/src/Handlers/Entry/EntryHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public static void MapIsReadOnly(EntryHandler handler, IEntry entry)
handler.TypedNativeView?.UpdateIsReadOnly(entry);
}

public static void MapKeyboard(EntryHandler handler, IEntry entry)
{
handler.TypedNativeView?.UpdateKeyboard(entry);
}

void OnTextChanged(string? text)
{
if (VirtualView == null || TypedNativeView == null)
Expand Down
1 change: 1 addition & 0 deletions src/Core/src/Handlers/Entry/EntryHandler.Standard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public static void MapIsPassword(IViewHandler handler, IEntry entry) { }
public static void MapIsTextPredictionEnabled(IViewHandler handler, IEntry entry) { }
public static void MapPlaceholder(IViewHandler handler, IEntry entry) { }
public static void MapIsReadOnly(IViewHandler handler, IEntry entry) { }
public static void MapKeyboard(IViewHandler handler, IEntry entry) { }
public static void MapFont(IViewHandler handler, IEntry entry) { }
}
}
1 change: 1 addition & 0 deletions src/Core/src/Handlers/Entry/EntryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public partial class EntryHandler
{
public static PropertyMapper<IEntry, EntryHandler> EntryMapper = new PropertyMapper<IEntry, EntryHandler>(ViewHandler.ViewMapper)
{
[nameof(IEntry.Keyboard)] = MapKeyboard,
[nameof(IEntry.Text)] = MapText,
[nameof(IEntry.TextColor)] = MapTextColor,
[nameof(IEntry.IsPassword)] = MapIsPassword,
Expand Down
Loading