summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/ModalActivityIndicatorTest.cs
blob: 2c8c8a2df61d1a37e612cb6f897a8c058a68d293 (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
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms.Controls
{
	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.None, 0, "Activity Indicator Does Not Show when set to default color")]
	public class ModalActivityIndicatorTest : TestContentPage 
	{
		protected override void Init ()
		{
			var vm = new ModalActivityIndicatorModel () { IsBusy = false, BusyText = "Not busy" };

	 		var button = new Button () { Text = "Make Busy" };
			var colorToggle = new Button() {Text = "Toggle Activity Indicator Color" };

			button.Clicked += async (sender, args) => {
				vm.IsBusy = true;
				vm.BusyText = "Busy";
				await Task.Delay (1500);
				vm.IsBusy = false;
				vm.BusyText = "Not Busy";
			};
			
			var activityIndicator = new ModalActivityIndicator();
			activityIndicator.BindingContext = vm;

			colorToggle.Clicked += (sender, args) => {
				vm.Color = vm.Color.IsDefault ? Color.Green : Color.Default;
			};

			Content = new StackLayout() {
				Children = { button, colorToggle, activityIndicator }
			};
		}

		[Preserve(AllMembers = true)]
		public class ModalActivityIndicatorModel : INotifyPropertyChanged
		{
			bool _isBusy;
			string _busyText;
			Color _color;

			public ModalActivityIndicatorModel ()
			{
				_color = Color.Default;
			}

			public bool IsBusy
			{
				get { return _isBusy; }
				set
				{
					_isBusy = value; 
					OnPropertyChanged();
				}
			}

			public string BusyText
			{
				get { return _busyText; }
				set
				{
					_busyText = value;
					OnPropertyChanged();
				}
			}

			public Color Color
			{
				get { return _color; }
				set
				{
					_color = value; 
					OnPropertyChanged();
				}
			}

			public event PropertyChangedEventHandler PropertyChanged;

			protected virtual void OnPropertyChanged ([CallerMemberName] string propertyName = null)
			{
				PropertyChanged?.Invoke (this, new PropertyChangedEventArgs (propertyName));
			}
		}

		[Preserve(AllMembers = true)]
		public class ModalActivityIndicator : RelativeLayout
		{
			public ModalActivityIndicator()
			{
				this.SetBinding(IsVisibleProperty, "IsBusy");
				this.SetBinding(IsEnabledProperty, "IsBusy");

				Children.Add(
					view: new BoxView
					{
						Opacity = .4,
						BackgroundColor = Color.FromHex("#ccc")
					},
					widthConstraint: Forms.Constraint.RelativeToParent((parent) => {
						return parent.Width;
					}),
					heightConstraint: Forms.Constraint.RelativeToParent((parent) => {
						return parent.Height;
					})
					);

				var content = new StackLayout
				{
					BackgroundColor = Color.White,
					Spacing = 10,
					Padding = new Thickness(
						horizontalSize: 10,
						verticalSize: 20
						)
				};

				var activityIndicator = new ActivityIndicator { IsRunning = true };
				activityIndicator.SetBinding(ActivityIndicator.ColorProperty, "Color");

				content.Children.Add(activityIndicator);
				var label = new Label { HorizontalOptions = LayoutOptions.CenterAndExpand };

				label.SetBinding(Label.TextProperty, "BusyText");
				label.SetBinding(Label.TextColorProperty, "Color");

				content.Children.Add(label);

				Children.Add(
					view: content,
					widthConstraint: Forms.Constraint.RelativeToParent((parent) => {
						return parent.Width / 2;
					}),
					heightConstraint: Forms.Constraint.RelativeToParent((parent) => {
						return parent.Width / 3;
					}),
					xConstraint: Forms.Constraint.RelativeToParent((parent) => {
						return parent.Width / 4;
					}),
					yConstraint: Forms.Constraint.RelativeToParent((parent) => {
						return (parent.Height / 2) - (parent.Width / 6);
					})
					);
			}
		}
	}
}