[NUI] Fix PropertyNotification.GetTarget() error (#1559)
authordongsug-song <35130733+dongsug-song@users.noreply.github.com>
Wed, 22 Apr 2020 04:14:04 +0000 (13:14 +0900)
committerGitHub <noreply@github.com>
Wed, 22 Apr 2020 04:14:04 +0000 (13:14 +0900)
src/Tizen.NUI/src/public/PropertyNotification.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/PropertyNotificationTest.cs [new file with mode: 0755]

index e494d0e..6fa83fe 100755 (executable)
@@ -186,9 +186,9 @@ namespace Tizen.NUI
         /// <since_tizen> 4 </since_tizen>
         public Animatable GetTarget()
         {
-            Animatable ret = new Animatable(Interop.PropertyNotification.PropertyNotification_GetTarget(swigCPtr), true);
+            BaseHandle ret = Registry.GetManagedBaseHandleFromNativePtr(Interop.PropertyNotification.PropertyNotification_GetTarget(swigCPtr));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            return ret;
+            return ret as Animatable;
         }
 
         /// <summary>
diff --git a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/PropertyNotificationTest.cs b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/PropertyNotificationTest.cs
new file mode 100755 (executable)
index 0000000..7789b91
--- /dev/null
@@ -0,0 +1,66 @@
+
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Components;
+
+namespace Tizen.NUI.Samples
+{
+    public class PropertyNotificationTest : IExample
+    {
+        Window win;
+        int cnt;
+        public void Activate()
+        {
+            win = NUIApplication.GetDefaultWindow();
+            win.BackgroundColor = Color.White;
+
+            View view = new View()
+            {
+                Size = new Size(100, 100),
+                BackgroundColor = Color.Red,
+                Name = "test view",
+            };
+
+            PropertyNotification propertyNotification = view.AddPropertyNotification("size", PropertyCondition.Step(1.0f));
+
+            propertyNotification.Notified += (object source, PropertyNotification.NotifyEventArgs args) =>
+            {
+                View target = args.PropertyNotification.GetTarget() as View;
+                if (target != null)
+                {
+                    Tizen.Log.Error("NUI", $"Size changed! ({target.SizeWidth},{target.SizeHeight})");
+                    global::System.Console.WriteLine($"Size changed! ({target.SizeWidth},{target.SizeHeight})");
+                }
+                Tizen.Log.Error("NUI", "Size changed");
+            };
+
+            Button button = new Button()
+            {
+                Size = new Size(100, 100),
+                Position = new Position(200, 200),
+                Text = "Click me",
+                Name = "test button",
+            };
+
+            button.ClickEvent += (object source, Button.ClickEventArgs args) =>
+            {
+                if (++cnt % 2 == 0)
+                {
+                    view.Size += new Size(5, 5);
+                }
+                else
+                {
+                    view.Position += new Position(10, 10);
+                }
+            };
+
+            win.GetDefaultLayer().Add(view);
+            win.GetDefaultLayer().Add(button);
+        }
+
+        public void Deactivate()
+        {
+            win.GetDefaultLayer().FindChildByName("test view")?.Unparent();
+            win.GetDefaultLayer().FindChildByName("test button")?.Unparent();
+        }
+    }
+}