summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla31141.cs
blob: 1c67f19f1046db1066ec5765f6a618f1e03113a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls.Issues
{
	[Preserve(AllMembers = true)]
	[Issue(IssueTracker.Bugzilla, 31141, "Change Entry keyboard type while typing", PlatformAffected.iOS)]
	public class Bugzilla31141 : TestContentPage // or TestMasterDetailPage, etc ...
	{
		protected override void Init()
		{
			var stackLayout = new StackLayout
			{
				Orientation = StackOrientation.Vertical,
				Spacing = 10,
				VerticalOptions = LayoutOptions.Start,
				HorizontalOptions = LayoutOptions.Center
			};

			var label = new Label
			{
				Text = "Focus Entry or Editor and type characters. For every 3 characters, the keyboard type will change while keyboard is focused up to 12 characters."
			};
			stackLayout.Children.Add(label);

			var entry = new Entry
			{
				WidthRequest = 250,
				HeightRequest = 50,
				BackgroundColor = Color.DarkGoldenrod
			};
			entry.TextChanged += InputViewOnTextChanged;
			stackLayout.Children.Add(entry);

			var editor = new Editor
			{
				WidthRequest = 250,
				HeightRequest = 50,
				BackgroundColor = Color.AntiqueWhite
			};
			editor.TextChanged += InputViewOnTextChanged;
			stackLayout.Children.Add(editor);

			Content = stackLayout;
		}

		void InputViewOnTextChanged(object sender, TextChangedEventArgs textChangedEventArgs)
		{
			if (textChangedEventArgs.NewTextValue.Length >= 15)
				return;

			switch (textChangedEventArgs.NewTextValue.Length % 15)
			{
				case 0:
					(sender as InputView).Keyboard = Keyboard.Default;
					break;
				case 3:
					(sender as InputView).Keyboard = Keyboard.Numeric;
					break;
				case 6:
					(sender as InputView).Keyboard = Keyboard.Email;
					break;
				case 9:
					(sender as InputView).Keyboard = Keyboard.Telephone;
					break;
				case 12:
					(sender as InputView).Keyboard = Keyboard.Url;
					break;
			}
		}
	}
}