Enhance the factory of native and unrealize the unused native object (#217)
author유리나/Common Platform Lab(SR)/Staff Engineer/삼성전자 <rina6350.you@samsung.com>
Wed, 6 May 2020 07:17:41 +0000 (16:17 +0900)
committer윤정현/Common Platform Lab(SR)/Staff Engineer/삼성전자 <jh0506.yun@samsung.com>
Wed, 6 May 2020 07:17:41 +0000 (16:17 +0900)
src/XSF/Tizen.Wearable.CircularUI.Forms.Renderer/NativeFactory.cs
src/XSF/Xamarin.Forms.Platform.Tizen/FormsApplication.cs
src/XSF/Xamarin.Forms.Platform.Tizen/Native/NativeFactory.cs

index c61d786fc6f7d338a7a7571d4d649d673d1d05a3..301e0b7d8937585725c0dc10295eed17570d0b44 100644 (file)
@@ -38,7 +38,7 @@ namespace Tizen.Wearable.CircularUI.Forms.Renderer
                                if (circlePages.Count >= 1)
                                {
                                        NativeCirclePage native = circlePages[circlePages.Count - 1];
-                                       circlePages.RemoveAt(circlePages.Count - 1);
+                                       circlePages.Remove(native);
                                        return native;
                                }
                                return new NativeCirclePage(XForms.NativeParent);
@@ -50,8 +50,7 @@ namespace Tizen.Wearable.CircularUI.Forms.Renderer
                                        var listview = circleListviews[surface];
                                        if (listview != null)
                                        {
-                                               Console.WriteLine("Pre Test");
-                                               //circleListviews.Remove(surface);
+                                               circleListviews.Remove(surface);
                                                return listview;
                                        }
                                }
@@ -64,7 +63,7 @@ namespace Tizen.Wearable.CircularUI.Forms.Renderer
                                        var scroller = circleScrollers[surface];
                                        if (scroller != null)
                                        {
-                                               //circleScrollers.Remove(surface);
+                                               circleScrollers.Remove(surface);
                                                return scroller;
                                        }
                                }
@@ -72,5 +71,26 @@ namespace Tizen.Wearable.CircularUI.Forms.Renderer
                        }
                        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)
+                       {
+                               item.Value.Unrealize();
+                       }
+                       circleScrollers.Clear();
+               }
        }
 }
\ No newline at end of file
index c2a06fb1e7cbfea259e56690dcdda086304a639c..cbe2f0b89b99b7906de36257adf662fd16bd5ad3 100644 (file)
@@ -11,6 +11,7 @@ using DeviceOrientation = Xamarin.Forms.Internals.DeviceOrientation;
 using Xamarin.Forms.Platform.Tizen.Native;
 using ElmSharp.Wearable;
 using Specific = Xamarin.Forms.PlatformConfiguration.TizenSpecific.Application;
+using CircularUI = Tizen.Wearable.CircularUI.Forms;
 
 namespace Xamarin.Forms.Platform.Tizen
 {
@@ -198,6 +199,7 @@ namespace Xamarin.Forms.Platform.Tizen
                        _platform.SetPage(page);
 
                        Device.BeginInvokeOnMainThread(() => Native.NativeFactory.DeleteUnusedNative());
+                       Device.BeginInvokeOnMainThread(() => CircularUI.Renderer.NativeFactory.DeleteUnusedNative());
                }
 
                void InitializeWindow()
index 4dc1436d9de91240a856b20db339888614bf001f..ad4bd4492e8247e2fd4e5589b130eaf33d80c4da 100644 (file)
@@ -59,7 +59,7 @@ namespace Xamarin.Forms.Platform.Tizen.Native
                                if (labels.Count >= 1)
                                {
                                        Label native = labels[labels.Count - 1];
-                                       labels.RemoveAt(labels.Count - 1);
+                                       labels.Remove(native);
                                        return native;
                                }
                                return new Label(Forms.NativeParent);
@@ -69,7 +69,7 @@ namespace Xamarin.Forms.Platform.Tizen.Native
                                if (images.Count >= 1)
                                {
                                        Image native = images[images.Count - 1];
-                                       images.RemoveAt(images.Count - 1);
+                                       images.Remove(native);
                                        return native;
                                }
                                return new Image(Forms.NativeParent);
@@ -79,7 +79,7 @@ namespace Xamarin.Forms.Platform.Tizen.Native
                                if (buttons.Count >= 1)
                                {
                                        Watch.WatchButton native = buttons[buttons.Count - 1];
-                                       buttons.RemoveAt(buttons.Count - 1);
+                                       buttons.Remove(native);
                                        return native;
                                }
                                return new Watch.WatchButton(Forms.NativeParent);
@@ -89,7 +89,7 @@ namespace Xamarin.Forms.Platform.Tizen.Native
                                if (editfieldEntrys.Count >= 1)
                                {
                                        EditfieldEntry native = editfieldEntrys[editfieldEntrys.Count - 1];
-                                       editfieldEntrys.RemoveAt(editfieldEntrys.Count - 1);
+                                       editfieldEntrys.Remove(native);
                                        return native;
                                }
                                return new EditfieldEntry(Forms.NativeParent);
@@ -99,7 +99,7 @@ namespace Xamarin.Forms.Platform.Tizen.Native
                                if (canvases.Count >= 1)
                                {
                                        Canvas native = canvases[canvases.Count - 1];
-                                       canvases.RemoveAt(canvases.Count - 1);
+                                       canvases.Remove(native);
                                        return native;
                                }
                                return new Canvas(Forms.NativeParent);
@@ -109,7 +109,7 @@ namespace Xamarin.Forms.Platform.Tizen.Native
                                if (pages.Count >= 1)
                                {
                                        Page native = pages[pages.Count - 1];
-                                       pages.RemoveAt(pages.Count - 1);
+                                       pages.Remove(native);
                                        return native;
                                }
                                return new Page(Forms.NativeParent);
@@ -119,36 +119,35 @@ namespace Xamarin.Forms.Platform.Tizen.Native
 
                public static void DeleteUnusedNative()
                {
-                       for (int i=0; i< labels.Count; i++)
+                       foreach (var native in labels)
                        {
-                               Label native = labels[labels.Count - 1];
-                               labels.RemoveAt(labels.Count - 1);
                                native.Unrealize();
                        }
-                       for (int i = 0; i < images.Count; i++)
+                       labels.Clear();
+
+                       foreach (var native in images)
                        {
-                               Image native = images[images.Count - 1];
-                               images.RemoveAt(images.Count - 1);
                                native.Unrealize();
                        }
-                       for (int i = 0; i < buttons.Count; i++)
+                       images.Clear();
+
+                       foreach (var native in buttons)
                        {
-                               Button native = buttons[buttons.Count - 1];
-                               buttons.RemoveAt(buttons.Count - 1);
                                native.Unrealize();
                        }
-                       for (int i = 0; i < canvases.Count; i++)
+                       buttons.Clear();
+
+                       foreach (var native in canvases)
                        {
-                               Canvas native = canvases[canvases.Count - 1];
-                               canvases.RemoveAt(canvases.Count - 1);
                                native.Unrealize();
                        }
-                       for (int i = 0; i < pages.Count; i++)
+                       canvases.Clear();
+
+                       foreach (var native in pages)
                        {
-                               Page native = pages[pages.Count - 1];
-                               pages.RemoveAt(pages.Count - 1);
                                native.Unrealize();
                        }
+                       pages.Clear();
                }
        }
 }
\ No newline at end of file