summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla44940.cs
blob: 57c686b756823f8be8f017f34ca1f29a26f462c5 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using System.Threading.Tasks;

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

// Apply the default category of "Issues" to all of the tests in this assembly
// We use this as a catch-all for tests which haven't been individually categorized
#if UITEST
[assembly: NUnit.Framework.Category("Issues")]
#endif

namespace Xamarin.Forms.Controls.Issues
{
	[Preserve(AllMembers = true)]
	[Issue(IssueTracker.Bugzilla, 44940, "[WinRT/UWP] ScrollView.ScrollToAsync does not return from await", PlatformAffected.WinRT)]
	public class Bugzilla44940 : TestContentPage
	{
		Label _statusLabel;
		Entry _firstEntry;
		Entry _secondEntry;
		StackLayout _verticalStackLayout;
		ScrollView _scrollView;

		protected override void Init()
		{
			_statusLabel = new Label
			{
				Text = "With focus on first Entry, hit Return key",
				HorizontalOptions = LayoutOptions.CenterAndExpand,
				LineBreakMode = LineBreakMode.WordWrap
			};

			_firstEntry = new Entry
			{
				HorizontalOptions = LayoutOptions.FillAndExpand,
				VerticalOptions = LayoutOptions.CenterAndExpand,
			};

			_secondEntry = new Entry
			{
				HorizontalOptions = LayoutOptions.FillAndExpand,
				VerticalOptions = LayoutOptions.CenterAndExpand,
			};

			_firstEntry.Completed += FirstEntryCompleted;

			_verticalStackLayout = new StackLayout
			{
				HorizontalOptions = LayoutOptions.FillAndExpand,
				VerticalOptions = LayoutOptions.FillAndExpand,
				Padding = new Thickness(0, 0, 0, 0),
				Margin = new Thickness(0, 0, 0, 0),
				Spacing = 5,
				Children =
				{
					_statusLabel,
					_firstEntry,
					_secondEntry
				}
			};

			_scrollView = new ScrollView
			{
				Orientation = ScrollOrientation.Vertical,
				HorizontalOptions = LayoutOptions.CenterAndExpand,
				VerticalOptions = LayoutOptions.FillAndExpand,
				Margin = new Thickness(10, 5, 10, 0),
				Padding = new Thickness(0, 0, 0, 0),
				Content = _verticalStackLayout
			};

			Content = _scrollView;
			
			Device.BeginInvokeOnMainThread(async () =>
			{
				await Task.Delay(100);
				_firstEntry.Focus();
			});
		}

		async void FirstEntryCompleted(object sender, System.EventArgs e)
		{
			_firstEntry?.Unfocus();
			_statusLabel.Text = "Attempting scroll. Return from await pending...";
			await _scrollView.ScrollToAsync(_secondEntry, ScrollToPosition.MakeVisible, false);
			_statusLabel.Text = "This should be visible on WinRT/UWP";
			_secondEntry?.Focus();
		}
	}
}