summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla37841.cs
blob: 1a3245e8bc09ac5e1ee6f0eb182bdadeadcedd67 (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
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
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
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, 37841, "TableView EntryCells and TextCells cease to update after focus change", PlatformAffected.Android)]
	public class Bugzilla37841 : TestContentPage
	{
		_37841ViewModel _viewModel;

		protected override void Init ()
		{
			_viewModel = new _37841ViewModel ();

			var instructions = new Label { FontSize = 16, Text = @"Click on the Generate button. 
The EntryCell should display '12345' and the TextCell should display '6789'. 
Click on the Generate button a second time. 
The EntryCell should display '112358' and the TextCell should display '48151623'." };

			var button = new Button { Text = "Generate" };
			button.SetBinding (Button.CommandProperty, nameof (_37841ViewModel.GetNextNumbersCommand));

			var random1 = new EntryCell { IsEnabled = false, Label = "Entry Cell" };
			random1.SetBinding (EntryCell.TextProperty, nameof (_37841ViewModel.Value1));

			var textCell = new TextCell { IsEnabled = false, Detail = "TextCell" };
			textCell.SetBinding (TextCell.TextProperty, nameof (_37841ViewModel.Value2));

			var buttonViewCell = new ViewCell { View = button };

			var section = new TableSection ("") {
				random1,
				textCell,
				buttonViewCell
			};

			var root = new TableRoot { section };
			var tv = new TableView { Root = root };

			Content = new StackLayout {
				Children = { instructions, tv }
			};

			BindingContext = _viewModel;
		}

		[Preserve (AllMembers = true)]
		public class _37841ViewModel : INotifyPropertyChanged
		{
			public int Value1
			{
				get { return _value1; }
				set
				{
					if (value != _value1) {
						_value1 = value;
						RaisePropertyChanged ();
					}
				}
			}

			public int Value2
			{
				get { return _value2; }
				set
				{
					if (value != _value2) {
						_value2 = value;
						RaisePropertyChanged ();
					}
				}
			}

			public Command GetNextNumbersCommand
				=> _getNextNumbersCommand ?? (_getNextNumbersCommand = new Command (ExecuteGenerateRandomCommand));

			class SomeNumbers : IEnumerable<int>
			{
				public IEnumerator<int> GetEnumerator ()
				{
					while (true) {
						yield return 12345;
						yield return 6789;
						yield return 112358;
						yield return 48151623;
					}
				}

				IEnumerator IEnumerable.GetEnumerator ()
				{
					return GetEnumerator ();
				}
			}

			readonly IEnumerator<int> _numberList = new SomeNumbers ().GetEnumerator ();

			void ExecuteGenerateRandomCommand ()
			{
				_numberList.MoveNext ();
				Value1 = _numberList.Current;
				_numberList.MoveNext ();
				Value2 = _numberList.Current;
			}

			void RaisePropertyChanged ([CallerMemberName] string propertyName = null)
			{
				PropertyChangedEventHandler handler = PropertyChanged;

				handler?.Invoke (this, new PropertyChangedEventArgs (propertyName));
			}

			#region INotifyPropertyChanged implementation

			public event PropertyChangedEventHandler PropertyChanged;

			#endregion

			Command _getNextNumbersCommand;
			int _value1;
			int _value2;
		}

#if UITEST
		[Test]
		public void TextAndEntryCellsDataBindInTableView()
		{
			RunningApp.WaitForElement ("Generate");
			RunningApp.Tap("Generate");

			RunningApp.Screenshot ("First Generate Tap");

			RunningApp.WaitForElement("12345");
			RunningApp.WaitForElement("6789");

			RunningApp.Tap("Generate");

			RunningApp.Screenshot("Second Generate Tap");

			RunningApp.WaitForElement("112358");
			RunningApp.WaitForElement("48151623");
		}
#endif
	}
}