[NUI] Change for Size2D property to own internalSize2D which is cashed to prevent...
authordongsug.song <dongsug.song@samsung.com>
Mon, 18 Oct 2021 08:01:19 +0000 (17:01 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 9 Nov 2021 05:57:53 +0000 (14:57 +0900)
src/Tizen.NUI/Tizen.NUI.csproj
src/Tizen.NUI/Tizen.NUI.sln
src/Tizen.NUI/src/public/BaseComponents/View.cs
src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs
src/Tizen.NUI/src/public/BaseComponents/ViewEvent.cs
src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs
src/Tizen.NUI/src/public/Common/PropertyValue.cs
src/Tizen.NUI/src/public/Common/Size2D.cs

index 16db3ce..c99c027 100755 (executable)
     </None>
   </ItemGroup>
 
+
+  <!--Target Name="PostBuild" AfterTargets="PostBuildEvent">
+    <Exec Command="sdb root on&#xA;&#xD;&#xA;sdb shell &quot;mount -o remount,rw /&quot;&#xA;&#xD;&#xA;sdb shell &quot;rm /usr/share/dotnet.tizen/framework/*.ni.dll&quot;&#xA;&#xD;&#xA;sdb push $(TargetDir)Tizen.NUI.dll /usr/share/dotnet.tizen/framework/&#xA;&#xD;&#xA;sdb shell &quot;chsmack -a '_' /usr/share/dotnet.tizen/framework/Tizen.NUI.dll&quot;&#xA;&#xD;&#xA;sdb shell sync&#xA;" />
+  </Target-->
+
+
+
 </Project>
index 382d9c5..e094980 100755 (executable)
@@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.Applications.Componen
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.System.Information", "..\Tizen.System.Information\Tizen.System.Information.csproj", "{AD4B56C0-01B2-4ED0-9DBD-6CF233D16FF4}"
 EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.Applications.ThemeManager", "..\Tizen.Applications.ThemeManager\Tizen.Applications.ThemeManager.csproj", "{F57F6911-C581-49CA-80A5-9B5DDDAE3D40}"
+EndProject
 Global
        GlobalSection(SolutionConfigurationPlatforms) = preSolution
                Debug|Any CPU = Debug|Any CPU
@@ -51,6 +53,10 @@ Global
                {AD4B56C0-01B2-4ED0-9DBD-6CF233D16FF4}.Debug|Any CPU.Build.0 = Debug|Any CPU
                {AD4B56C0-01B2-4ED0-9DBD-6CF233D16FF4}.Release|Any CPU.ActiveCfg = Release|Any CPU
                {AD4B56C0-01B2-4ED0-9DBD-6CF233D16FF4}.Release|Any CPU.Build.0 = Release|Any CPU
+               {F57F6911-C581-49CA-80A5-9B5DDDAE3D40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+               {F57F6911-C581-49CA-80A5-9B5DDDAE3D40}.Debug|Any CPU.Build.0 = Debug|Any CPU
+               {F57F6911-C581-49CA-80A5-9B5DDDAE3D40}.Release|Any CPU.ActiveCfg = Release|Any CPU
+               {F57F6911-C581-49CA-80A5-9B5DDDAE3D40}.Release|Any CPU.Build.0 = Release|Any CPU
        EndGlobalSection
        GlobalSection(SolutionProperties) = preSolution
                HideSolutionNode = FALSE
index 1829836..78ab3da 100755 (executable)
@@ -51,6 +51,9 @@ namespace Tizen.NUI.BaseComponents
         // List of constraints
         private Constraint widthConstraint = null;
         private Constraint heightConstraint = null;
+
+        private Size2D internalSize2D = null;
+
         static View()
         {
             RegisterPropertyGroup(PositionProperty, positionPropertyGroup);
@@ -1014,17 +1017,15 @@ namespace Tizen.NUI.BaseComponents
         {
             get
             {
-                Size2D temp = (Size2D)GetValue(Size2DProperty);
-                int width = temp.Width;
-                int height = temp.Height;
+                var temp = (Size2D)GetValue(Size2DProperty);
 
                 if (this.Layout == null)
                 {
-                    if (width < 0) { width = 0; }
-                    if (height < 0) { height = 0; }
+                    if (temp.Width < 0) { temp.Width = 0; }
+                    if (temp.Height < 0) { temp.Height = 0; }
                 }
 
-                return new Size2D(OnSize2DChanged, width, height);
+                return temp;
             }
             set
             {
index feb9a3d..44af62c 100755 (executable)
@@ -607,26 +607,43 @@ namespace Tizen.NUI.BaseComponents
         /// Size2DProperty
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public static readonly BindableProperty Size2DProperty = BindableProperty.Create(nameof(Size2D), typeof(Size2D), typeof(View), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
-        {
-            var view = (View)bindable;
-            if (newValue != null)
+        public static readonly BindableProperty Size2DProperty = BindableProperty.Create(nameof(Size2D), typeof(Size2D), typeof(View), null,
+            propertyChanged: ((bindable, oldValue, newValue) =>
             {
-                Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)view.SwigCPtr, View.Property.SIZE, new Tizen.NUI.PropertyValue(new Size((Size2D)newValue)));
-                view.widthPolicy = ((Size2D)newValue).Width;
-                view.heightPolicy = ((Size2D)newValue).Height;
+                View view = (View)bindable;
+                if (newValue != null)
+                {
+                    view.SetSize(((Size2D)newValue).Width, ((Size2D)newValue).Height, 0);
 
-                view.layout?.RequestLayout();
-            }
-        }),
-        defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
-        {
-            var view = (View)bindable;
-            Size temp = new Size(0.0f, 0.0f, 0.0f);
-            Tizen.NUI.Object.GetProperty((System.Runtime.InteropServices.HandleRef)view.SwigCPtr, View.Property.SIZE).Get(temp);
-            Size2D size = new Size2D((int)temp.Width, (int)temp.Height);
-            return size;
-        }));
+                    view.widthPolicy = ((Size2D)newValue).Width;
+                    view.heightPolicy = ((Size2D)newValue).Height;
+
+                    view.layout?.RequestLayout();
+                }
+            }),
+            defaultValueCreator: ((bindable) =>
+            {
+                View view = (View)bindable;
+                var tmp = new Size(0, 0, 0);
+                Object.GetProperty(view.SwigCPtr, Property.SIZE).Get(tmp);
+
+                int tmpWidth = (int)tmp?.Width;
+                int tmpHeight = (int)tmp?.Height;
+                tmp?.Dispose();
+                tmp = null;
+
+                if (view.internalSize2D == null)
+                {
+                    view.internalSize2D = new Size2D(view.OnSize2DChanged, tmpWidth, tmpHeight);
+                }
+                else
+                {
+                    if (view.internalSize2D.Width != tmpWidth) { view.internalSize2D.Width = tmpWidth; }
+                    if (view.internalSize2D.Height != tmpHeight) { view.internalSize2D.Height = tmpHeight; }
+                }
+                return view.internalSize2D;
+            })
+        );
 
         /// <summary>
         /// OpacityProperty
