summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla40722.cs
blob: 1ce0482f0d4dfb087c0a8e171cc6760f85e7720f (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
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific.AppCompat;

namespace Xamarin.Forms.Controls
{
	[Preserve(AllMembers = true)]
	[Issue(IssueTracker.Bugzilla, 40722, "Using FormsAppCompatActivity calls OnDisappearing on device sleep")]
	public class Bugzilla40722 : TestContentPage
	{
		const string ButtonText_Disable = "Disable Pause/Resume events";
		const string ButtonText_Enable = "Enable Pause/Resume events";
		const string Instructions_Disabled = "Sleep the device, then wake it. If \"Disappearing!\" and/or \"Appearing!\" is displayed on this screen, this test has failed.";
		const string Instructions_Enabled = "Sleep the device, then wake it. If \"Disappearing!\" and/or \"Appearing!\" is NOT displayed on this screen, this test has failed.";

		Label _Target = new Label();
		bool _sendEvents = true;

		protected override void Init()
		{
			ToggleEvents(_sendEvents);

			var instructions = new Label
			{
				Text = Instructions_Enabled
			};

			var button = new Button
			{
				Text = ButtonText_Disable
			};

			button.Clicked += (sender, e) =>
			{
				_sendEvents = !_sendEvents;
				ToggleEvents(_sendEvents);
				button.Text = _sendEvents ? ButtonText_Disable : ButtonText_Enable;
				instructions.Text = _sendEvents ? Instructions_Enabled : Instructions_Disabled;
				_Target.Text = "";
			};

			Content = new StackLayout { Children = { instructions, button, _Target } };
		}


		protected override void OnAppearing()
		{
			base.OnAppearing();

			_Target.Text += "\r\nAppearing!";
		}

		protected override void OnDisappearing()
		{
			base.OnDisappearing();

			_Target.Text += "\r\nDisappearing!";
		}

		void ToggleEvents(bool value)
		{
			Application.Current.On<Android>()
							.SendDisappearingEventOnPause(value)
							.SendAppearingEventOnResume(value);
		}
	}
}