From 17fdde66d94155fc62a034fa6658995bef6fd6e5 Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Tue, 22 Mar 2016 13:02:25 -0700 Subject: Initial import --- .../Bugzilla31330.cs | 163 +++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla31330.cs (limited to 'Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla31330.cs') diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla31330.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla31330.cs new file mode 100644 index 00000000..5f7e14ec --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla31330.cs @@ -0,0 +1,163 @@ +using System; + +using Xamarin.Forms.CustomAttributes; +using System.Collections.ObjectModel; +using System.Windows.Input; + + +#if UITEST +using Xamarin.UITest.iOS; +using Xamarin.UITest; +using NUnit.Framework; +#endif + +namespace Xamarin.Forms.Controls +{ + [Preserve (AllMembers = true)] + [Issue (IssueTracker.Bugzilla, 31330, "Disabled context actions appear enabled")] + public class Bugzilla31330 : TestContentPage + { + protected override void Init () + { + var vm = new ListViewModel (); + BindingContext = vm; + vm.Init (); + var listview = new ListView (); + listview.SetBinding (ListView.ItemsSourceProperty, new Binding ("Items")); + listview.ItemTemplate = new DataTemplate (typeof(CustomTextCell)); + listview.ItemSelected += (object sender, SelectedItemChangedEventArgs e) => { + (e.SelectedItem as ListItemViewModel).CanExecute = true; + ((e.SelectedItem as ListItemViewModel).DeleteItemCommand as Command).ChangeCanExecute (); + }; + // Initialize ui here instead of ctor + Content = listview; + } + + [Preserve (AllMembers = true)] + public class CustomTextCell : TextCell + { + public CustomTextCell () + { + SetBinding (TextProperty, new Binding ("Title")); + var deleteMenuItem = new MenuItem (); + deleteMenuItem.Text = "Delete"; + deleteMenuItem.IsDestructive = true; + deleteMenuItem.SetBinding (MenuItem.CommandProperty, new Binding ("DeleteItemCommand")); + ContextActions.Add (deleteMenuItem); + } + } + + [Preserve (AllMembers = true)] + public class ListViewModel : ViewModel + { + public void Init () + { + Items.Add (new ListItemViewModel (this) { Title = string.Format ("Something {0}", Items.Count.ToString ()) }); + Items.Add (new ListItemViewModel (this) { Title = string.Format ("Something {0}", Items.Count.ToString ()) }); + Items.Add (new ListItemViewModel (this) { Title = string.Format ("Something {0}", Items.Count.ToString ()) }); + } + + public ObservableCollection Items { get; } = new ObservableCollection(); + + ICommand _disabledCommand; + + public ICommand DisabledCommand { + get { + if (_disabledCommand == null) { + _disabledCommand = new Command (() => { + }, () => false); + } + + return _disabledCommand; + } + } + + ICommand _addItemCommand; + + public ICommand AddItemCommand { + get { + if (_addItemCommand == null) { + _addItemCommand = new Command (() => Items.Add (new ListItemViewModel (this) { Title = string.Format ("Something {0}", Items.Count.ToString ()) })); + } + + return _addItemCommand; + } + } + } + + [Preserve (AllMembers = true)] + public class ListItemViewModel : ViewModel + { + public bool CanExecute = false; + readonly ListViewModel _listViewModel; + + public ListItemViewModel (ListViewModel listViewModel) + { + if (listViewModel == null) { + throw new ArgumentNullException ("listViewModel"); + } + _listViewModel = listViewModel; + } + + public string Title { get; set; } + + ICommand _deleteItemCommand; + + public ICommand DeleteItemCommand { + get { + if (_deleteItemCommand == null) { + _deleteItemCommand = new Command (() => _listViewModel.Items.Remove (this), () => CanExecute); + } + + return _deleteItemCommand; + } + } + + ICommand _otherCommand; + + public ICommand OtherCommand { + get { + if (_otherCommand == null) { + _otherCommand = new Command (() => { + }, () => false); + } + + return _otherCommand; + } + } + } + + #if UITEST + [Test] + public void Bugzilla31330Test () + { + var screenBounds = RunningApp.Query (q => q.Raw ("* index:0"))[0].Rect; + + var cell = RunningApp.Query (c => c.Marked ("Something 1")) [0]; + var cell2 = RunningApp.Query (c => c.Marked ("Something 2")) [0]; + if (RunningApp is iOSApp) { + RunningApp.DragCoordinates (screenBounds.Width - 10, cell.Rect.CenterY, 0, cell.Rect.CenterY); + RunningApp.WaitForElement (c => c.Marked ("Delete")); + RunningApp.Tap (c => c.Marked ("Delete")); + RunningApp.WaitForElement (c => c.Marked ("Something 1")); + RunningApp.Tap (c => c.Marked ("Something 2")); + RunningApp.DragCoordinates (screenBounds.Width - 10, cell2.Rect.CenterY, 0, cell2.Rect.CenterY); + RunningApp.Tap (c => c.Marked ("Delete")); + RunningApp.WaitForNoElement (c => c.Marked ("Something 2")); + } + else { + RunningApp.TouchAndHoldCoordinates (cell.Rect.CenterX, cell.Rect.CenterY); + RunningApp.WaitForElement (c => c.Marked ("Delete")); + RunningApp.Tap (c => c.Marked ("Delete")); + RunningApp.Back (); + RunningApp.WaitForElement (c => c.Marked ("Something 1")); + RunningApp.Tap (c => c.Marked ("Something 2")); + RunningApp.TouchAndHoldCoordinates (cell2.Rect.CenterX, cell2.Rect.CenterY); + RunningApp.Tap (c => c.Marked ("Delete")); + RunningApp.WaitForNoElement (c => c.Marked ("Something 2")); + } + + } +#endif + } +} -- cgit v1.2.3