From ec75b998fa75868f7c36f78043ad4ec156da94e2 Mon Sep 17 00:00:00 2001 From: Samantha Houts Date: Tue, 20 Jun 2017 11:11:40 -0700 Subject: [PATCH] [iOS] Picker no longer allows arbitrary text to be typed with keyboard (#996) * Add repro * [iOS] Reset text on editing * Add instructions, fix test case number --- .../Bugzilla37285.cs | 22 +++++++++++++++++++ ...rin.Forms.Controls.Issues.Shared.projitems | 1 + .../Renderers/PickerRenderer.cs | 9 ++++++++ 3 files changed, 32 insertions(+) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla37285.cs diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla37285.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla37285.cs new file mode 100644 index 000000000..8cfd8a3fe --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla37285.cs @@ -0,0 +1,22 @@ +using System.Linq; +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +namespace Xamarin.Forms.Controls.Issues +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Bugzilla, 37285, "Possible to enter text into Picker control", PlatformAffected.iOS)] + public class Bugzilla37285 : TestContentPage + { + const string Instructions = "On iOS, focus the Picker below and type with a hardware keyboard. If text appears in the Picker text view, this test has failed. Note that Windows will allow you to select items with the keyboard, but the text you type will not appear in the text view. Also note that Android will allow you to select an item using the arrow and enter keys, but again, no text will appear in the text view."; + + protected override void Init() + { + var picker = new Picker { ItemsSource = Enumerable.Range(0, 100).Select(c => c.ToString()).ToList() }; + + var stack = new StackLayout { Children = { new Label { Text = Instructions }, picker } }; + + Content = stack; + } + } +} \ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index c6f34ade0..61ca0a951 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -86,6 +86,7 @@ + diff --git a/Xamarin.Forms.Platform.iOS/Renderers/PickerRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/PickerRenderer.cs index 0905dcfc1..50ad64a81 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/PickerRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/PickerRenderer.cs @@ -28,6 +28,7 @@ namespace Xamarin.Forms.Platform.iOS entry.EditingDidBegin += OnStarted; entry.EditingDidEnd += OnEnded; + entry.EditingChanged += OnEditing; _picker = new UIPickerView(); @@ -75,6 +76,14 @@ namespace Xamarin.Forms.Platform.iOS UpdateTextColor(); } + void OnEditing(object sender, EventArgs eventArgs) + { + // Reset the TextField's Text so it appears as if typing with a keyboard does not work. + var selectedIndex = Element.SelectedIndex; + var items = Element.Items; + Control.Text = selectedIndex == -1 || items == null ? "" : items[selectedIndex]; + } + void OnEnded(object sender, EventArgs eventArgs) { ElementController.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, false);