Modified NativeFactory for Xamarin.Forms 4.6.0 and CircularUI 1.5.0 (#226)
author윤정현/Common Platform Lab(SR)/Staff Engineer/삼성전자 <jh0506.yun@samsung.com>
Fri, 15 May 2020 07:55:56 +0000 (16:55 +0900)
committer안주원/Common Platform Lab(SR)/Principal Engineer/삼성전자 <juwon.ahn@samsung.com>
Fri, 15 May 2020 07:55:56 +0000 (16:55 +0900)
* Modified NativeFactory for Xamarin.Forms 4.6.0 and CircularUI 1.5.0

* Remove Annotation

* Fixed NativeFactory

* Delete unused code

src/XSF/Tizen.Wearable.CircularUI.Forms.Renderer/CircleListViewRenderer.cs
src/XSF/Tizen.Wearable.CircularUI.Forms.Renderer/CircleScrollViewRenderer.cs
src/XSF/Tizen.Wearable.CircularUI.Forms.Renderer/CircularUIForms.cs
src/XSF/Tizen.Wearable.CircularUI.Forms.Renderer/NativeFactory.cs
src/XSF/Xamarin.Forms.Platform.Tizen/Forms.cs
src/XSF/Xamarin.Forms.Platform.Tizen/Native/NativeFactory.cs
src/XSF/Xamarin.Forms.Platform.Tizen/Renderers/ListViewRenderer.cs
src/XSF/Xamarin.Forms.Platform.Tizen/Renderers/ScrollViewRenderer.cs

index 91bb806..aea5018 100644 (file)
@@ -36,7 +36,7 @@ namespace Tizen.Wearable.CircularUI.Forms.Renderer
 
                protected override Xamarin.Forms.Platform.Tizen.Native.ListView CreateNativeControl()
                {
-                       return _listView = new WatchListView(XForms.NativeParent, this.GetSurface());
+                       return _listView = NativeFactory.GetNativeControl(typeof(WatchListView), this.GetSurface()) as WatchListView;
                }
 
                void UpdateBarColor()
index c9b39d2..ef2097b 100644 (file)
@@ -34,8 +34,8 @@ namespace Tizen.Wearable.CircularUI.Forms.Renderer
                }
 
                protected override Xamarin.Forms.Platform.Tizen.Native.Scroller CreateNativeControl()
