--- /dev/null
+using System;
+using ElmSharp;
+using System.Collections.Generic;
+
+namespace Xamarin.Forms.Platform.Tizen.Native
+{
+ public static class NativeFactory
+ {
+ static List<Label> labels = new List<Label>();
+ static List<Image> images = new List<Image>();
+ static List<Canvas> canvases = new List<Canvas>();
+ static List<Page> pages = new List<Page>();
+ const int hfrequency = 6;
+ const int lfrequency = 3;
+
+ public static void PrecreateNatives(EvasObject window)
+ {
+ for (int i = 0; i < hfrequency; i++)
+ {
+ var label = new Label(window);
+ label.Hide();
+ labels.Add(label);
+
+ var image = new Image(window);
+ image.Hide();
+ images.Add(image);
+ }
+
+ for (int i = 0; i < lfrequency; i++)
+ {
+ var page = new Page(window);
+ page.Hide();
+ pages.Add(page);
+
+ var canvas = new Canvas(window);
+ canvas.Hide();
+ canvases.Add(canvas);
+ }
+ }
+
+ public static EvasObject GetNativeControl(Type type)
+ {
+ if (type == typeof(Label))
+ {
+ if (labels.Count >= 1)
+ {
+ Label native = labels[labels.Count - 1];
+ labels.RemoveAt(labels.Count - 1);
+ return native;
+ }
+ return new Label(Forms.NativeParent);
+ }
+ else if (type == typeof(Image))
+ {
+ if (images.Count >= 1)
+ {
+ Image native = images[images.Count - 1];
+ images.RemoveAt(images.Count - 1);
+ return native;
+ }
+ return new Image(Forms.NativeParent);
+ }
+ else if (type == typeof(Canvas))
+ {
+ if (canvases.Count >= 1)
+ {
+ Canvas native = canvases[canvases.Count - 1];
+ canvases.RemoveAt(canvases.Count - 1);
+ return native;
+ }
+ return new Canvas(Forms.NativeParent);
+ }
+ else if (type == typeof(Page))
+ {
+ if (pages.Count >= 1)
+ {
+ Page native = pages[pages.Count - 1];
+ pages.RemoveAt(pages.Count - 1);
+ return native;
+ }
+ return new Page(Forms.NativeParent);
+ }
+ return Activator.CreateInstance(type, new[] { Forms.NativeParent }) as EvasObject;
+ }
+
+ public static void DeleteUnusedNative()
+ {
+ for (int i=0; i< labels.Count; i++)
+ {
+ Label native = labels[labels.Count - 1];
+ labels.RemoveAt(labels.Count - 1);
+ native.Unrealize();
+ }
+ for (int i = 0; i < images.Count; i++)
+ {
+ Image native = images[images.Count - 1];
+ images.RemoveAt(images.Count - 1);
+ native.Unrealize();
+ }
+ for (int i = 0; i < pages.Count; i++)
+ {
+ Page native = pages[pages.Count - 1];
+ pages.RemoveAt(pages.Count - 1);
+ native.Unrealize();
+ }
+ for (int i = 0; i < canvases.Count; i++)
+ {
+ Canvas native = canvases[canvases.Count - 1];
+ canvases.RemoveAt(canvases.Count - 1);
+ native.Unrealize();
+ }
+ }
+ }
+}
\ No newline at end of file