summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue889.cs
blob: 75b08a1b1b8a9fb9ebbcd05c9080be10e1f74d85 (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
using System.Diagnostics;

using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

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

namespace Xamarin.Forms.Controls.Issues
{
	[Preserve (AllMembers=true)]
	[Issue (IssueTracker.Github, 889, "Assigning to MasterDetailPage.Detail after construction doesn't work", PlatformAffected.Android | PlatformAffected.iOS)]
	public class Issue889 : TestMasterDetailPage
	{
		protected override void Init ()
		{
			var cells = new [] {
				new NavPageNameObject ("Page 1"),
				new NavPageNameObject ("Page 3"),
				new NavPageNameObject ("Page 4"),
				new NavPageNameObject ("Page 5"),
				new NavPageNameObject ("Page 6"),
				new NavPageNameObject ("Page 7"),
				new NavPageNameObject ("Page 8"),
			};

			var template = new DataTemplate (typeof (TextCell));
			template.SetBinding (TextCell.TextProperty, "PageName");

			var listView = new ListView { 
				ItemTemplate = template,
				ItemsSource = cells
			};

			listView.BindingContext = cells;

			listView.ItemTapped += (sender, e) => {
				var cellName = ((NavPageNameObject)e.Item).PageName;
				Detail = new CustomNavTabDetailPage (cellName);
			};

			var master = new ContentPage {
				Title = "Master",
				Icon = "bank.png",
				Content = listView
			};



			Master = master;
			Detail = new CustomNavTabDetailPage ("Initial Page");
		}

		// Issue892
		// NavigationPage nested in MasterDetail not working as expected Android

#if UITEST
		[Test]
		[Description ("Reproduce app crash - Issue #983")]
		[UiTest (typeof(MasterDetailPage), "Detail")]
		public void Issue899TestsAppCrashWhenSwitchingTabs ()
		{
			RunningApp.Tap (q => q.Marked ("Push new page"));
			RunningApp.WaitForElement (q => q.Marked ("I have been pushed"));
			RunningApp.Screenshot ("Push page");
			RunningApp.Back ();
			RunningApp.Screenshot ("Navigate back");

			RunningApp.Tap (q => q.Marked ("Tab 2 Title"));
			RunningApp.Screenshot ("Go to second tab");
		}
#endif
	}

	public class CustomNavTabDetailPage : NavigationPage
	{
		public CustomNavTabDetailPage (string pageName)
		{
			PushAsync (new NestedNavTabPageRootView (pageName));
		}
	}

	public class NestedNavTabPageRootView : TabbedPage
	{
		public NestedNavTabPageRootView (string pageTitle)
		{
			Title = pageTitle;

			var tabOne = new ContentPage {
				Title = "Tab 1 Title",
				BackgroundColor = Color.FromHex ("#666"),
				Content = new StackLayout {
					Children = {
						new Button {
							Text = "Push new page",
							Command = new Command (() => Navigation.PushAsync (new NestedNavTabPageOneLevel ()))
						}
					}
				}
			};

			var tabTwo = new ContentPage {
				Title = "Tab 2 Title",
				BackgroundColor = Color.FromHex ("#BBB"),
				Content = new StackLayout {
					Children = {
						new Button {
							Text = "Push new page",
							Command = new Command (() => Navigation.PushAsync (new NestedNavTabPageOneLevel ()))
						}
					}
				}
			};

			tabOne.SetValue (IconProperty, "bank.png");
			tabTwo.SetValue (IconProperty, "coffee.png");
			Children.Add (tabOne);
			Children.Add (tabTwo);
		}
	}

	public class NestedNavTabPageOneLevel : ContentPage
	{
		public NestedNavTabPageOneLevel ()
		{
			Title = "One pushed";
			BackgroundColor = Color.FromHex("#999");

			Content = new StackLayout {
				Children = {
					new Label {
						TextColor = Color.Red,
						Text = "I have been pushed"
					}
				}
			};
		}
	}
}