summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla30835.cs
blob: f68c873bb692acf297408f373934e7ebd3097c38 (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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
using System;

using Xamarin.Forms.CustomAttributes;
using System.Collections.Generic;
using Xamarin.Forms.Internals;

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

namespace Xamarin.Forms.Controls
{
	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Bugzilla, 30835, "Navigating to and from the Carousel page with MasterDetail page creates an Out of memory exception")]
	public class Bugzilla30835 : TestMasterDetailPage // or TestMasterDetailPage, etc ...
	{
		protected override void Init ()
		{
			var menuPage = new MenuPage ();

			menuPage.Menu.ItemSelected += (sender, e) => NavigateTo (e.SelectedItem as MenuItem);

			Master = menuPage;
			Detail = new NavigationPage (new HolderCarouselPages ());
		}

		void NavigateTo (MenuItem menu)
		{
			var displayPage = (Page)Activator.CreateInstance (menu.TargetType);
			Detail = new NavigationPage (displayPage);
			IsPresented = false;
		}

		[Preserve (AllMembers = true)]
		public class HolderCarouselPages : CarouselPage
		{
			public HolderCarouselPages ()
			{
				Device.BeginInvokeOnMainThread (() => {
					ItemsSource = new HolderImage[] {				
						new HolderImage ("frog", "photo.jpg"),
						new HolderImage ("history", "photo.jpg"),
						new HolderImage ("Test", "photo.jpg"), 
					};			
				});

				ItemTemplate = new DataTemplate (() => new DisplayContentPage ());
			}
		}

		[Preserve (AllMembers = true)]
		public class HolderImage
		{
			public HolderImage (string name, string images)
			{
				Name = name;
				Homeimages = images;
			}

			public string Name { private set; get; }

			public string Homeimages { private set; get; }

			public override string ToString ()
			{
				return Name;
			}
		}

		[Preserve (AllMembers = true)]
		public class DisplayContentPage : ContentPage
		{
			public DisplayContentPage ()
			{
				var imageView = new Image {
					HorizontalOptions = LayoutOptions.Center,
				};

				Content = new StackLayout {
					Children = {
						new StackLayout {   
							HorizontalOptions = LayoutOptions.Center,
							VerticalOptions = LayoutOptions.StartAndExpand,
							Children = {
								imageView
							}
						},
					}
				};
				imageView.SetBinding (Image.SourceProperty, "Homeimages");
			}
		}

		[Preserve (AllMembers = true)]
		public class MenuPage : ContentPage
		{
			public ListView Menu { get; set; }

			public MenuPage ()
			{
				Icon = "bank.png";
				Title = "Carsousel Memory Bug";
				BackgroundColor = Color.FromHex ("#000000");

				Menu = new MenuListView ();

				var menuLabel = new ContentView {
					Padding = new Thickness (10, 36, 0, 5),
					Content = new Label {
						TextColor = Color.FromHex ("#FFFFFF"),
						Text = "Carsousel Memory Bug",
					}
				};

				var layout = new StackLayout { 
					Spacing = 0, 
					VerticalOptions = LayoutOptions.FillAndExpand,
				};
				layout.Children.Add (menuLabel);
				layout.Children.Add (Menu);

				Content = layout;
			}
		}

		[Preserve (AllMembers = true)]
		public class MenuListView : ListView
		{
			public MenuListView ()
			{
				List<MenuItem> data = new MenuListData ();

				ItemsSource = data;
				VerticalOptions = LayoutOptions.FillAndExpand;
				BackgroundColor = Color.Black;

				var cell = new DataTemplate (typeof(ImageCell));
				cell.SetBinding (TextCell.TextColorProperty, "TextColor");
				cell.SetBinding (TextCell.TextProperty, "Title");
				cell.SetBinding (ImageCell.ImageSourceProperty, "IconSource");

				ItemTemplate = cell;
				SelectedItem = data [0];
			}
		}

		[Preserve (AllMembers = true)]
		public class MenuListData : List<MenuItem>
		{
			public MenuListData ()
			{
				Add (new MenuItem () { 
					Title = "Carousel", 
					IconSource = "icon.png", 
					TargetType = typeof(HolderCarouselPages),
					TextColor = Color.White
				});

				Add (new MenuItem () { 
					Title = "Pic 1",
					IconSource = "icon.png", 
					TargetType = typeof(Pic1),
					TextColor = Color.White
				});

				Add (new MenuItem () { 
					Title = "Pic 2", 
					IconSource = "icon.png", 
					TargetType = typeof(Pic1),
					TextColor = Color.White
				});	

				Add (new MenuItem () {
					Title = "Pic 3",
					IconSource = "icon.png",
					TargetType = typeof(Pic1),
					TextColor = Color.White
				});
			}
		}

		[Preserve (AllMembers = true)]
		public class MenuItem
		{
			public string Title { get; set; }

			public string IconSource { get; set; }

			public Type TargetType { get; set; }

			public Color TextColor { get ; set; }
		}

		[Preserve (AllMembers = true)]
		public class Pic1 : ContentPage
		{
			public Pic1 ()
			{
				Content = new StackLayout { 
					Children = {
						new Image { Source = "photo.jpg" }
					}
				};
			}
		}
	}
}