@@ -1180,9 +1197,9 @@ namespace Tizen.NUI.BaseComponents
             var view = (View)bindable;
             if (newValue != null)
             {
-                if((ResizePolicyType)newValue == ResizePolicyType.KeepSizeFollowingParent)
+                if ((ResizePolicyType)newValue == ResizePolicyType.KeepSizeFollowingParent)
                 {
-                    if(view.widthConstraint == null)
+                    if (view.widthConstraint == null)
                     {
                         view.widthConstraint = new EqualConstraintWithParentFloat((System.Runtime.InteropServices.HandleRef)view.SwigCPtr, View.Property.SizeWidth, View.Property.SizeWidth);
                         view.widthConstraint.Apply();
@@ -1240,9 +1257,9 @@ namespace Tizen.NUI.BaseComponents
             var view = (View)bindable;
             if (newValue != null)
             {
-                if((ResizePolicyType)newValue == ResizePolicyType.KeepSizeFollowingParent)
+                if ((ResizePolicyType)newValue == ResizePolicyType.KeepSizeFollowingParent)
                 {
-                    if(view.heightConstraint == null)
+                    if (view.heightConstraint == null)
                     {
                         view.heightConstraint = new EqualConstraintWithParentFloat((System.Runtime.InteropServices.HandleRef)view.SwigCPtr, View.Property.SizeHeight, View.Property.SizeHeight);
                         view.heightConstraint.Apply();
index 685f31e..a9f2213 100755 (executable)
@@ -710,19 +710,18 @@ namespace Tizen.NUI.BaseComponents
 
         private void OnSize2DChanged(int? width, int? height)
         {
-            PropertyValue temp;
+            PropertyValue temp = null;
             if (width != null)
             {
-                temp = new Tizen.NUI.PropertyValue((float)width);
-                Tizen.NUI.Object.SetProperty(this.SwigCPtr, View.Property.SizeWidth, temp);
-                temp.Dispose();
+                temp = new PropertyValue((float)width);
+                Object.SetProperty(SwigCPtr, Property.SizeWidth, temp);
             }
             if (height != null)
             {
-                temp = new Tizen.NUI.PropertyValue((float)height);
-                Tizen.NUI.Object.SetProperty(this.SwigCPtr, View.Property.SizeHeight, temp);
-                temp.Dispose();
+                temp = new PropertyValue((float)height);
+                Object.SetProperty(SwigCPtr, Property.SizeHeight, temp);
             }
+            temp?.Dispose();
         }
 
         private void OnMinimumSizeChanged(int? width, int? height)
index 0c6c021..11de701 100755 (executable)
@@ -1155,6 +1155,8 @@ namespace Tizen.NUI.BaseComponents
 
 
             //_mergedStyle = null;
+            
+            internalSize2D?.Dispose();
 
             if (type == DisposeTypes.Explicit)
             {
index 78499e3..1de77d9 100755 (executable)
@@ -15,6 +15,7 @@
  *
  */
 
+using System;
 using System.ComponentModel;
 
 namespace Tizen.NUI
@@ -243,6 +244,43 @@ namespace Tizen.NUI
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
+
+        /// <summary>
+        /// Hidden API (Inhouse API).
+        /// Dispose. 
+        /// </summary>
+        /// <remarks>
+        /// Following the guide of https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-dispose.
+        /// This will replace "protected virtual void Dispose(DisposeTypes type)" which is exactly same in functionality.
+        /// </remarks>
+        /// <param name="disposing">true in order to free managed objects</param>
+        // Protected implementation of Dispose pattern.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected override void Dispose(bool disposing)
+        {
+            if (disposed)
+            {
+                return;
+            }
+
+            //perform dipose here without being added to DisposeQueue.
+            if (SwigCMemOwn && SwigCPtr.Handle != IntPtr.Zero)
+            {
+                if (disposing)
+                {
+                    base.Dispose(DisposeTypes.Explicit);
+                }
+                else
+                {
+                    base.Dispose(DisposeTypes.Implicit);
+                }
+            }
+
+            base.Dispose(disposing);
+        }
+
+
+
         /// <summary>
         /// An extension to the property value class that allows us to create a
         /// Property value from a C# object, for example, integer, float, or string.<br />
index 782e112..d50854f 100755 (executable)
@@ -69,6 +69,42 @@ namespace Tizen.NUI
         internal delegate void Size2DChangedCallback(int? width, int? height);
 
         /// <summary>
+        /// Hidden API (Inhouse API).
+        /// Dispose. 
+        /// </summary>
+        /// <remarks>
+        /// Following the guide of https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-dispose.
+        /// This will replace "protected virtual void Dispose(DisposeTypes type)" which is exactly same in functionality.
+        /// </remarks>
+        /// <param name="disposing">true in order to free managed objects</param>
+        // Protected implementation of Dispose pattern.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected override void Dispose(bool disposing)
+        {
+            if (disposed)
+            {
+                return;
+            }
+
+            callback = null;
+
+            //perform dipose here without being added to DisposeQueue.
+            if (SwigCMemOwn && SwigCPtr.Handle != IntPtr.Zero)
+            {
+                if (disposing)
+                {
+                    base.Dispose(DisposeTypes.Explicit);
+                }
+                else
+                {
+                    base.Dispose(DisposeTypes.Implicit);
+                }
+            }
+
+            base.Dispose(disposing);
+        }
+
+        /// <summary>
         /// The property for the width component of a size.
         /// </summary>
         /// <remarks>