From 9dff4c16508452512c5faa36788f65ba6419170e Mon Sep 17 00:00:00 2001 From: adrianknight89 Date: Tue, 6 Dec 2016 06:07:29 -0600 Subject: [Android] ScrollView should send correct ScrollX and ScrollY (#394) * Android should show correct ScrollX and ScrollY when scrolling in both directions * Adding sample code to demonstrate scrolling * Orientation fix * ScrollTo should work for horizontal + vertical scrolling * Get correct scroll x and y values for ScrollOrientation.Both * Convert positions to pixels * Adding unit test to watch out for incorrect animation positioning * automated test * improvements * fixed texts --- .../Bugzilla41415.cs | 115 +++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41415.cs (limited to 'Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41415.cs') diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41415.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41415.cs new file mode 100644 index 00000000..c16f3734 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41415.cs @@ -0,0 +1,115 @@ +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +#if UITEST +using Xamarin.UITest; +using NUnit.Framework; +#endif + +namespace Xamarin.Forms.Controls +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Bugzilla, 41415, "ScrollX and ScrollY values are not consistent with iOS", PlatformAffected.Android)] + public class Bugzilla41415 : TestContentPage + { + const string ButtonText = "Click Me"; + float _x, _y; + bool _didXChange, _didYChange; + + protected override void Init() + { + var grid = new Grid + { + BackgroundColor = Color.Yellow, + WidthRequest = 1000, + HeightRequest = 1000, + Children = + { + new BoxView + { + WidthRequest = 200, + HeightRequest = 200, + BackgroundColor = Color.Red, + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center + } + } + }; + + var labelx = new Label(); + var labely = new Label(); + var labelz = new Label(); + var labela = new Label(); + + var scrollView = new ScrollView + { + Orientation = ScrollOrientation.Both, + HorizontalOptions = LayoutOptions.FillAndExpand, + VerticalOptions = LayoutOptions.FillAndExpand + }; + + scrollView.Content = grid; + scrollView.Scrolled += (sender, args) => + { + labelx.Text = $"x: {args.ScrollX}"; + labely.Text = $"y: {args.ScrollY}"; + + // first and second taps + if (_x == 0) + { + if (args.ScrollX != 0 && args.ScrollX != 100) + _didXChange = true; + if (args.ScrollY != 0 && args.ScrollY != 100) + _didYChange = true; + } + else if (_x == 100) + { + if (args.ScrollX != _x && args.ScrollX != _x + 100) + _didXChange = true; + if (args.ScrollY != 100) + _didYChange = true; + } + + labelz.Text = "z: " + _didXChange.ToString(); + labela.Text = "a: " + _didYChange.ToString(); + }; + + var button = new Button { Text = ButtonText }; + button.Clicked += async (sender, e) => + { + // reset + labelx.Text = null; + labely.Text = null; + labelz.Text = null; + labela.Text = null; + _didXChange = false; + _didYChange = false; + + await scrollView.ScrollToAsync(_x + 100, _y + 100, true); + _x = 100; + }; + + Content = new StackLayout { Children = { button, labelx, labely, labelz, labela, scrollView } }; + } + +#if UITEST + + [Test] + public void Bugzilla41415Test() + { + RunningApp.WaitForElement(q => q.Marked(ButtonText)); + RunningApp.Tap(q => q.Marked(ButtonText)); + RunningApp.WaitForElement(q => q.Marked("x: 100")); + RunningApp.WaitForElement(q => q.Marked("y: 100")); + RunningApp.WaitForElement(q => q.Marked("z: True")); + RunningApp.WaitForElement(q => q.Marked("a: True")); + RunningApp.Tap(q => q.Marked(ButtonText)); + RunningApp.WaitForElement(q => q.Marked("x: 200")); + RunningApp.WaitForElement(q => q.Marked("y: 100")); + RunningApp.WaitForElement(q => q.Marked("z: True")); + RunningApp.WaitForElement(q => q.Marked("a: False")); + } + +#endif + } +} \ No newline at end of file -- cgit v1.2.3