[ElmSharp] Add scroll animation start/stop event for Scroller 51/164051/5
authordarkleem <cdark.lim@samsung.com>
Fri, 15 Dec 2017 04:39:18 +0000 (13:39 +0900)
committerdarkleem <cdark.lim@samsung.com>
Thu, 28 Dec 2017 06:58:52 +0000 (15:58 +0900)
  - fix background color issue and logic for scrollerTest3

Change-Id: I6fa87a3e45b656e409a9c8043d0e8847ac3976dd

src/ElmSharp/ElmSharp/Scroller.cs
test/ElmSharp.Test/TC/ScrollerTest3.cs

index 6cf1c94..857fac4 100755 (executable)
@@ -91,6 +91,8 @@ namespace ElmSharp
     public class Scroller : Layout
     {
         SmartEvent _scroll;
+        SmartEvent _scrollAnimationStart;
+        SmartEvent _scrollAnimationStop;
         SmartEvent _dragStart;
         SmartEvent _dragStop;
         SmartEvent _scrollpage;
@@ -129,6 +131,38 @@ namespace ElmSharp
         }
 
         /// <summary>
+        /// ScrollAnimationStarted will be triggered when the content animation has been started.
+        /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        public event EventHandler ScrollAnimationStarted
+        {
+            add
+            {
+                _scrollAnimationStart.On += value;
+            }
+            remove
+            {
+                _scrollAnimationStart.On -= value;
+            }
+        }
+
+        /// <summary>
+        /// ScrollAnimationStopped will be triggered when the content animation has been stopped.
+        /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        public event EventHandler ScrollAnimationStopped
+        {
+            add
+            {
+                _scrollAnimationStop.On += value;
+            }
+            remove
+            {
+                _scrollAnimationStop.On -= value;
+            }
+        }
+
+        /// <summary>
         /// DragStart will be triggered when dragging the contents around has started.
         /// </summary>
         /// <since_tizen> preview </since_tizen>
