This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AutoCaptialization support for Entry/Editor (#1683)
- Loading branch information
Showing
14 changed files
with
484 additions
and
5 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue1683.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
using System; | ||
|
||
using Xamarin.Forms.CustomAttributes; | ||
using Xamarin.Forms.Internals; | ||
using System.Collections.Generic; | ||
|
||
#if UITEST | ||
using Xamarin.UITest; | ||
using NUnit.Framework; | ||
using System.Diagnostics; | ||
#endif | ||
|
||
namespace Xamarin.Forms.Controls.Issues | ||
{ | ||
[Preserve (AllMembers = true)] | ||
[Issue (IssueTracker.Github, 1683, "Auto Capitalization Implementation")] | ||
public class Issue1683 : ContentPage | ||
{ | ||
const string kContainerId = "Container"; | ||
public Issue1683() | ||
{ | ||
var layout = new StackLayout() { ClassId = kContainerId }; | ||
|
||
List<InputView> intputViews = new List<InputView>() | ||
{ | ||
new Entry() { ClassId = "EntryNotSet" }, | ||
new Entry() { AutoCapitalization = AutoCapitalization.Default, ClassId = "EntryDefault" }, | ||
new Entry() { AutoCapitalization = AutoCapitalization.None, ClassId = "EntryNone" }, | ||
new Entry() { AutoCapitalization = AutoCapitalization.Words, ClassId = "EntryWords" }, | ||
new Entry() { AutoCapitalization = AutoCapitalization.Sentences, ClassId = "EntrySentences" }, | ||
new Entry() { AutoCapitalization = AutoCapitalization.Characters, ClassId = "EntryCharacters" }, | ||
new Editor() { ClassId = "EditorNotSet" }, | ||
new Editor() { AutoCapitalization = AutoCapitalization.Default, ClassId = "EditorDefault" }, | ||
new Editor() { AutoCapitalization = AutoCapitalization.None, ClassId = "EditorNone" }, | ||
new Editor() { AutoCapitalization = AutoCapitalization.Words, ClassId = "EditorWords" }, | ||
new Editor() { AutoCapitalization = AutoCapitalization.Sentences, ClassId = "EditorSentences" }, | ||
new Editor() { AutoCapitalization = AutoCapitalization.Characters, ClassId = "EditorCharacters" }, | ||
}; | ||
|
||
|
||
if(Device.RuntimePlatform == Device.UWP) | ||
{ | ||
layout.Children.Add(new Label() { Text = "Sentence and Character don't do anything on UWP" }); | ||
} | ||
|
||
foreach(InputView child in intputViews) | ||
{ | ||
var inputs = new StackLayout() | ||
{ | ||
Orientation = StackOrientation.Horizontal | ||
}; | ||
|
||
if(child is Entry) | ||
(child as Entry).Text = "All the Same."; | ||
|
||
if(child is Editor) | ||
(child as Editor).Text = "All the Same."; | ||
|
||
|
||
child.HorizontalOptions = LayoutOptions.FillAndExpand; | ||
var theLabel = new Label(); | ||
|
||
theLabel.SetBinding(Label.TextProperty, new Binding("ClassId", source: child)); | ||
inputs.Children.Add(theLabel); | ||
inputs.Children.Add(child); | ||
layout.Children.Add(inputs); | ||
} | ||
|
||
Button rotate = new Button() { Text = "Change Capitalization Settings. Ensure they update correctly" }; | ||
|
||
// This shifts everyones capitalization by one in order | ||
// to test that updating the field works as expected | ||
rotate.Clicked += (_, __) => | ||
{ | ||
for (int i = 0; i < intputViews.Count; i++) | ||
{ | ||
var entry1 = intputViews[i]; | ||
var cap1 = ((int)entry1.AutoCapitalization + 1); | ||
|
||
if(!entry1.IsSet(InputView.AutoCapitalizationProperty)) | ||
{ | ||
entry1.AutoCapitalization = AutoCapitalization.Default; | ||
entry1.ClassId = $"{entry1.GetType().Name}{entry1.AutoCapitalization}"; | ||
} | ||
else if(!Enum.IsDefined(typeof(AutoCapitalization), cap1)) | ||
{ | ||
cap1 = 0; | ||
entry1.ClearValue(InputView.AutoCapitalizationProperty); | ||
entry1.ClassId = $"{entry1.GetType().Name}NotSet"; | ||
} | ||
else | ||
{ | ||
entry1.AutoCapitalization = (AutoCapitalization)cap1; | ||
entry1.ClassId = $"{entry1.GetType().Name}{entry1.AutoCapitalization}"; | ||
} | ||
} | ||
}; | ||
|
||
layout.Children.Add(rotate); | ||
|
||
|
||
Content = new ScrollView() | ||
{ | ||
Content = layout | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Xamarin.Forms | ||
{ | ||
public enum AutoCapitalization | ||
{ | ||
/// <summary> | ||
/// Don't set anything on the platform component. | ||
/// Currently this only affects iOS | ||
/// </summary> | ||
Default = 0, | ||
/// <summary> | ||
/// no automatic text capitalization. | ||
/// </summary> | ||
None = 1, | ||
/// <summary> | ||
/// capitalize the first character of every word. | ||
/// </summary> | ||
Words = 2, | ||
/// <summary> | ||
/// capitalize the first character of each sentence. | ||
/// </summary> | ||
Sentences = 3, | ||
/// <summary> | ||
/// capitalize all characters. | ||
/// </summary> | ||
Characters = 4 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.