summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla32615.cs
blob: 861664a8c892fa0136be9c779847cce4c9000dbf (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
using System;

using Xamarin.Forms.CustomAttributes;
using System.Threading.Tasks;
using Xamarin.Forms.Internals;

#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls
{
	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Bugzilla, 32615, "OnAppearing is not called on previous page when modal page is popped")]
	public class Bugzilla32615 : TestContentPage // or TestMasterDetailPage, etc ...
	{
		int _counter;
		Label _textField;
		protected override void Init ()
		{
			var btnModal = new Button { AutomationId = "btnModal",  Text = "open",  HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand };
			btnModal.Clicked += async (sender, e) => await Navigation.PushModalAsync (new Bugzilla32615Page2 ());
			_textField = new Label { AutomationId = "lblCount"};
			var layout = new StackLayout ();
			layout.Children.Add (btnModal);
			layout.Children.Add (_textField);
			// Initialize ui here instead of ctor
			Content = layout;
		}

		protected override void OnAppearing()
		{
			_textField.Text = _counter++.ToString();
		}

		class Bugzilla32615Page2 : ContentPage
		{
			public Bugzilla32615Page2 ()
			{
				var btnPop = new Button { AutomationId = "btnPop",  Text = "pop",  HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand };
				btnPop.Clicked += async (sender, e) => await Navigation.PopModalAsync ();
				Content = btnPop;
			}

			protected override void OnDisappearing ()
			{
				System.Diagnostics.Debug.WriteLine ("Disappearing Modal");
				base.OnDisappearing ();
			}

			protected override void OnAppearing ()
			{
				System.Diagnostics.Debug.WriteLine ("Appearing Modal");
				base.OnAppearing ();
			}
		}

#if UITEST
		[Test]
		public async Task Bugzilla32615Test ()
		{
			RunningApp.Tap (q => q.Marked ("btnModal"));
			RunningApp.Tap (q => q.Marked ("btnPop"));
			await Task.Delay (1000);
			var lbl = RunningApp.WaitForElement (c => c.Marked("lblCount"));
			Assert.AreEqual ("1", lbl [0].Text);
		}
#endif
	}
}