From 77ac1a5c09f26626538823378bb28cf7dcbcae00 Mon Sep 17 00:00:00 2001 From: neostom432 <31119276+neostom432@users.noreply.github.com> Date: Mon, 13 Jan 2020 17:19:19 +0900 Subject: [PATCH] [NUI] Add ScrollEnabled property to ScrollableBase (#1298) * [NUI] Add ScrollEnabled property to ScrollableBase User can disable / enable scrolling using this property. * [NUI] Add CurrentPage property to ScrollableBase Can get current page of ScrollableBase when using SnapToPage mode. Co-authored-by: krown --- .../Controls/ScrollableBase.cs | 61 +++++++++++++++++----- 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/src/Tizen.NUI.Components/Controls/ScrollableBase.cs b/src/Tizen.NUI.Components/Controls/ScrollableBase.cs index 1018c33..1e29196 100755 --- a/src/Tizen.NUI.Components/Controls/ScrollableBase.cs +++ b/src/Tizen.NUI.Components/Controls/ScrollableBase.cs @@ -28,6 +28,7 @@ namespace Tizen.NUI.Components { static bool LayoutDebugScrollableBase = false; // Debug flag private Direction mScrollingDirection = Direction.Vertical; + private bool mScrollEnabled = true; private class ScrollableBaseCustomLayout : LayoutGroup { @@ -203,6 +204,36 @@ namespace Tizen.NUI.Components } /// + /// [Draft] Enable or disable scrolling. + /// + /// 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 bool ScrollEnabled + { + get + { + return mScrollEnabled; + } + set + { + if (value != mScrollEnabled) + { + mScrollEnabled = value; + if(mScrollEnabled) + { + mPanGestureDetector.Detected += OnPanGestureDetected; + mTapGestureDetector.Detected += OnTapGestureDetected; + } + else + { + mPanGestureDetector.Detected -= OnPanGestureDetected; + mTapGestureDetector.Detected -= OnTapGestureDetected; + } + } + } + } + + /// /// [Draft] Pages mode, enables moving to the next or return to current page depending on pan displacement. /// Default is false. /// @@ -211,6 +242,14 @@ namespace Tizen.NUI.Components public bool SnapToPage { set; get; } = false; /// + /// [Draft] Get current page. + /// Working propery with SnapToPage property. + /// + /// 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 int CurrentPage { get; private set; } = 0; + + /// /// [Draft] Pages mode, Number of pages. /// /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API @@ -271,8 +310,6 @@ namespace Tizen.NUI.Components // If false then can only flick pages when the current animation/scroll as ended. private bool flickWhenAnimating = false; - private int currentPage = 0; - /// /// [Draft] Constructor /// @@ -529,24 +566,24 @@ namespace Tizen.NUI.Components private void PageSnap() { Debug.WriteLineIf(LayoutDebugScrollableBase, "PageSnap with pan candidate totalDisplacement:" + totalDisplacementForPan + - " currentPage[" + currentPage + "]" ); + " currentPage[" + CurrentPage + "]" ); //Increment current page if total displacement enough to warrant a page change. if (Math.Abs(totalDisplacementForPan) > (PageWidth * ratioOfScreenWidthToCompleteScroll)) { if (totalDisplacementForPan < 0) { - currentPage = Math.Min(NumberOfPages-1, ++currentPage); + CurrentPage = Math.Min(NumberOfPages - 1, ++CurrentPage); } else { - currentPage = Math.Max(0, --currentPage); + CurrentPage = Math.Max(0, --CurrentPage); } } // Animate to new page or reposition to current page - int destinationX = -(currentPage * PageWidth); - Debug.WriteLineIf(LayoutDebugScrollableBase, "Snapping to page[" + currentPage + "] to:"+ destinationX + " from:" + mScrollingChild.PositionX); + int destinationX = -(CurrentPage * PageWidth); + Debug.WriteLineIf(LayoutDebugScrollableBase, "Snapping to page[" + CurrentPage + "] to:"+ destinationX + " from:" + mScrollingChild.PositionX); AnimateChildTo(ScrollDuration, destinationX); } @@ -558,15 +595,15 @@ namespace Tizen.NUI.Components { if(flickDisplacement < 0) { - currentPage = Math.Min(NumberOfPages - 1, currentPage + 1); - Debug.WriteLineIf(LayoutDebugScrollableBase, "Snap - to page:" + currentPage); + CurrentPage = Math.Min(NumberOfPages - 1, CurrentPage + 1); + Debug.WriteLineIf(LayoutDebugScrollableBase, "Snap - to page:" + CurrentPage); } else { - currentPage = Math.Max(0, currentPage - 1); - Debug.WriteLineIf(LayoutDebugScrollableBase, "Snap + to page:" + currentPage); + CurrentPage = Math.Max(0, CurrentPage - 1); + Debug.WriteLineIf(LayoutDebugScrollableBase, "Snap + to page:" + CurrentPage); } - float targetPosition = -(currentPage* PageWidth); // page size + float targetPosition = -(CurrentPage* PageWidth); // page size Debug.WriteLineIf(LayoutDebugScrollableBase, "Snapping to :" + targetPosition); AnimateChildTo(ScrollDuration,targetPosition); } -- 2.7.4