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 35 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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -319,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
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
128 changes: 1 addition & 127 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 @@ -150,64 +82,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 Expand Up @@ -209,17 +210,17 @@ internal void UpdateText()
var normal =
control
.GetAttributedTitle(UIControlState.Normal)
.AddCharacterSpacing(text, _element.CharacterSpacing);
.WithCharacterSpacing(_element.CharacterSpacing);

var highlighted =
control
.GetAttributedTitle(UIControlState.Highlighted)
.AddCharacterSpacing(text, _element.CharacterSpacing);
.WithCharacterSpacing(_element.CharacterSpacing);

var disabled =
control
.GetAttributedTitle(UIControlState.Disabled)
.AddCharacterSpacing(text, _element.CharacterSpacing);
.WithCharacterSpacing(_element.CharacterSpacing);

normal.AddAttribute(
UIStringAttributeKey.ForegroundColor,
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 Expand Up @@ -217,7 +218,7 @@ protected internal virtual void UpdateFont()
[PortHandler]
void UpdateCharacterSpacing()
{
var textAttr = Control.AttributedText.AddCharacterSpacing(Control.Text, Element.CharacterSpacing);
var textAttr = Control.AttributedText.WithCharacterSpacing(Element.CharacterSpacing);

if (textAttr != null)
Control.AttributedText = textAttr;
Expand Down
7 changes: 4 additions & 3 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 Expand Up @@ -74,12 +75,12 @@ protected internal override void UpdatePlaceholderText()
[PortHandler("Partially ported")]
protected internal override void UpdateCharacterSpacing()
{
var textAttr = TextView.AttributedText.AddCharacterSpacing(Element.Text, Element.CharacterSpacing);
var textAttr = TextView.AttributedText.WithCharacterSpacing(Element.CharacterSpacing);

if(textAttr != null)
TextView.AttributedText = textAttr;

var placeHolder = _placeholderLabel.AttributedText.AddCharacterSpacing(Element.Placeholder, Element.CharacterSpacing);
var placeHolder = _placeholderLabel.AttributedText.WithCharacterSpacing(Element.CharacterSpacing);

if(placeHolder != null)
_placeholderLabel.AttributedText = placeHolder;
Expand Down Expand Up @@ -122,7 +123,7 @@ void CreatePlaceholderLabel()
);

_placeholderLabel.TranslatesAutoresizingMaskIntoConstraints = false;
_placeholderLabel.AttributedText = _placeholderLabel.AttributedText.AddCharacterSpacing(Element.Placeholder, Element.CharacterSpacing);
_placeholderLabel.AttributedText = _placeholderLabel.AttributedText.WithCharacterSpacing(Element.CharacterSpacing);

Control.AddConstraints(hConstraints);
Control.AddConstraints(vConstraints);
Expand Down
7 changes: 4 additions & 3 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 Expand Up @@ -360,7 +361,7 @@ protected virtual void UpdatePlaceholder()
UpdateAttributedPlaceholder(formatted.ToAttributed(Element, color));
}

UpdateAttributedPlaceholder(Control.AttributedPlaceholder.AddCharacterSpacing(Element.Placeholder, Element.CharacterSpacing));
UpdateAttributedPlaceholder(Control.AttributedPlaceholder.WithCharacterSpacing(Element.CharacterSpacing));
}

