-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Implemented MaxLength property on Entry and Editor #1880
Implemented MaxLength property on Entry and Editor #1880
Conversation
This reverts commit e17a662.
Added MaxLength property on InputView and implemented iOS and Android Entry and Android Editor
First check to see if there is a LengthFilter in there already and remove that first
Except GTK, seems everything is spaces there, so kept it for consistency
Xamarin.Forms.Core/InputView.cs
Outdated
@@ -5,6 +5,14 @@ public class InputView : View | |||
public static readonly BindableProperty KeyboardProperty = BindableProperty.Create("Keyboard", typeof(Keyboard), typeof(InputView), Keyboard.Default, | |||
coerceValue: (o, v) => (Keyboard)v ?? Keyboard.Default); | |||
|
|||
public static readonly BindableProperty MaxLengthProperty = BindableProperty.Create("MaxLength", typeof(int), typeof(int), int.MaxValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use -1
as default value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use nameof(MaxLength)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we usually use tabs for indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the #1663 we sort of decided to go with int.MaxValue. What would be the benefit of using -1?
Fixed nameof and tabs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll discuss the defaultValue with @hartez. both are fine, both make sense. But having Int32.MaxValue prevents us from having a really long text in, while -1 does not.
@@ -60,6 +62,7 @@ protected override void OnElementChanged(ElementChangedEventArgs<Editor> e) | |||
Control.Changed += HandleChanged; | |||
Control.Started += OnStarted; | |||
Control.Ended += OnEnded; | |||
Control.ShouldChangeText += ShouldChangeText; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks like you do not do anything on property change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you mean here. The event is hooked up? If you mean that I don't act on the MaxLength being changed you're right. Wasn't sure what to do with that. The logical thing to do would be to cut off the current value if its length exceeds the new MaxLength value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logical thing to do would be to cut off the current value if its length exceeds the new MaxLength value
that's what I'd do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely makes sense, implemented it
@jfversluis the build is failing in the Tizen platform
|
@rmarinho should be resolved now |
@@ -35,6 +35,9 @@ protected override void Build (StackLayout stackLayout) | |||
var textColorDisabledContainer = new ViewContainer<Editor> (Test.Editor.TextColor, | |||
new Editor { Text = "I should have the default disabled text color", TextColor = Color.Red, IsEnabled = false }); | |||
|
|||
var maxLengthContainer = new ViewContainer<Editor>(Test.Editor.MaxLength, | |||
new Editor { MaxLength = 3 }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Funky whitespace for fun and profit :)
|
||
Control?.SetFilters(currentFilters.ToArray()); | ||
|
||
if (Control?.Text.Length > Element.MaxLength) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You fetch Control.Text 3 times here. This causes 3 GetValue calls to be sent down to BindableObject. In this case it should be trivial to use a temporary variable to avoid that :)
|
||
Control?.SetFilters(currentFilters.ToArray()); | ||
|
||
if (Control?.Text.Length > Element.MaxLength) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetValue calls here as well
|
||
void UpdateMaxLength() | ||
{ | ||
if (Control?.StringValue?.Length > Element?.MaxLength) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple calls to Control.StringValue again :)
|
||
void UpdateMaxLength() | ||
{ | ||
if (Control?.StringValue?.Length > Element?.MaxLength) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here too
{ | ||
Control.MaxLength = Element.MaxLength; | ||
|
||
if (Control.Text.Length > Element.MaxLength) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here
@@ -105,6 +108,14 @@ void UpdateTextColor() | |||
Control.UpdateDependencyColor(System.Windows.Controls.Control.ForegroundProperty, Element.TextColor); | |||
} | |||
|
|||
void UpdateMaxLength() | |||
{ | |||
Control.MaxLength = Element.MaxLength; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not going to call anymore of these out, but there are quite a few more :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you got pretty much all of them? :P But thanks! Learning a lot here :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah its fun, just doing these little optimizations on our first pass once we realized this was a problem gave Forms a fairly sizeable performance boost. Now its about making sure we dont end up needing to do that again :)
Scheduling builds now |
That’s curious. Does anyone have details on the failing build? |
@jfversluis is failing on docs, you need to generate the docs needed and commit also. |
@rmarinho done! |
@@ -451,9 +451,6 @@ | |||
<AssemblyVersion>2.0.0.0</AssemblyVersion> | |||
</AssemblyInfo> | |||
<Attributes> | |||
<Attribute> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to commit this, build in Debug, then generate docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rmarinho I'm not sure what went wrong..? Rebuild the whole solution in Debug and then commit the results? Or what am I supposed to do here?
@@ -512,9 +512,6 @@ | |||
<AssemblyVersion>2.0.0.0</AssemblyVersion> | |||
</AssemblyInfo> | |||
<Attributes> | |||
<Attribute> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to commit this
docs/Xamarin.Forms.Core/index.xml
Outdated
@@ -3,13 +3,13 @@ | |||
<Assembly Name="Xamarin.Forms.Core" Version="2.0.0.0"> | |||
<Attributes> | |||
<Attribute> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to commit this
docs/Xamarin.Forms.Maps/index.xml
Outdated
@@ -3,13 +3,13 @@ | |||
<Assembly Name="Xamarin.Forms.Maps" Version="2.0.0.0"> | |||
<Attributes> | |||
<Attribute> | |||
<AttributeName>System.Diagnostics.Debuggable(System.Diagnostics.DebuggableAttribute+DebuggingModes.Default | System.Diagnostics.DebuggableAttribute+DebuggingModes.DisableOptimizations | System.Diagnostics.DebuggableAttribute+DebuggingModes.EnableEditAndContinue | System.Diagnostics.DebuggableAttribute+DebuggingModes.IgnoreSymbolStoreSequencePoints)</AttributeName> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to commit this or the others similar
This reverts commit 416e287.
@rmarinho better like this? :) |
Is there anything I need to do for the failing UI tests? |
@jfversluis no it's good |
* 'master' of https://github.com/xamarin/Xamarin.Forms: (23 commits) [C] use direct cast [Core, iOS, Android, UWP, WPF] Hide scroll view scroll bars (xamarin#1910) Allow users to specify resolution method for handlers, effects, and services (xamarin#1870) fixes xamarin#1739 [Build] Update submodule Capitalization keyboard flag additions for Entry/Editor (xamarin#1683) (xamarin#1833) [Build] Don't specify .net sdk version Simplify event raising invocation pattern (xamarin#1971) [iOS Maps] Pin rendering customization (xamarin#1065) set csharp_space_after_keywords_in_control_flow_statements to true to fit our design guide lines (xamarin#1964) [iOS] Add shadow effect (xamarin#1896) Added support for ListView full width separators on iOS (xamarin#1854) fixes xamarin#1665 Support CascadeInputTransparent to Tizen (xamarin#1916) [Android]?Remove UserVisibleHint (xamarin#1550) fixes xamarin#1438 [iOS] ViewDidLayoutSubviews after removing page (xamarin#1532) fixes xamarin#1426 Use relative URL to support recursive checkout in VSTS (xamarin#1926) [UITest] Fix test for UITest package update (xamarin#1923) Implemented MaxLength property on Entry and Editor (xamarin#1880) [Build]Fix master and build (xamarin#1920) [Build] Fix windows cert Fix to absolute URL ... # Conflicts: # Xamarin.Forms.Controls/CoreGalleryPages/EditorCoreGalleryPage.cs # Xamarin.Forms.Controls/CoreGalleryPages/EntryCoreGalleryPage.cs # Xamarin.Forms.Core/InputView.cs # Xamarin.Forms.CustomAttributes/TestAttributes.cs # Xamarin.Forms.Platform.Android/Renderers/EditorRenderer.cs # Xamarin.Forms.Platform.Android/Renderers/EntryRenderer.cs # Xamarin.Forms.Platform.MacOS/Renderers/EditorRenderer.cs # Xamarin.Forms.Platform.MacOS/Renderers/EntryRenderer.cs # Xamarin.Forms.Platform.Tizen/Renderers/EditorRenderer.cs # Xamarin.Forms.Platform.Tizen/Renderers/EntryRenderer.cs # Xamarin.Forms.Platform.WPF/Renderers/EditorRenderer.cs # Xamarin.Forms.Platform.WPF/Renderers/EntryRenderer.cs # Xamarin.Forms.Platform.iOS/Renderers/EditorRenderer.cs # Xamarin.Forms.Platform.iOS/Renderers/EntryRenderer.cs
Description of Change
Implementation of MaxLength on both the Entry as well as the Editor (by implementing it on the InputView) for all platforms supported today. Fixes #1663.
No unit tests have been added since I would just be testing the getter/setter of the property.
Bugs Fixed
API Changes
Added:
static BindableProperty InputView.MaxLengthProperty;
int InputView.MaxLength { get; set; }
//Bindable Property, default value int.MaxValueBehavioral Changes
There shouldn't be any behavioral changes by just upgrading. But they now have the ability to limit the input length of the Editor and Entry controls.
PR Checklist