[NUI] CanvasView: Manage added drawables as a list (#3060)
authorJunsuChoi <jsuya.choi@samsung.com>
Tue, 25 May 2021 07:24:01 +0000 (16:24 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Wed, 26 May 2021 01:00:09 +0000 (10:00 +0900)
Canvasview manages drawables as a list so that added drawables
used in canvasview are not released by gc.

src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/CanvasView.cs

index db387c6..53ae87c 100755 (executable)
@@ -16,6 +16,7 @@
 */
 using System;
 using System.ComponentModel;
+using System.Collections.Generic;
 using System.Diagnostics.CodeAnalysis;
 
 namespace Tizen.NUI.BaseComponents.VectorGraphics
@@ -26,6 +27,8 @@ namespace Tizen.NUI.BaseComponents.VectorGraphics
     /// <since_tizen> 9 </since_tizen>
     public class CanvasView : View
     {
+        private List<Drawable> drawables; //The list of added drawables
+
         static CanvasView() { }
 
         /// <summary>
@@ -42,6 +45,7 @@ namespace Tizen.NUI.BaseComponents.VectorGraphics
 
         internal CanvasView(global::System.IntPtr cPtr, bool shown = true) : base(cPtr, shown)
         {
+            drawables = new List<Drawable>();
             if (!shown)
             {
                 SetVisible(false);
@@ -59,6 +63,12 @@ namespace Tizen.NUI.BaseComponents.VectorGraphics
             {
                 return;
             }
+
+            if (type == DisposeTypes.Explicit)
+            {
+                drawables.Clear();
+            }
+
             base.Dispose(type);
         }
 
@@ -75,11 +85,20 @@ namespace Tizen.NUI.BaseComponents.VectorGraphics
         /// This method is similar to registration. The added shape is drawn on the inner canvas.
         /// </summary>
         /// <param name="drawable">Drawable object</param>
+        /// <exception cref="ArgumentNullException"> Thrown when drawable is null. </exception>
         /// <since_tizen> 9 </since_tizen>
         public void AddDrawable(Drawable drawable)
         {
+            if (drawable == null)
+            {
+                throw new ArgumentNullException(nameof(drawable));
+            }
             Interop.CanvasView.AddDrawable(View.getCPtr(this), BaseHandle.getCPtr(drawable));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            if (!drawables.Contains(drawable))
+            {
+                drawables.Add(drawable);
+            }
         }
     }
 }