@@ -835,6 +869,8 @@ namespace ElmSharp
         {
             base.OnRealized();
             _scroll = new SmartEvent(this, this.RealHandle, "scroll");
+            _scrollAnimationStart = new SmartEvent(this, this.RealHandle, "scroll,anim,start");
+            _scrollAnimationStop = new SmartEvent(this, this.RealHandle, "scroll,anim,stop");
             _dragStart = new SmartEvent(this, this.RealHandle, "scroll,drag,start");
             _dragStop = new SmartEvent(this, this.RealHandle, "scroll,drag,stop");
             _scrollpage = new SmartEvent(this, this.RealHandle, "scroll,page,changed");
index 90d7015..1542508 100755 (executable)
@@ -23,6 +23,7 @@ namespace ElmSharp.Test
     {
         public override string TestName => "ScrollerTest3";
         public override string TestDescription => "To test ScrollTo operation of Scroller";
+        Scroller _scroller;
 
         public override void Run(Window window)
         {
@@ -30,6 +31,7 @@ namespace ElmSharp.Test
             conformant.Show();
             Box outterBox = new Box(window)
             {
+                BackgroundColor = Color.Gray,
                 AlignmentX = -1,
                 AlignmentY = -1,
                 WeightX = 1,
@@ -37,17 +39,16 @@ namespace ElmSharp.Test
                 IsHorizontal = false,
             };
             outterBox.Show();
-            Scroller scroller = new Scroller(window)
+            _scroller = new Scroller(window)
             {
                 AlignmentX = -1,
                 AlignmentY = -1,
                 WeightX = 1,
                 WeightY = 1,
-                ScrollBlock = ScrollBlock.Vertical,
                 HorizontalPageScrollLimit = 1,
             };
-            scroller.SetPageSize(1.0, 1.0);
-            scroller.Show();
+            _scroller.SetPageSize(1.0, 1.0);
+            _scroller.Show();
 
             Box box = new Box(window)
             {
@@ -57,9 +58,9 @@ namespace ElmSharp.Test
                 WeightY = 1
             };
             box.Show();
-            scroller.SetContent(box);
+            _scroller.SetContent(box);
 
-            for (int i = 0; i < 30; i++)
+            for (int i = 0; i < 150; i++)
             {
                 Label addlabel = new Label(window)
                 {
@@ -74,7 +75,7 @@ namespace ElmSharp.Test
             }
 
             conformant.SetContent(outterBox);
-            outterBox.PackEnd(scroller);
+            outterBox.PackEnd(_scroller);
 
             Button prev = new Button(window)
             {
@@ -88,25 +89,79 @@ namespace ElmSharp.Test
                 WeightX = 1,
                 Text = "next"
             };
+
+            int index = 0;
+
             prev.Clicked += (s, e) =>
             {
-                Rect region = new Rect(0, 0, scroller.Geometry.Width, scroller.Geometry.Width);
-                Console.WriteLine("{0} {1}\n", scroller.Geometry.Width, scroller.Geometry.Width);
-                scroller.ScrollTo(region, true);
+                Rect region = new Rect(0, _scroller.Geometry.Height * --index, _scroller.Geometry.Width * index, _scroller.Geometry.Height);
+                Console.WriteLine("index : {0} [{1}, {2}]\n", index, _scroller.Geometry.Width, _scroller.Geometry.Height);
+                _scroller.ScrollTo(region, false);
             };
+
             next.Clicked += (s, e) =>
             {
-                Rect region = new Rect(0, scroller.Geometry.Height, scroller.Geometry.Width, scroller.Geometry.Height);
-                Console.WriteLine("{0} {1}\n", scroller.Geometry.Width, scroller.Geometry.Width);
-                scroller.ScrollTo(region, true);
+                Rect region = new Rect(0, _scroller.Geometry.Height * ++index, _scroller.Geometry.Width, _scroller.Geometry.Height);
+                Console.WriteLine("index : {0} [{1}, {2}]\n", index, _scroller.Geometry.Width, _scroller.Geometry.Height);
+                _scroller.ScrollTo(region, false);
             };
             prev.Show();
             next.Show();
+
+            Button prev2 = new Button(window)
+            {
+                AlignmentX = -1,
+                WeightX = 1,
+                Text = "animation Prev"
+            };
+            Button next2 = new Button(window)
+            {
+                AlignmentX = -1,
+                WeightX = 1,
+                Text = "animation next"
+            };
+
+            prev2.Clicked += (s, e) =>
+            {
+                Rect region = new Rect(0, _scroller.Geometry.Height * --index, _scroller.Geometry.Width * index, _scroller.Geometry.Height);
+                Console.WriteLine("animation index : {0} [{1}, {2}]\n", index, _scroller.Geometry.Width, _scroller.Geometry.Height);
+                _scroller.ScrollTo(region, true);
+            };
+
+            next2.Clicked += (s, e) =>
+            {
+                Rect region = new Rect(0, _scroller.Geometry.Height * ++index, _scroller.Geometry.Width, _scroller.Geometry.Height);
+                Console.WriteLine("animation index : {0} [{1}, {2}]\n", index, _scroller.Geometry.Width, _scroller.Geometry.Height);
+                _scroller.ScrollTo(region, true);
+            };
+            prev2.Show();
+            next2.Show();
+
             outterBox.PackEnd(prev);
             outterBox.PackEnd(next);
+            outterBox.PackEnd(prev2);
+            outterBox.PackEnd(next2);
+
+            _scroller.DragStart += Scroller_DragStart;
+            _scroller.DragStop += Scroller_DragStop;
+            _scroller.ScrollAnimationStarted += Scroller_ScrollStart;
+            _scroller.ScrollAnimationStopped += Scroller_ScrollStop;
+            _scroller.Scrolled += Scroller_Scrolled;
+        }
 
-            scroller.DragStart += Scroller_DragStart;
-            scroller.DragStop += Scroller_DragStop;
+        private void Scroller_Scrolled(object sender, EventArgs e)
+        {
+            Console.WriteLine($"scrolled : {_scroller.CurrentRegion}");
+        }
+
+        private void Scroller_ScrollStop(object sender, EventArgs e)
+        {
+            Console.WriteLine("scroll animation stop");
+        }
+
+        private void Scroller_ScrollStart(object sender, EventArgs e)
+        {
+             Console.WriteLine("scroll animation start");
         }
 
         private void Scroller_DragStop(object sender, EventArgs e)