-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Issue1455.xaml.cs
162 lines (139 loc) · 6.12 KB
/
Issue1455.xaml.cs
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using Xamarin.Forms.Xaml;
using System.Windows.Input;
#if UITEST
using Xamarin.UITest.Queries;
using NUnit.Framework;
#endif
namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[NUnit.Framework.Category(Core.UITests.UITestCategories.Github5000)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 1455, "Context action are not changed when selected item changed on Android", PlatformAffected.Android)]
public partial class Issue1455 : TestContentPage
{
public Issue1455()
{
#if APP
InitializeComponent();
#endif
}
MyViewModel ViewModel
{
get
{
return (MyViewModel)BindingContext;
}
}
protected override void Init()
{
BindingContext = new MyViewModel();
}
[Preserve(AllMembers = true)]
public class MyViewModel : PropertyChangedBase
{
bool _isContextActionsLegacyModeEnabled;
public bool IsContextActionsLegacyModeEnabled
{
get
{
return _isContextActionsLegacyModeEnabled;
}
set
{
_isContextActionsLegacyModeEnabled = value;
OnPropertyChanged();
}
}
public ICommand ToggleLegacyMode { get; }
public ObservableCollection<ContextMenuItem> Items { get; private set; }
public MyViewModel()
{
IsContextActionsLegacyModeEnabled = false;
ToggleLegacyMode = new Command(() => IsContextActionsLegacyModeEnabled = !IsContextActionsLegacyModeEnabled);
Items = new ObservableCollection<ContextMenuItem>();
Items.Add(new ContextMenuItem { Item1Text = "Lorem", Text = "Cell 1", Type = ContextMenuItemType.Temp1 });
Items.Add(new ContextMenuItem { Item2Text = "Ipsum", Text = "Cell 2", Type = ContextMenuItemType.Temp2 });
Items.Add(new ContextMenuItem { Item1Text = "Dictum", Text = "Cell 3", Type = ContextMenuItemType.Temp1 });
Items.Add(new ContextMenuItem { Item2Text = "Vestibulum", Text = "Cell 4", Type = ContextMenuItemType.Temp2 });
Items.Add(new ContextMenuItem { Item1Text = "Hendrerit", Text = "Cell 5", Type = ContextMenuItemType.Temp1 });
Items.Add(new ContextMenuItem { Item2Text = "Posuere", Text = "Cell 6", Type = ContextMenuItemType.Temp2 });
Items.Add(new ContextMenuItem { Item1Text = "Bibendum", Text = "Cell 7", Type = ContextMenuItemType.Temp1 });
Items.Add(new ContextMenuItem { Item2Text = "Vivamus", Text = "Cell 8", Type = ContextMenuItemType.Temp2 });
Items.Add(new ContextMenuItem { Item1Text = "Enim", Text = "Cell 9", Type = ContextMenuItemType.Temp1 });
Items.Add(new ContextMenuItem { Item2Text = "Quis", Text = "Cell 10", Type = ContextMenuItemType.Temp2 });
Items.Add(new ContextMenuItem { Item1Text = "Phasellus", Text = "Cell 11", Type = ContextMenuItemType.Temp1 });
Items.Add(new ContextMenuItem { Item2Text = "Pretium", Text = "Cell 12", Type = ContextMenuItemType.Temp2 });
Items.Add(new ContextMenuItem { Item1Text = "Aliquam", Text = "Cell 13", Type = ContextMenuItemType.Temp1 });
Items.Add(new ContextMenuItem { Item2Text = "Tristique", Text = "Cell 14", Type = ContextMenuItemType.Temp2 });
Items.Add(new ContextMenuItem { Item1Text = "Malesuada", Text = "Cell 15", Type = ContextMenuItemType.Temp1 });
Items.Add(new ContextMenuItem { Item2Text = "Dolor", Text = "Cell 16", Type = ContextMenuItemType.Temp2 });
Items.Add(new ContextMenuItem { Item1Text = "Id", Text = "Cell 17", Type = ContextMenuItemType.Temp1 });
Items.Add(new ContextMenuItem { Item2Text = "Orci", Text = "Cell 18", Type = ContextMenuItemType.Temp2 });
Items.Add(new ContextMenuItem { Item1Text = "Diam", Text = "Cell 19", Type = ContextMenuItemType.Temp1 });
Items.Add(new ContextMenuItem { Item2Text = "Nibh", Text = "Cell 20", Type = ContextMenuItemType.Temp2 });
Items.Add(new ContextMenuItem { Item1Text = "Non", Text = "Cell 21", Type = ContextMenuItemType.Temp1 });
Items.Add(new ContextMenuItem { Item2Text = "Aliquam", Text = "Cell 22", Type = ContextMenuItemType.Temp2 });
Items.Add(new ContextMenuItem { Item1Text = "Ultrices", Text = "Cell 23", Type = ContextMenuItemType.Temp1 });
Items.Add(new ContextMenuItem { Item2Text = "Vulputate", Text = "Cell 24", Type = ContextMenuItemType.Temp2 });
}
}
#if UITEST && __ANDROID__
[Test]
[Category(Core.UITests.UITestCategories.ListView)]
public void RefreshContextActions()
{
RunningApp.WaitForElement("Cell 1");
RunningApp.Screenshot("I am at Issue 1455");
RunningApp.TouchAndHold(q => q.Marked("Cell 4"));
RunningApp.Screenshot("Long Press Cell 4 to show context actions");
RunningApp.Tap(q => q.Marked("Cell 5"));
RunningApp.Screenshot("Clicked another cell and changed menu items");
Assert.AreEqual(1, RunningApp.Query(c => c.Marked("Hendrerit")).Length);
RunningApp.Back();
RunningApp.WaitForElement("Toggle LegacyMode");
RunningApp.Tap(q => q.Marked("Toggle LegacyMode"));
RunningApp.TouchAndHold(q => q.Marked("Cell 4"));
RunningApp.Screenshot("Long Press Cell 4 to show context actions");
RunningApp.Tap(q => q.Marked("Cell 5"));
RunningApp.Screenshot("Clicked another cell and changed menu items");
Assert.AreEqual(1, RunningApp.Query(c => c.Marked("Vestibulum")).Length);
}
#endif
}
public enum ContextMenuItemType
{
Temp1,
Temp2
}
[Preserve(AllMembers = true)]
public class ContextMenuItem
{
public ContextMenuItemType Type { get; set; } = ContextMenuItemType.Temp1;
public string Item1Text { get; set; } = "Text 1";
public string Item2Text { get; set; } = "Text 2";
public string Item3Text { get; set; } = "Text 3";
public string Item4Text { get; set; } = "Text 4";
public string Text { get; set; }
}
[Preserve(AllMembers = true)]
public class Issue1455DataTemplateSelector : DataTemplateSelector
{
public DataTemplate Temp1Template { get; set; }
public DataTemplate Temp2Template { get; set; }
protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
{
return ((ContextMenuItem)item).Type == ContextMenuItemType.Temp1 ? Temp1Template : Temp2Template;
}
}
}