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

namespace Xamarin.Forms.Platform.Tizen
{
	public class ImageCellRenderer : TextCellRenderer
	{
		const int _defaultHeight = 100;
		Dictionary<EvasObject, Native.Image> _realizedViews = new Dictionary<EvasObject, Native.Image>();

		public ImageCellRenderer() : this("type1")
		{
			ImagePart = "elm.swallow.icon";
		}
		protected ImageCellRenderer(string style) : base(style) { }

		protected string ImagePart { get; set; }

		protected override EvasObject OnGetContent(Cell cell, string part)
		{
			if (part == ImagePart)
			{
				var imgCell = cell as ImageCell;
				var size = imgCell.RenderHeight;
				if (size <= 0)
				{
					size = _defaultHeight;
				}

				var image = new Native.Image(Forms.Context.MainWindow)
				{
					MinimumWidth = (int)size,
					MinimumHeight = (int)size
				};
				image.SetAlignment(-1.0, -1.0); // fill
				image.SetWeight(1.0, 1.0); // expand

				image.LoadFromImageSourceAsync(imgCell.ImageSource);
				return image;
			}
			else
			{
				return null;
			}
		}

		protected override bool OnCellPropertyChanged(Cell cell, string property, Dictionary<string, EvasObject> realizedView)
		{
			if (property == ImageCell.ImageSourceProperty.PropertyName)
			{
				EvasObject image;
				realizedView.TryGetValue(ImagePart, out image);
				(image as Native.Image)?.LoadFromImageSourceAsync((cell as ImageCell)?.ImageSource);
				return false;
			}
			return base.OnCellPropertyChanged(cell, property, realizedView);
		}

	}
}