From: SangHyeon Jade Lee Date: Mon, 17 May 2021 11:18:01 +0000 (+0900) Subject: [NUI] refactoring ScrollTo. (#3042) (#3043) X-Git-Tag: accepted/tizen/unified/20231205.024657~1908 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3cc4ce32b52122950d34e9c855f01a4d66fff655;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] refactoring ScrollTo. (#3042) (#3043) 1. delay ScrollTo action till CollectionView is ready to scroll. 2. checking param index in ScrollTo(). 3. override(new) ScrollToIndex(int index) to ScrollTo(int index, bool anim, ItemScrollTo align). --- diff --git a/src/Tizen.NUI.Components/Controls/RecyclerView/CollectionView.cs b/src/Tizen.NUI.Components/Controls/RecyclerView/CollectionView.cs index 125ef00..e2d7ef6 100755 --- a/src/Tizen.NUI.Components/Controls/RecyclerView/CollectionView.cs +++ b/src/Tizen.NUI.Components/Controls/RecyclerView/CollectionView.cs @@ -120,6 +120,11 @@ namespace Tizen.NUI.Components private int prevFocusedDataIndex = 0; private List recycleGroupHeaderCache { get; } = new List(); private List recycleGroupFooterCache { get; } = new List(); + private bool delayedScrollTo; + private (float position, bool anim) delayedScrollToParam; + + private bool delayedIndexScrollTo; + private (int index, bool anim, ItemScrollTo scrollTo) delayedIndexScrollToParam; /// /// Base constructor. @@ -678,7 +683,28 @@ namespace Tizen.NUI.Components /// Destination. /// Scroll with or without animation /// 9 - public new void ScrollTo(float position, bool animate) => base.ScrollTo(position, animate); + public new void ScrollTo(float position, bool animate) + { + if (ItemsLayouter == null) throw new Exception("Item Layouter must exist."); + if ((InternalItemSource == null) || needInitalizeLayouter) + { + delayedScrollTo = true; + delayedScrollToParam = (position, animate); + return; + } + + base.ScrollTo(position, animate); + } + + /// + /// Scrolls to the item at the specified index. + /// + /// Index of item. + [EditorBrowsable(EditorBrowsableState.Never)] + public new void ScrollToIndex(int index) + { + ScrollTo(index, true, ItemScrollTo.Start); + } /// /// Scroll to specific item's aligned position with or without animation. @@ -690,6 +716,16 @@ namespace Tizen.NUI.Components public virtual void ScrollTo(int index, bool animate = false, ItemScrollTo align = ItemScrollTo.Nearest) { if (ItemsLayouter == null) throw new Exception("Item Layouter must exist."); + if ((InternalItemSource == null) || needInitalizeLayouter) + { + delayedIndexScrollTo = true; + delayedIndexScrollToParam = (index, animate, align); + return; + } + if (index < 0 || index >= InternalItemSource.Count) + { + throw new Exception("index is out of boundary. index should be a value between (0, " + InternalItemSource.Count.ToString() + ")."); + } float scrollPos, curPos, curSize, curItemSize; (float x, float y) = ItemsLayouter.GetItemPosition(index); @@ -1136,6 +1172,18 @@ namespace Tizen.NUI.Components } ItemsLayouter.RequestLayout(0.0f, true); + if (delayedScrollTo) + { + delayedScrollTo = false; + ScrollTo(delayedScrollToParam.position, delayedScrollToParam.anim); + } + + if (delayedIndexScrollTo) + { + delayedIndexScrollTo = false; + ScrollTo(delayedIndexScrollToParam.index, delayedIndexScrollToParam.anim, delayedIndexScrollToParam.scrollTo); + } + if (ScrollingDirection == Direction.Horizontal) { ContentContainer.SizeWidth = ItemsLayouter.CalculateLayoutOrientationSize();