diff options
author | E.Z. Hart <hartez@users.noreply.github.com> | 2017-07-24 16:57:31 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-24 16:57:31 -0400 |
commit | 7303d60ab69a0c2b3c3e54e177efa0d54a7a08de (patch) | |
tree | 89424276785f6b39e4c365eabcdee4728ded957e /Xamarin.Forms.Controls.Issues | |
parent | b19c401312227e9661fef63ab1c012614cb95fe1 (diff) | |
download | xamarin-forms-7303d60ab69a0c2b3c3e54e177efa0d54a7a08de.tar.gz xamarin-forms-7303d60ab69a0c2b3c3e54e177efa0d54a7a08de.tar.bz2 xamarin-forms-7303d60ab69a0c2b3c3e54e177efa0d54a7a08de.zip |
Disallow scrolling in ScrollView when IsEnabled set to False (#1049)
* Repro and fix for iOS
* Automated tests
* Fix for Android
* Update issue number
* Alternate version of test which I hope will work on iOS 8
* trying yet another variation of the test which will hopefully work on iOS 8
Diffstat (limited to 'Xamarin.Forms.Controls.Issues')
2 files changed, 139 insertions, 0 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/ScrollViewIsEnabled.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/ScrollViewIsEnabled.cs new file mode 100644 index 00000000..563a3319 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/ScrollViewIsEnabled.cs @@ -0,0 +1,138 @@ +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +#if UITEST +using Xamarin.UITest; +using NUnit.Framework; +using Xamarin.Forms.Core.UITests; +#endif + +namespace Xamarin.Forms.Controls.Issues +{ +#if UITEST + [Category(UITestCategories.IsEnabled)] +#endif + + [Preserve(AllMembers = true)] + [Issue(IssueTracker.None, 0112358, "ScrollView set to disabled will still allow scrolling", PlatformAffected.All)] + public class ScrollViewIsEnabled : TestNavigationPage + { + const string InitiallyEnabled = "Initially Enabled"; + const string InitiallyNotEnabled = "Initially Not Enabled"; + const string ToggleButton = "ToggleButton"; + const string ScrollView = "TheScrollView"; + const string FirstItem = "FirstItem"; + const string Success = "Success"; + + protected override void Init() + { + var initiallyEnabled = new Button { Text = InitiallyEnabled }; + initiallyEnabled.Clicked += (sender, args) => { Navigation.PushAsync(ScrollViewTestPage(true)); }; + + var initiallyNotEnabled = new Button { Text = InitiallyNotEnabled }; + initiallyNotEnabled.Clicked += (sender, args) => { Navigation.PushAsync(ScrollViewTestPage(false)); }; + + var layout = new StackLayout { Children = { initiallyNotEnabled, initiallyEnabled } }; + + var root = new ContentPage { Content = layout }; + + PushAsync(root); + } + + static ContentPage ScrollViewTestPage(bool initiallyEnabled) + { + var scrollViewContents = new StackLayout(); + scrollViewContents.Children.Add(new Label { Text = FirstItem }); + for (int n = 0; n < 100; n++) + { + scrollViewContents.Children.Add(new Label { Text = n.ToString() }); + } + + var sv = new ScrollView { Content = scrollViewContents, IsEnabled = initiallyEnabled, AutomationId = ScrollView }; + var layout = new StackLayout { Margin = new Thickness(5, 40, 5, 0) }; + + var toggleButton = new Button { Text = $"Toggle IsEnabled (currently {sv.IsEnabled})", AutomationId = ToggleButton }; + + toggleButton.Clicked += (sender, args) => + { + sv.IsEnabled = !sv.IsEnabled; + toggleButton.Text = $"Toggle IsEnabled (currently {sv.IsEnabled})"; + }; + + var instructions = new Label + { + Text = @"Attempt to scroll the ScrollView below. +If 'IsEnabled' is false and the ScrollView scrolls, this test has failed. +If 'IsEnabled' is true and the ScrollView does not scroll, this test has failed. +Use the toggle button to check both values of 'IsEnabled'." + }; + + var success = new Label(); + + layout.Children.Add(instructions); + layout.Children.Add(toggleButton); + layout.Children.Add(success); + layout.Children.Add(sv); + + sv.Scrolled += (sender, args) => success.Text = Success; + + return new ContentPage { Content = layout }; + } + +#if UITEST + [Test] + public void ScrollViewInitiallyEnabled() + { + RunningApp.WaitForElement(InitiallyEnabled); + RunningApp.Tap(InitiallyEnabled); + RunningApp.WaitForElement(FirstItem); + RunningApp.WaitForElement(ScrollView); + RunningApp.ScrollDown(ScrollView, ScrollStrategy.Gesture); + RunningApp.WaitForElement(Success); // If the ScrollView scrolled, the success label should be displayed + } + + [Test] + public void ScrollViewInitiallyEnabledThenDisabled() + { + RunningApp.WaitForElement(InitiallyEnabled); + RunningApp.Tap(InitiallyEnabled); + RunningApp.WaitForElement(ToggleButton); + RunningApp.Tap(ToggleButton); + + // Scrolling should now be IsEnabled = false + + RunningApp.WaitForElement(FirstItem); + RunningApp.WaitForElement(ScrollView); + RunningApp.ScrollDown(ScrollView, ScrollStrategy.Gesture); + RunningApp.WaitForNoElement(Success); // Shouldn't have scrolled, so no success label should be displayed + } + + [Test] + public void ScrollViewInitiallyNotEnabled() + { + RunningApp.WaitForElement(InitiallyNotEnabled); + RunningApp.Tap(InitiallyNotEnabled); + RunningApp.WaitForElement(FirstItem); + RunningApp.WaitForElement(ScrollView); + RunningApp.ScrollDown(ScrollView, ScrollStrategy.Gesture); + RunningApp.WaitForNoElement(Success); // Shouldn't have scrolled, so no success label should be displayed + } + + [Test] + public void ScrollViewInitiallyNotEnabledThenEnabled() + { + RunningApp.WaitForElement(InitiallyNotEnabled); + RunningApp.Tap(InitiallyNotEnabled); + RunningApp.WaitForElement(ToggleButton); + RunningApp.Tap(ToggleButton); + + // Scrolling should now be IsEnabled = true + + RunningApp.WaitForElement(FirstItem); + RunningApp.WaitForElement(ScrollView); + RunningApp.ScrollDown(ScrollView, ScrollStrategy.Gesture); + RunningApp.WaitForElement(Success); // If the ScrollView scrolled, the success label should be displayed + } +#endif + } +}
\ 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 b7a7530b..05f45c74 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 @@ -268,6 +268,7 @@ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla39829.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla39458.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla39853.cs" /> + <Compile Include="$(MSBuildThisFileDirectory)ScrollViewIsEnabled.cs" /> <Compile Include="$(MSBuildThisFileDirectory)PlatformSpecifics_iOSTranslucentNavBarX.xaml.cs"> <DependentUpon>PlatformSpecifics_iOSTranslucentNavBarX.xaml</DependentUpon> <SubType>Code</SubType> |