summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Tizen/Cells/SwitchCellRenderer.cs
blob: a676478142b972c43034912f331d2fe6e6daddf4 (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
using System.Collections.Generic;
using ElmSharp;

namespace Xamarin.Forms.Platform.Tizen
{
	public class SwitchCellRenderer : CellRenderer
	{
		readonly Dictionary<EvasObject, VisualElement> _cacheCandidate = new Dictionary<EvasObject, VisualElement>();

		protected SwitchCellRenderer(string style) : base(style)
		{
		}

		public SwitchCellRenderer() : this("end_icon")
		{
			MainPart = "elm.text";
			SwitchPart = "elm.swallow.end";
		}

		protected string MainPart { get; set; }
		protected string SwitchPart { get; set; }

		protected override Span OnGetText(Cell cell, string part)
		{
			if (part == MainPart)
			{
				return new Span()
				{
					Text = (cell as SwitchCell).Text
				};
			}
			return null;
		}

		protected override EvasObject OnGetContent(Cell cell, string part)
		{
			if (part == SwitchPart)
			{
				var toggle = new Switch()
				{
				};
				toggle.SetBinding(Switch.IsToggledProperty, new Binding(SwitchCell.OnProperty.PropertyName));
				toggle.BindingContext = cell;
				toggle.Parent = cell.Parent;
				var nativeView = Platform.GetOrCreateRenderer(toggle).NativeView;
				return nativeView;
			}
			return null;
		}

		protected override EvasObject OnReusableContent(Cell cell, string part, EvasObject old)
		{
			if (!_cacheCandidate.ContainsKey(old))
			{
				return null;
			}
			_cacheCandidate[old].BindingContext = cell;
			return old;
		}

		protected override bool OnCellPropertyChanged(Cell cell, string property, Dictionary<string, EvasObject> realizedView)
		{
			if (property == SwitchCell.TextProperty.PropertyName)
			{
				return true;
			}
			return base.OnCellPropertyChanged(cell, property, realizedView);
		}
	}
}