From f83ec6c0e0510525328a148591189695220eb67c Mon Sep 17 00:00:00 2001 From: neostom432 <31119276+neostom432@users.noreply.github.com> Date: Thu, 30 Jan 2020 14:16:30 +0900 Subject: [PATCH] [NUI] Add ScrollToIndex to ScrollableBase (#1350) * [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 --- .../Controls/ScrollableBase.cs | 28 +++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Tizen.NUI.Components/Controls/ScrollableBase.cs b/src/Tizen.NUI.Components/Controls/ScrollableBase.cs index 42b780b..52129f0 100755 --- a/src/Tizen.NUI.Components/Controls/ScrollableBase.cs +++ b/src/Tizen.NUI.Components/Controls/ScrollableBase.cs @@ -381,6 +381,32 @@ namespace Tizen.NUI.Components mScrollingChild = new View(); } + + /// + /// Scrolls to the item at the specified index. + /// + /// Index of item. + /// 6 + /// 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() -- 2.7.4