protected virtual void UpdateAttributedPlaceholder(NSAttributedString nsAttributedString) =>
Expand All @@ -378,12 +379,12 @@ void UpdateText()
[PortHandler ("Partially ported ...")]
void UpdateCharacterSpacing()
{
var textAttr = Control.AttributedText.AddCharacterSpacing(Element.Text, Element.CharacterSpacing);
var textAttr = Control.AttributedText.WithCharacterSpacing(Element.CharacterSpacing);

if (textAttr != null)
Control.AttributedText = textAttr;

var placeHolder = Control.AttributedPlaceholder.AddCharacterSpacing(Element.Placeholder, Element.CharacterSpacing);
var placeHolder = Control.AttributedPlaceholder.WithCharacterSpacing(Element.CharacterSpacing);

if (placeHolder != null)
UpdateAttributedPlaceholder(placeHolder);
Expand Down
3 changes: 2 additions & 1 deletion 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 Expand Up @@ -417,7 +418,7 @@ void UpdateCharacterSpacing()
if (string.IsNullOrEmpty(Element.Text))
return;
#if __MOBILE__
var textAttr = Control.AttributedText.AddCharacterSpacing(Element.Text, Element.CharacterSpacing);
var textAttr = Control.AttributedText.WithCharacterSpacing(Element.CharacterSpacing);

if (textAttr != null)
Control.AttributedText = textAttr;
Expand Down
7 changes: 4 additions & 3 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 Expand Up @@ -192,12 +193,12 @@ protected void UpdateCharacterSpacing()
if (Control == null)
return;

var textAttr = Control.AttributedText.AddCharacterSpacing(Control.Text, Element.CharacterSpacing);
var textAttr = Control.AttributedText.WithCharacterSpacing(Element.CharacterSpacing);

if (textAttr != null)
Control.AttributedText = textAttr;

var placeHolder = Control.AttributedPlaceholder.AddCharacterSpacing(Element.Title, Element.CharacterSpacing);
var placeHolder = Control.AttributedPlaceholder.WithCharacterSpacing(Element.CharacterSpacing);

if (placeHolder != null)
UpdateAttributedPlaceholder(placeHolder);
Expand Down Expand Up @@ -230,7 +231,7 @@ protected internal virtual void UpdatePlaceholder()
UpdateAttributedPlaceholder(formatted.ToAttributed(Element, color));
}

UpdateAttributedPlaceholder(Control.AttributedPlaceholder.AddCharacterSpacing(Element.Title, Element.CharacterSpacing));
UpdateAttributedPlaceholder(Control.AttributedPlaceholder.WithCharacterSpacing(Element.CharacterSpacing));
}

protected virtual void UpdateAttributedPlaceholder(NSAttributedString nsAttributedString) =>
Expand Down
9 changes: 5 additions & 4 deletions src/Compatibility/Core/src/iOS/Renderers/SearchBarRenderer.cs
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 Expand Up @@ -233,8 +234,8 @@ void UpdateCharacterSpacing()
if (_textField == null)
return;

_textField.AttributedText = _textField.AttributedText.AddCharacterSpacing(Element.Text, Element.CharacterSpacing);
_textField.AttributedPlaceholder = _textField.AttributedPlaceholder.AddCharacterSpacing(Element.Placeholder, Element.CharacterSpacing);
_textField.AttributedText = _textField.AttributedText.WithCharacterSpacing(Element.CharacterSpacing);
_textField.AttributedPlaceholder = _textField.AttributedPlaceholder.WithCharacterSpacing(Element.CharacterSpacing);
}

[PortHandler]
Expand Down Expand Up @@ -325,14 +326,14 @@ void UpdatePlaceholder()
? targetColor : ColorExtensions.PlaceholderColor.ToColor();

_textField.AttributedPlaceholder = formatted.ToAttributed(Element, color);
_textField.AttributedPlaceholder.AddCharacterSpacing(Element.Placeholder, Element.CharacterSpacing);
_textField.AttributedPlaceholder.WithCharacterSpacing(Element.CharacterSpacing);

}
else
{
_textField.AttributedPlaceholder = formatted.ToAttributed(Element, targetColor.IsDefault
? ColorExtensions.PlaceholderColor.ToColor() : targetColor);
_textField.AttributedPlaceholder.AddCharacterSpacing(Element.Placeholder, Element.CharacterSpacing);
_textField.AttributedPlaceholder.WithCharacterSpacing(Element.CharacterSpacing);
}
}

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 Expand Up @@ -198,7 +199,7 @@ protected internal virtual void UpdateTextColor()
[PortHandler]
void UpdateCharacterSpacing()
{
var textAttr = Control.AttributedText.AddCharacterSpacing(Control.Text, Element.CharacterSpacing);
var textAttr = Control.AttributedText.WithCharacterSpacing(Element.CharacterSpacing);

if (textAttr != null)
Control.AttributedText = textAttr;
Expand Down
Loading