Make sure scrollable shadow is shown only when scrolled vertically
authorhuayong.xu <huayong.xu@samsung.com>
Mon, 2 Nov 2020 07:58:02 +0000 (15:58 +0800)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Wed, 4 Nov 2020 08:17:17 +0000 (17:17 +0900)
When the scrollable is scrolled horizontally, a background image
is shown accidentally.
This patch adds a check that scrollable shadow is shown only when
scrolled vertically.

src/Tizen.NUI.Components/Controls/ScrollableBase.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/ScrollableBaseSample.cs [new file with mode: 0755]

index 0fa7250..509f692 100755 (executable)
@@ -1019,6 +1019,9 @@ namespace Tizen.NUI.Components
 
         private void AttachShadowView()
         {
+            if (ScrollingDirection != Direction.Vertical)
+                return;
+
             // stop animation if necessary.
             StopVerticalShadowAnimation();
 
@@ -1037,6 +1040,9 @@ namespace Tizen.NUI.Components
 
         private void DragVerticalShadow(float displacement)
         {
+            if (ScrollingDirection != Direction.Vertical)
+                return;
+
             if ((int)displacement > 0) // downwards
             {
                 // check if reaching at the top.
@@ -1092,6 +1098,9 @@ namespace Tizen.NUI.Components
 
         private void PlayVerticalShadowAnimation()
         {
+            if (ScrollingDirection != Direction.Vertical)
+                return;
+
             // stop animation if necessary.
             StopVerticalShadowAnimation();
 
diff --git a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/ScrollableBaseSample.cs b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/ScrollableBaseSample.cs
new file mode 100755 (executable)
index 0000000..08fa5e4
--- /dev/null
@@ -0,0 +1,94 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Tizen.NUI.BaseComponents;
+
+namespace Tizen.NUI.Samples
+{
+    public class ScrollableBaseOutOfBoundSample : IExample
+    {
+        private View root;
+        private Components.ScrollableBase mScrollableBase = null;
+        private TextLabel[] items;
+
+        public void Activate()
+        {
+            Window window = NUIApplication.GetDefaultWindow();
+            root = new View()
+            {
+                Size = new Size(1920, 1080),
+                BackgroundColor = new Color(0.7f, 0.9f, 0.8f, 1.0f),
+            };
+            root.Layout = new LinearLayout()
+            {
+                LinearOrientation = LinearLayout.Orientation.Vertical
+            };
+            window.Add(root);
+
+            CreateScrollableBase();
+        }
+
+        private void CreateScrollableBase()
+        {
+            mScrollableBase = new Components.ScrollableBase()
+            {
+                Position = new Position(300, 100),
+                Size = new Size(400, 300),
+                ScrollingDirection = Components.ScrollableBase.Direction.Vertical,
+            };
+            mScrollableBase.ScrollOutOfBound += OnScrollOutOfBound;
+
+            items = new TextLabel[5];
+            for (int i = 0; i < 5; i++)
+            {
+                items[i] = new TextLabel
+                {
+                    Position = new Position(0, i * 100),
+                    Size = new Size(800, 100),
+                    PointSize = 12.0f,
+                    TextColor = Color.Black,
+                };
+                if (i % 2 == 0)
+                {
+                    items[i].BackgroundColor = Color.White;
+                }
+                else
+                {
+                    items[i].BackgroundColor = Color.Cyan;
+                }
+                mScrollableBase.Add(items[i]);
+            }
+            root.Add(mScrollableBase);
+        }
+
+        private void OnScrollOutOfBound(object sender, Components.ScrollOutOfBoundEventArgs e)
+        {
+            if (e.ScrollableBound == Components.ScrollOutOfBoundEventArgs.Bound.Top)
+            {
+                items[0].Text = "Reached at the top.";
+            }
+            else
+            {
+                items[4].Text = "Reached at the bottom.";
+            }
+        }
+
+        public void Deactivate()
+        {
+            for (int i = 0; i < 5; i++)
+            {
+                if (items[i] != null)
+                {
+                    mScrollableBase.Remove(items[i]);
+                    items[i].Dispose();
+                }
+            }
+            if (mScrollableBase != null)
+            {
+                root.Remove(mScrollableBase);
+                mScrollableBase.Dispose();
+            }
+            root.Dispose();
+        }
+    }
+}