Revert "[NUI] Fix to make null assigning to ResourceUrl possible (#538)" (#562)
authordongsug-song <35130733+dongsug-song@users.noreply.github.com>
Wed, 21 Nov 2018 08:52:54 +0000 (17:52 +0900)
committerGitHub <noreply@github.com>
Wed, 21 Nov 2018 08:52:54 +0000 (17:52 +0900)
- need to keep the behavior with previous version of API
- comment added to make clear the null-setting
- add sample app to test (ImageViewResourceUrlSetNullTest.cs)

This reverts commit 66ae1948186c30b4131116ebc664e7b59b1f78b6.

src/Tizen.NUI/src/public/BaseComponents/ImageView.cs
test/NUITestSample/NUITestSample/examples/ImageViewResourceUrlSetNullTest.cs [new file with mode: 0755]

index 1a4829d..5f3a0b9 100755 (executable)
@@ -34,25 +34,22 @@ namespace Tizen.NUI.BaseComponents
         public static readonly BindableProperty ResourceUrlProperty = BindableProperty.Create(nameof(ImageView.ResourceUrl), typeof(string), typeof(ImageView), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
         {
             var imageView = (ImageView)bindable;
-            imageView._url = (string)newValue;
-
-            if (imageView._url != null)
+            if (newValue != null)
             {
-                if (imageView.IsCreateByXaml && imageView._url.Contains("*Resource*"))
+                string url = (string)newValue;
+                if (imageView.IsCreateByXaml && url.Contains("*Resource*"))
                 {
                     string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
-                    imageView._url = imageView._url.Replace("*Resource*", resource);
+                    url = url.Replace("*Resource*", resource);
                 }
+                imageView._url = url;
+                imageView.UpdateImage();
             }
-            imageView.UpdateImage();
         },
         defaultValueCreator:(bindable) =>
         {
             var imageView = (ImageView)bindable;
-            if(imageView._url != null)
-            {
-                Tizen.NUI.Object.GetProperty(imageView.swigCPtr, ImageView.Property.IMAGE).Get(out imageView._url);
-            }
+            Tizen.NUI.Object.GetProperty(imageView.swigCPtr, ImageView.Property.IMAGE).Get(out imageView._url);
             return imageView._url;
         });
         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
@@ -481,6 +478,8 @@ namespace Tizen.NUI.BaseComponents
 
         /// <summary>
         /// ImageView ResourceUrl, type string.
+        /// This is one of mandatory property. Even if not set or null set, it sets empty string ("") internally.
+        /// When it is set as null, it gives empty string ("") to be read.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
         public string ResourceUrl
@@ -491,7 +490,8 @@ namespace Tizen.NUI.BaseComponents
             }
             set
             {
-                SetValue(ResourceUrlProperty, value);
+                _url = (value == null? "" : value);
+                SetValue(ResourceUrlProperty, _url);
                 NotifyPropertyChanged();
             }
         }
@@ -732,10 +732,6 @@ namespace Tizen.NUI.BaseComponents
                     SetProperty(ImageView.Property.IMAGE, new PropertyValue(_url));
                 }
             }
-            else
-            {
-                SetProperty(ImageView.Property.IMAGE, new PropertyValue(""));
-            }
         }
 
         private Rectangle _border = null;
