summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android/Cells/CellFactory.cs
blob: 0967fa1651ab7aed4185cf7bb76bf5fead1c6147 (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
using Android.Content;
using Android.Views;
using AView = Android.Views.View;
using AListView = Android.Widget.ListView;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms.Platform.Android
{
	public static class CellFactory
	{
		public static AView GetCell(Cell item, AView convertView, ViewGroup parent, Context context, View view)
		{
			CellRenderer renderer = CellRenderer.GetRenderer(item);
			if (renderer == null)
			{
				renderer = Registrar.Registered.GetHandler<CellRenderer>(item.GetType());
				renderer.ParentView = view;
			}

			AView result = renderer.GetCell(item, convertView, parent, context);

			if (view is TableView)
				UpdateMinimumHeightFromParent(context, result, (TableView)view);
			else if (view is ListView)
				UpdateMinimumHeightFromParent(context, result, (ListView)view);

			return result;
		}

		static void UpdateMinimumHeightFromParent(Context context, AView view, TableView table)
		{
			if (!table.HasUnevenRows && table.RowHeight > 0)
				view.SetMinimumHeight((int)context.ToPixels(table.RowHeight));
		}

		static void UpdateMinimumHeightFromParent(Context context, AView view, ListView listView)
		{
			if (!listView.HasUnevenRows && listView.RowHeight > 0)
				view.SetMinimumHeight((int)context.ToPixels(listView.RowHeight));
		}
	}
}