-                       {
-                       return _scroller = new WatchScroller(XForms.NativeParent, this.GetSurface());
+               {
+                       return _scroller = Xamarin.Forms.Platform.Tizen.Native.NativeFactory.GetNativeControl(typeof(WatchScroller), this.GetSurface()) as WatchScroller;
                }
 
                void UpdateBarColor()
index ad638a3..d1a96d3 100644 (file)
@@ -10,10 +10,9 @@ namespace Tizen.Wearable.CircularUI.Forms
        public static class CircularUIForms
        {
                [EditorBrowsable(EditorBrowsableState.Never)]
-               public static void Preload(object windows)
+               public static void Preload(Xamarin.Forms.Platform.Tizen.PreloadedWindow preloadedWindow)
                {
-                       EvasObject win = windows as EvasObject;
-                       NativeFactory.PrecreateNatives(win);
+                       NativeFactory.PrecreateNatives(preloadedWindow);
                }
 
                public static Dictionary<Type, Func<IRegisterable>> StaticHandlers = new Dictionary<Type, Func<IRegisterable>>()
index cb30e7d..df08725 100644 (file)
@@ -8,89 +8,44 @@ namespace Tizen.Wearable.CircularUI.Forms.Renderer
 {
        class NativeFactory
        {
-               static List<NativeCirclePage> circlePages = new List<NativeCirclePage>();
-               static Dictionary<CircleSurface, CircleListView> circleListviews = new Dictionary<CircleSurface, CircleListView>();
-               static Dictionary<CircleSurface, CircleScroller> circleScrollers = new Dictionary<CircleSurface, CircleScroller>();
-               const int lfrequency = 3;
+               static Dictionary<CircleSurface, WatchListView> watchListviews = new Dictionary<CircleSurface, WatchListView>();
+               const int lfrequency = 1;
 
-               public static void PrecreateNatives(EvasObject window)
+               public static void PrecreateNatives(Xamarin.Forms.Platform.Tizen.PreloadedWindow preloadedWindow)
                {
                        for (int i = 0; i < lfrequency; i++)
                        {
-                               var page = new NativeCirclePage(window);
-                               page.Hide();
-                               circlePages.Add(page);
-
-                               //var listview = new CircleListView(window, page.Surface);
-                               //listview.Hide();
-                               //circleListviews.Add(page.Surface, listview);
-
-                               var scroller = new CircleScroller(window, page.Surface);
-                               scroller.Hide();
-                               circleScrollers.Add(page.Surface, scroller);
+                               var listview = new WatchListView(preloadedWindow.Window, preloadedWindow.BaseCircleSurface);
+                               listview.Hide();
+                               watchListviews.Add(preloadedWindow.BaseCircleSurface, listview);
                        }
                }
 
                public static EvasObject GetNativeControl(Type type, CircleSurface surface = null)
                {
-                       if (type == typeof(NativeCirclePage))
-                       {
-                               if (circlePages.Count >= 1)
-                               {
-                                       NativeCirclePage native = circlePages[circlePages.Count - 1];
-                                       circlePages.Remove(native);
-                                       return native;
-                               }
-                               return new NativeCirclePage(XForms.NativeParent);
-                       }
-                       else if (type == typeof(CircleListView))
+                       if (type == typeof(WatchListView))
                        {
-                               //if (circleListviews.ContainsKey(surface))
-                               //{
-                               //      var listview = circleListviews[surface];
-                               //      if (listview != null)
-                               //      {
-                               //              circleListviews.Remove(surface);
-                               //              return listview;
-                               //      }
-                               //}
-                               //return new CircleListView(XForms.NativeParent, surface);
-                       }
-                       else if (type == typeof(CircleScroller))
-                       {
-                               if (circleScrollers.ContainsKey(surface))
+                               if (watchListviews.ContainsKey(surface))
                                {
-                                       var scroller = circleScrollers[surface];
-                                       if (scroller != null)
+                                       var listview = watchListviews[surface];
+                                       if (listview != null)
                                        {
-                                               circleScrollers.Remove(surface);
-                                               return scroller;
+                                               watchListviews.Remove(surface);
+                                               return listview;
                                        }
                                }
-                               return new CircleScroller(XForms.NativeParent, surface);
+                               return new WatchListView(XForms.NativeParent, surface);
                        }
                        return Activator.CreateInstance(type, new[] { XForms.NativeParent }) as EvasObject;
                }
 
                public static void DeleteUnusedNative()
                {
-                       foreach (var item in circlePages)
-                       {
-                               item.Unrealize();
-                       }
-                       circlePages.Clear();
-
-                       //foreach (var item in circleListviews)
-                       //{
-                       //      item.Value.Unrealize();
-                       //}
-                       //circleListviews.Clear();
-
-                       foreach (var item in circleScrollers)
+                       foreach (var item in watchListviews)
                        {
                                item.Value.Unrealize();
                        }
-                       circleScrollers.Clear();
+                       watchListviews.Clear();
                }
        }
 }
\ No newline at end of file
index 9526161..52686bf 100644 (file)
@@ -732,8 +732,8 @@ namespace Xamarin.Forms
                        PTizen.PreloadedWindow preloadedWindow = new PTizen.PreloadedWindow();
                        if (preloadedWindow.Window != null)
                        {
-                               global::Xamarin.Forms.Platform.Tizen.Native.NativeFactory.PrecreateNatives(preloadedWindow.Window);
-                               global::Tizen.Wearable.CircularUI.Forms.CircularUIForms.Preload(preloadedWindow.Window);
+                               global::Xamarin.Forms.Platform.Tizen.Native.NativeFactory.PrecreateNatives(preloadedWindow);
+                               global::Tizen.Wearable.CircularUI.Forms.CircularUIForms.Preload(preloadedWindow);
                        }
                        else
                        {
index ad4bd44..b2077a1 100644 (file)
@@ -1,5 +1,6 @@
 using System;
 using ElmSharp;
+using ElmSharp.Wearable;
 using System.Collections.Generic;
 
 namespace Xamarin.Forms.Platform.Tizen.Native
@@ -12,47 +13,57 @@ namespace Xamarin.Forms.Platform.Tizen.Native
                static List<EditfieldEntry> editfieldEntrys = new List<EditfieldEntry>();
                static List<Canvas> canvases = new List<Canvas>();
                static List<Page> pages = new List<Page>();
+               static Dictionary<CircleSurface, Watch.WatchListView> watchListviews = new Dictionary<CircleSurface, Watch.WatchListView>();
+               static Dictionary<CircleSurface, Watch.WatchScroller> watchScrollers = new Dictionary<CircleSurface, Watch.WatchScroller>();
                const int hfrequency = 20;
                const int mfrequency = 6;
                const int lfrequency = 3;
 
-               public static void PrecreateNatives(EvasObject window)
+               public static void PrecreateNatives(PreloadedWindow preloadedWindow)
                {
                        for (int i = 0; i < hfrequency; i++)
                        {
-                               var image = new Image(window);
+                               var image = new Image(preloadedWindow.Window);
                                image.Hide();
                                images.Add(image);
                        }
 
                        for (int i = 0; i < mfrequency; i++)
                        {
-                               var label = new Label(window);
+                               var label = new Label(preloadedWindow.Window);
                                label.Hide();
                                labels.Add(label);
                        }
 
                        for (int i = 0; i < lfrequency; i++)
                        {
-                               var page = new Page(window);
+                               var page = new Page(preloadedWindow.Window);
                                page.Hide();
                                pages.Add(page);
 
-                               var canvas = new Canvas(window);
+                               var canvas = new Canvas(preloadedWindow.Window);
                                canvas.Hide();
                                canvases.Add(canvas);
 
-                               var button = new Native.Watch.WatchButton(window);
+                               var button = new Watch.WatchButton(preloadedWindow.Window);
                                button.Hide();
                                buttons.Add(button);
 
-                               var editfield = new EditfieldEntry(window);
+                               var editfield = new EditfieldEntry(preloadedWindow.Window);
                                editfield.Hide();
                                editfieldEntrys.Add(editfield);
                        }
+
+                       var listview = new Watch.WatchListView(preloadedWindow.Window, preloadedWindow.BaseCircleSurface);
+                       listview.Hide();
+                       watchListviews.Add(preloadedWindow.BaseCircleSurface, listview);
+
+                       var scroller = new Watch.WatchScroller(preloadedWindow.Window, preloadedWindow.BaseCircleSurface);
+                       scroller.Hide();
+                       watchScrollers.Add(preloadedWindow.BaseCircleSurface, scroller);
                }
 
-               public static EvasObject GetNativeControl(Type type)
+               public static EvasObject GetNativeControl(Type type, CircleSurface surface = null)
                {
                        if (type == typeof(Label))
                        {
@@ -114,6 +125,32 @@ namespace Xamarin.Forms.Platform.Tizen.Native
                                }
                                return new Page(Forms.NativeParent);
                        }
+                       else if (type == typeof(Watch.WatchListView))
+                       {
+                               if (watchListviews.ContainsKey(surface))
+                               {
+                                       var listview = watchListviews[surface];
+                                       if (listview != null)
+                                       {
+                                               watchListviews.Remove(surface);
+                                               return listview;
+                                       }
+                               }
+                               return new Watch.WatchListView(Forms.NativeParent, surface);
+                       }
+                       else if (type == typeof(Watch.WatchScroller))
+                       {
+                               if (watchScrollers.ContainsKey(surface))
+                               {
+                                       var scroller = watchScrollers[surface];
+                                       if (scroller != null)
+                                       {
+                                               watchScrollers.Remove(surface);
+                                               return scroller;
+                                       }
+                               }
+                               return new Watch.WatchScroller(Forms.NativeParent, surface);
+                       }
                        return Activator.CreateInstance(type, new[] { Forms.NativeParent }) as EvasObject;
                }
 
@@ -148,6 +185,18 @@ namespace Xamarin.Forms.Platform.Tizen.Native
                                native.Unrealize();
                        }
                        pages.Clear();
+
+                       foreach (var item in watchListviews)
+                       {
+                               item.Value.Unrealize();
+                       }
+                       watchListviews.Clear();
+
+                       foreach (var item in watchScrollers)
+                       {
+                               item.Value.Unrealize();
+                       }
+                       watchScrollers.Clear();
                }
        }
 }
\ No newline at end of file
index 3f69976..3fda591 100644 (file)
@@ -84,7 +84,7 @@ namespace Xamarin.Forms.Platform.Tizen
                {
                        if (Device.Idiom == TargetIdiom.Watch)
                        {
-                               return new Native.Watch.WatchListView(Forms.NativeParent, Forms.CircleSurface);
+                               return Native.NativeFactory.GetNativeControl(typeof(Native.Watch.WatchListView), Forms.CircleSurface) as Native.Watch.WatchListView;
                        }
                        else
                        {
index 815dc82..bb51991 100644 (file)
@@ -63,10 +63,9 @@ namespace Xamarin.Forms.Platform.Tizen
 
                protected virtual NScroller CreateNativeControl()
                {
-
                        if (Device.Idiom == TargetIdiom.Watch)
                        {
-                               return new Native.Watch.WatchScroller(Forms.NativeParent, Forms.CircleSurface);
+                               return Native.NativeFactory.GetNativeControl(typeof(Native.Watch.WatchScroller), Forms.CircleSurface) as Native.Watch.WatchScroller;
                        }
                        else
                        {