summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla34632.cs
blob: 30cbc5a867a7142dbd40cb3e722d3525ff88340d (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
using System;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

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

namespace Xamarin.Forms.Controls.Issues
{
	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Bugzilla, 34632, "Can't change IsPresented when setting SplitOnLandscape ")]
	public class Bugzilla34632 : TestMasterDetailPage
	{
		protected override void Init ()
		{
			if (Device.RuntimePlatform == Device.Windows)
				MasterBehavior = MasterBehavior.Split;
			else
				MasterBehavior = MasterBehavior.SplitOnLandscape;

			Master = new ContentPage { Title = "Main Page", 
				Content = new Button { Text = "Master", AutomationId = "btnMaster", 
					Command = new Command (() => {
						//If we're in potrait toggle hide the menu on click
						if (Width < Height || Device.Idiom == TargetIdiom.Phone) {
							IsPresented = false;
						}
					})
				} 
			};

			Detail = new NavigationPage (new ModalRotationIssue ());
			NavigationPage.SetHasBackButton (Detail, false);
		}

		[Preserve (AllMembers = true)]
		public class ModalRotationIssue : ContentPage
		{
			public ModalRotationIssue ()
			{
				var btn = new Button { Text = "Open Modal", AutomationId = "btnModal"  };
				btn.Clicked += OnButtonClicked;
				Content = btn;
			}

			async void OnButtonClicked (object sender, EventArgs e)
			{
				var testButton = new Button { Text = "Rotate Before Clicking", AutomationId = "btnDismissModal" };
				testButton.Clicked += (async (snd, args) => await Navigation.PopModalAsync ());

				var testModal = new ContentPage () {
					Content = testButton
				};

				await Navigation.PushModalAsync (testModal);
			}
		}

		#if UITEST
		[Test]
		public void Bugzilla34632Test ()
		{
			var app = RunningApp as iOSApp;
			if (app != null && app.Device.IsTablet) {
				RunningApp.SetOrientationPortrait ();
				RunningApp.Tap (q => q.Marked ("btnModal"));
				RunningApp.SetOrientationLandscape ();
				RunningApp.Tap (q => q.Marked ("btnDismissModal"));
				RunningApp.Tap (q => q.Marked ("btnModal"));
				RunningApp.SetOrientationPortrait ();
				RunningApp.Tap (q => q.Marked ("btnDismissModal"));
				RunningApp.Tap (q => q.Marked ("btnMaster"));
			}
		}

		[TearDown]
		public void TearDown() 
		{
			RunningApp.SetOrientationPortrait ();
		}
		#endif
	}
}