[NUI] Add ScrollToIndex to ScrollableBase (#1350)
authorneostom432 <31119276+neostom432@users.noreply.github.com>
Thu, 30 Jan 2020 05:16:30 +0000 (14:16 +0900)
committerGitHub <noreply@github.com>
Thu, 30 Jan 2020 05:16:30 +0000 (14:16 +0900)
* [NUI] Add ScrollToIndex to ScrollableBase

Scrolls to the item at the specified index.

* [NUI] Use position instead of Size for calculating scrolling position

Co-authored-by: krown <neostom432@nate.com>
src/Tizen.NUI.Components/Controls/ScrollableBase.cs

index 42b780b..52129f0 100755 (executable)
@@ -381,6 +381,32 @@ namespace Tizen.NUI.Components
             mScrollingChild = new View();
         }
 
+
+        /// <summary>
+        /// Scrolls to the item at the specified index.
+        /// </summary>
+        /// <param name="index">Index of item.</param>
+        /// <since_tizen> 6 </since_tizen>
+        /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void ScrollToIndex(int index)
+        {
+            if(mScrollingChild.ChildCount-1 < index || index < 0)
+            {
+                return;
+            }
+
+            if(SnapToPage)
+            {
+                CurrentPage = index;
+            }
+
+            maxScrollDistance = CalculateMaximumScrollDistance();
+
+            float targetPosition = Math.Min(ScrollingDirection == Direction.Vertical ? mScrollingChild.Children[index].Position.Y : mScrollingChild.Children[index].Position.X, maxScrollDistance);
+            AnimateChildTo(ScrollDuration, -targetPosition);
+        }
+
         private void OnScrollDragStart()
         {
             ScrollEventArgs eventArgs = new ScrollEventArgs();
@@ -591,7 +617,7 @@ namespace Tizen.NUI.Components
                                                    " parent length:" + scrollerLength +
                                                    " scrolling child length:" + scrollingChildLength);
 
-            return scrollingChildLength - scrollerLength;
+            return Math.Max(scrollingChildLength - scrollerLength,0);
         }
 
         private void PageSnap()