diff --git a/test/NUITestSample/NUITestSample/examples/ImageViewResourceUrlSetNullTest.cs b/test/NUITestSample/NUITestSample/examples/ImageViewResourceUrlSetNullTest.cs
new file mode 100755 (executable)
index 0000000..34f7006
--- /dev/null
@@ -0,0 +1,136 @@
+
+using System;
+using Tizen.NUI;
+using Tizen.NUI.UIComponents;
+using Tizen.NUI.BaseComponents;
+
+namespace ImageViewResourceUrlSetNullTest
+{
+    class Example : NUIApplication
+    {
+        protected override void OnCreate()
+        {
+            base.OnCreate();
+            Activate();        
+        }
+
+        Window win;
+        Timer timer1;
+        View view1;
+        TextLabel textlabel1;
+        ImageView imageview1;
+        string res;
+
+        public void Activate()
+        {
+            Console.WriteLine("\n ##### _MyTestResourceUrlNull test!\n");
+
+            win = Window.Instance;
+            win.BackgroundColor = Color.Green;
+            Vector2 dpi = win.Dpi;
+            Console.WriteLine($"dpi x={dpi.X} y={dpi.Y} \n");
+            win.TouchEvent += Win_TouchEvent;
+
+            res = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
+            Console.WriteLine($"res={res} \n");
+
+            view1 = new View();
+            view1.Size2D = new Size2D(1000, 1000);
+            view1.Position2D = new Position2D(460, 40);
+            view1.BackgroundColor = Color.Yellow;
+            win.GetDefaultLayer().Add(view1);
+
+            textlabel1 = new TextLabel();
+            textlabel1.Size2D = new Size2D(1000, 200);
+            textlabel1.Position2D = new Position2D(0, 0);
+            textlabel1.Text = "ImageView ResourceUrl property NULL/empty string assigning Test \n click this window!";
+            textlabel1.BackgroundColor = Color.Magenta;
+            textlabel1.HorizontalAlignment = HorizontalAlignment.Center;
+            textlabel1.VerticalAlignment = VerticalAlignment.Center;
+            textlabel1.PointSize = dpi.X / 4;
+            textlabel1.MultiLine = true;
+            textlabel1.TextColor = Color.White;
+            view1.Add(textlabel1);
+
+            timer1 = new Timer(300);
+            timer1.Tick += Timer1_Tick;
+        }
+
+        int teststate = 0;
+        private bool Timer1_Tick(object source, Timer.TickEventArgs e)
+        {
+            switch (teststate)
+            {
+                case 0:
+                    imageview1 = new ImageView();
+                    imageview1.Size2D = new Size2D(300, 300);
+                    imageview1.Position2D = new Position2D(350, 300);
+                    view1.Add(imageview1);
+                    textlabel1.Text = $"0. new ImageView but NOT set ResourceUrl! (Is ResourceUrl NULL? {(imageview1.ResourceUrl == null)}) " +
+                        $"ResourceUrl=({imageview1.ResourceUrl})";
+                    teststate = 1;
+                    break;
+                case 1:
+                    imageview1.ResourceUrl = res + "images/gallery-0.jpg";
+                    textlabel1.Text = $"1. set proper picture path into ResourceUrl! (should show the image!) " +
+                        $"ResourceUrl=( {imageview1.ResourceUrl} )";
+                    textlabel1.PointSize /= 2;
+                    teststate = 2;
+                    break;
+                case 2:
+                    imageview1.ResourceUrl = "";
+                    textlabel1.Text = $"2. set empty string into ResourceUrl! (picture should be disappeared!) " +
+                        $"ResourceUrl=( {imageview1.ResourceUrl} )";
+                    textlabel1.PointSize *= 2;
+                    teststate = 3;
+                    break;
+                case 3:
+                    imageview1.ResourceUrl = res + "images/gallery-1.jpg";
+                    textlabel1.Text = $"3. set proper path into ResourceUrl! (different picture should be shown!) " +
+                        $"ResourceUrl=( {imageview1.ResourceUrl} )";
+                    textlabel1.PointSize /= 2;
+                    teststate = 4;
+                    break;
+                case 4:
+                    imageview1.ResourceUrl = null;
+                    textlabel1.Text = $"4. set NULL into ResourceUrl! (picture disappeared and ResourceUrl should NOT be NULL!) " +
+                        $"(Is ResourceUrl NULL? { (imageview1.ResourceUrl == null)}) " + $"ResourceUrl=( {imageview1.ResourceUrl} )";
+                    teststate = 5;
+                    textlabel1.PointSize *= 2;
+                    break;
+                case 5:
+                    view1.Remove(imageview1);
+                    imageview1.Dispose();
+                    imageview1 = null;
+                    textlabel1.Text = $"5. dispose and make NULL for ImageView!";
+                    teststate = 0;
+                    break;
+
+            }
+            return false;
+        }
+
+        private void Win_TouchEvent(object sender, Window.TouchEventArgs e)
+        {
+            if (e.Touch.GetState(0) == PointStateType.Down)
+            {
+                timer1.Start();
+            }
+        }
+
+        public void Deactivate()
+        {
+            win.Remove(view1);
+            view1.Dispose();
+            view1 = null;
+        }
+
+
+        [STAThread]
+        static void _Main(string[] args)
+        {
+            Example example = new Example();
+            example.Run(args);
+        }
+    }
+}