summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla28570.cs
blob: 0f51f61fd691480a4e4d6e332899aa761d92d4a2 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System;
using System.Diagnostics;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.UITest.Android;
using Xamarin.UITest;
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls
{
	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Bugzilla, 28570, "https://bugzilla.xamarin.com/show_bug.cgi?id=28570")]
	internal class Bugzilla28570 : TestContentPage
	{
		public ScrollView ScrollView;

		protected override void Init ()
		{
			Label header = new Label {
				Text = "ScrollView Bug",
				FontSize = 50,
				FontAttributes = FontAttributes.Bold,
				HorizontalOptions = LayoutOptions.Center
			};

			Label lab1 = new Label ();
			lab1.Text = "Sometimes page content fits entirely on " +
						"the page. That's very convenient. But " +
						"on many occasions, the content of the page " +
						"is much too large for the page, or only " +
						"becomes available at runtime." +
						"\n\n" +
						"For cases such as these, the ScrollView " +
						"provides a solution. Simply set its " +
						"Content property to your content \u2014 in this " +
						"case a Label but in the general case very " +
						"likely a Layout derivative with multiple " +
						"children \u2014 and the ScrollView provides " +
						"scrolling with the distinctive look and touch " +
						"familiar to the user." +
						"\n\n" +
						"The ScrollView is also capable of " +
						"horizontal scrolling, and while that's " +
						"usually not as common as vertical scrolling, " +
						"sometimes it comes in handy." +
						"\n\n" +
						"Most often, the content of a ScrollView is " +
						"a StackLayout. Whenever you're using a " +
						"StackLayout with a number of items determined " +
						"only at runtime, you should probably put it in " +
						"a StackLayout just to be sure your stuff doesn't " +
						"go running off the bottom of the screen." +
						"Most often, the content of a ScrollView is " +
						"a StackLayout. Whenever you're using a " +
						"StackLayout with a number of items determined " +
						"only at runtime, you should probably put it in " +
						"a StackLayout just to be sure your stuff doesn't " +
						"go running off the bottom of the screen.";

			var targetLabel = new Label {Text = "Find Me"};
			targetLabel.AutomationId = "28570Target";

			lab1.FontSize = Device.GetNamedSize (NamedSize.Small, typeof (Label));


			ScrollView = new ScrollView {
				VerticalOptions = LayoutOptions.FillAndExpand,
				Content = new StackLayout {
					Children = {
						lab1,
						targetLabel
					}
				}
			};

			Button makeBig = new Button ();
			makeBig.Text = "Tap";
			//
			// Clicking button first time does not scroll event though scrollView.Height is already set.
			// Clicking a second time does correctly scroll to the end.  scrollView.Height  is unchanged.
			//
			// For this test to work you should make sure the text fits into the screen when the font is small
			// and then becomes larger than the screeen when switching to the Large font.
			//
			makeBig.Clicked += (object sender, EventArgs e) => {
				lab1.FontSize = Device.GetNamedSize (NamedSize.Large, typeof (Label));
				Debug.WriteLine ("******** scrollView.Height= {0}", lab1.Height); // this shows the same updated size on all clicks, so this is not the problem.
				ScrollView.ScrollToAsync (0, lab1.Bounds.Bottom, false);
			};

			// Build the page.
			Content = new StackLayout {
				Children = {
					makeBig,
					header,
					ScrollView,
				}
			};
		}

#if UITEST
		[Test]
		[Ignore("Fails intermittently on TestCloud")]
		public void Bugzilla28570Test ()
		{
			if (RunningApp is AndroidApp) {
				RunningApp.WaitForElement (q => q.Marked ("Tap"));
				RunningApp.Screenshot ("At test page");
				RunningApp.Tap (q => q.Marked ("Tap"));

				RunningApp.WaitForElement (q => q.Marked ("28570Target"));
			}
		}
#endif
	}
}