summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core/Effect.cs
blob: 895284461a02bf698c9062e2caecd49c623f40c3 (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
using System;
using System.ComponentModel;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms
{
	public abstract class Effect
	{
		internal Effect()
		{
		}

		public Element Element { get; internal set; }

		public bool IsAttached { get; private set; }

		public string ResolveId { get; internal set; }

		#region Statics

		public static Effect Resolve(string name)
		{
			Type effectType;
			Effect result = null;
			if (Registrar.Effects.TryGetValue(name, out effectType))
			{
				result = (Effect)Activator.CreateInstance(effectType);
			}

			if (result == null)
				result = new NullEffect();
			result.ResolveId = name;
			return result;
		}

		#endregion

		// Received after Control/Container/Element made valid
		protected abstract void OnAttached();

		// Received after Control/Container made invalid
		protected abstract void OnDetached();

		internal virtual void ClearEffect()
		{
			if (IsAttached)
				SendDetached();
			Element = null;
		}

		internal virtual void SendAttached()
		{
			if (IsAttached)
				return;
			OnAttached();
			IsAttached = true;
		}

		internal virtual void SendDetached()
		{
			if (!IsAttached)
				return;
			OnDetached();
			IsAttached = false;
		}

		internal virtual void SendOnElementPropertyChanged(PropertyChangedEventArgs args)
		{
		}
	}
}