summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Tizen/Renderers/LayoutRenderer.cs
blob: c2df8061de92ba1f0c0341ba48936307cb95ce5d (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
using System;

namespace Xamarin.Forms.Platform.Tizen
{
	/// <summary>
	/// Renderer of a Layout.
	/// </summary>
	public class LayoutRenderer : ViewRenderer<Layout, Native.Canvas>
	{
		bool _isLayoutUpdatedRegistered = false;

		public void RegisterOnLayoutUpdated()
		{
			if (!_isLayoutUpdatedRegistered)
			{
				Control.LayoutUpdated += OnLayoutUpdated;
				_isLayoutUpdatedRegistered = true;
			}
		}

		protected override void OnElementChanged(ElementChangedEventArgs<Layout> e)
		{
			if (null == Control)
			{
				var canvas = new Native.Canvas(Forms.Context.MainWindow);
				SetNativeControl(canvas);
			}

			base.OnElementChanged(e);
		}

		protected override void Dispose(bool disposing)
		{
			if (_isLayoutUpdatedRegistered)
			{
				Control.LayoutUpdated -= OnLayoutUpdated;
			}

			base.Dispose(disposing);
		}

		void OnLayoutUpdated(object sender, Native.LayoutEventArgs e)
		{
			DoLayout(e);
		}
	}
}