From: neostom432 <31119276+neostom432@users.noreply.github.com> Date: Mon, 9 Mar 2020 03:01:56 +0000 (+0900) Subject: [NUI] Change PageToSnap Behavior (#1453) X-Git-Tag: accepted/tizen/unified/20210219.040944~833 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7b91591a5dca55366b285745ab32d9160c9c5309;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] Change PageToSnap Behavior (#1453) Previously, page moves the width of ScrollableBase in SnapToPage mode. Now, Center of Page will be aligned with Center of ScrollableBase. And User can set min/max scroll distance by setting ScrollAvailableArea. --- diff --git a/src/Tizen.NUI.Components/Controls/ScrollableBase.cs b/src/Tizen.NUI.Components/Controls/ScrollableBase.cs index 7ce29ec..5ba03eb 100755 --- a/src/Tizen.NUI.Components/Controls/ScrollableBase.cs +++ b/src/Tizen.NUI.Components/Controls/ScrollableBase.cs @@ -258,7 +258,14 @@ namespace Tizen.NUI.Components /// /// 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 ScrollDuration { set; get; } = 125; + /// + /// [Draft] Scroll Available area. + /// + /// 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 Rectangle ScrollAvailableArea { set; get; } /// /// ScrollEventArgs is a class to record scroll event arguments which will sent to user. @@ -540,8 +547,22 @@ namespace Tizen.NUI.Components " maxScrollDistance:" + maxScrollDistance ); childTargetPosition = childCurrentPosition + displacement; // child current position + gesture displacement - childTargetPosition = Math.Min(0,childTargetPosition); - childTargetPosition = Math.Max(-maxScrollDistance,childTargetPosition); + + if(ScrollAvailableArea != null) + { + float minScrollPosition = ScrollingDirection == Direction.Horizontal? ScrollAvailableArea.X:ScrollAvailableArea.Y; + float maxScrollPosition = ScrollingDirection == Direction.Horizontal? + ScrollAvailableArea.X + ScrollAvailableArea.Width: + ScrollAvailableArea.Y + ScrollAvailableArea.Height; + + childTargetPosition = Math.Min( -minScrollPosition, childTargetPosition ); + childTargetPosition = Math.Max( -maxScrollPosition, childTargetPosition ); + } + else + { + childTargetPosition = Math.Min(0, childTargetPosition); + childTargetPosition = Math.Max(-maxScrollDistance, childTargetPosition); + } Debug.WriteLineIf( LayoutDebugScrollableBase, "ScrollBy currentAxisPosition:" + childCurrentPosition + "childTargetPosition:" + childTargetPosition); @@ -687,8 +708,8 @@ namespace Tizen.NUI.Components } // Animate to new page or reposition to current page - int destinationX = -(CurrentPage * mPageWidth); - Debug.WriteLineIf(LayoutDebugScrollableBase, "Snapping to page[" + CurrentPage + "] to:"+ destinationX + " from:" + mScrollingChild.PositionX); + float destinationX = -(mScrollingChild.Children[CurrentPage].Position.X + mScrollingChild.Children[CurrentPage].CurrentSize.Width/2 - CurrentSize.Width/2); // set to middle of current page + Debug.WriteLineIf(LayoutDebugScrollableBase, "Snapping to page[" + CurrentPage + "] to:" + destinationX + " from:" + mScrollingChild.PositionX); AnimateChildTo(ScrollDuration, destinationX); } @@ -708,9 +729,10 @@ namespace Tizen.NUI.Components CurrentPage = Math.Max(0, CurrentPage - 1); Debug.WriteLineIf(LayoutDebugScrollableBase, "Snap + to page:" + CurrentPage); } - float targetPosition = -(CurrentPage* mPageWidth); // page size - Debug.WriteLineIf(LayoutDebugScrollableBase, "Snapping to :" + targetPosition); - AnimateChildTo(ScrollDuration,targetPosition); + + float destinationX = -(mScrollingChild.Children[CurrentPage].Position.X + mScrollingChild.Children[CurrentPage].CurrentSize.Width/2.0f - CurrentSize.Width/2.0f); // set to middle of current page + Debug.WriteLineIf(LayoutDebugScrollableBase, "Snapping to :" + destinationX); + AnimateChildTo(ScrollDuration, destinationX); } } else