1 /* Copyright (c) 2020 Samsung Electronics Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
18 using Tizen.NUI.BaseComponents;
19 using System.Collections.Generic;
20 using System.ComponentModel;
21 using System.Diagnostics;
22 using System.Runtime.InteropServices;
23 using Tizen.NUI.Accessibility;
25 namespace Tizen.NUI.Components
28 /// ScrollEventArgs is a class to record scroll event arguments which will sent to user.
30 /// <since_tizen> 8 </since_tizen>
31 public class ScrollEventArgs : EventArgs
33 private Position position;
34 private Position scrollPosition;
37 /// Default constructor.
39 /// <param name="position">Current container position</param>
40 /// <since_tizen> 8 </since_tizen>
41 public ScrollEventArgs(Position position)
43 this.position = position;
44 this.scrollPosition = new Position(-position);
48 /// Current position of ContentContainer.
50 /// <since_tizen> 8 </since_tizen>
51 public Position Position
59 /// Current scroll position of scrollableBase pan.
60 /// This is the position in the opposite direction to the current position of ContentContainer.
62 [EditorBrowsable(EditorBrowsableState.Never)]
63 public Position ScrollPosition
67 return scrollPosition;
73 /// ScrollOutofBoundEventArgs is to record scroll out-of-bound event arguments which will be sent to user.
75 [EditorBrowsable(EditorBrowsableState.Never)]
76 public class ScrollOutOfBoundEventArgs : EventArgs
79 /// The direction to be touched.
81 [EditorBrowsable(EditorBrowsableState.Never)]
87 [EditorBrowsable(EditorBrowsableState.Never)]
93 [EditorBrowsable(EditorBrowsableState.Never)]
99 [EditorBrowsable(EditorBrowsableState.Never)]
105 [EditorBrowsable(EditorBrowsableState.Never)]
112 /// <param name="direction">Current pan direction</param>
113 /// <param name="displacement">Current total displacement</param>
114 [EditorBrowsable(EditorBrowsableState.Never)]
115 public ScrollOutOfBoundEventArgs(Direction direction, float displacement)
117 PanDirection = direction;
118 Displacement = displacement;
122 /// Current pan direction of ContentContainer.
124 [EditorBrowsable(EditorBrowsableState.Never)]
125 public Direction PanDirection
131 /// Current total displacement of ContentContainer.
132 /// if its value is greater than 0, it is at the top/left;
133 /// if less than 0, it is at the bottom/right.
135 [EditorBrowsable(EditorBrowsableState.Never)]
136 public float Displacement
143 /// This class provides a View that can scroll a single View with a layout. This View can be a nest of Views.
145 /// <since_tizen> 8 </since_tizen>
146 public class ScrollableBase : Control
148 static bool LayoutDebugScrollableBase = false; // Debug flag
149 private Direction mScrollingDirection = Direction.Vertical;
150 private bool mScrollEnabled = true;
151 private int mScrollDuration = 125;
152 private int mPageWidth = 0;
153 private float mPageFlickThreshold = 0.4f;
154 private float mScrollingEventThreshold = 0.001f;
156 private class ScrollableBaseCustomLayout : AbsoluteLayout
158 protected override void OnMeasure(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec)
160 MeasuredSize.StateType childWidthState = MeasuredSize.StateType.MeasuredSizeOK;
161 MeasuredSize.StateType childHeightState = MeasuredSize.StateType.MeasuredSizeOK;
163 Direction scrollingDirection = Direction.Vertical;
164 ScrollableBase scrollableBase = this.Owner as ScrollableBase;
165 if (scrollableBase != null)
167 scrollingDirection = scrollableBase.ScrollingDirection;
170 float totalWidth = 0.0f;
171 float totalHeight = 0.0f;
173 // measure child, should be a single scrolling child
174 foreach (LayoutItem childLayout in LayoutChildren)
176 if (childLayout != null && childLayout.Owner.Name == "ContentContainer")
179 // Use an Unspecified MeasureSpecification mode so scrolling child is not restricted to it's parents size in Height (for vertical scrolling)
180 // or Width for horizontal scrolling
181 if (scrollingDirection == Direction.Vertical)
183 MeasureSpecification unrestrictedMeasureSpec = new MeasureSpecification(heightMeasureSpec.Size, MeasureSpecification.ModeType.Unspecified);
184 MeasureChildWithMargins(childLayout, widthMeasureSpec, new LayoutLength(0), unrestrictedMeasureSpec, new LayoutLength(0)); // Height unrestricted by parent
188 MeasureSpecification unrestrictedMeasureSpec = new MeasureSpecification(widthMeasureSpec.Size, MeasureSpecification.ModeType.Unspecified);
189 MeasureChildWithMargins(childLayout, unrestrictedMeasureSpec, new LayoutLength(0), heightMeasureSpec, new LayoutLength(0)); // Width unrestricted by parent
192 totalWidth = (childLayout.MeasuredWidth.Size + (childLayout.Padding.Start + childLayout.Padding.End)).AsDecimal();
193 totalHeight = (childLayout.MeasuredHeight.Size + (childLayout.Padding.Top + childLayout.Padding.Bottom)).AsDecimal();
195 if (childLayout.MeasuredWidth.State == MeasuredSize.StateType.MeasuredSizeTooSmall)
197 childWidthState = MeasuredSize.StateType.MeasuredSizeTooSmall;
199 if (childLayout.MeasuredHeight.State == MeasuredSize.StateType.MeasuredSizeTooSmall)
201 childHeightState = MeasuredSize.StateType.MeasuredSizeTooSmall;
206 MeasuredSize widthSizeAndState = ResolveSizeAndState(new LayoutLength(totalWidth), widthMeasureSpec, MeasuredSize.StateType.MeasuredSizeOK);
207 MeasuredSize heightSizeAndState = ResolveSizeAndState(new LayoutLength(totalHeight), heightMeasureSpec, MeasuredSize.StateType.MeasuredSizeOK);
208 totalWidth = widthSizeAndState.Size.AsDecimal();
209 totalHeight = heightSizeAndState.Size.AsDecimal();
211 // Ensure layout respects it's given minimum size
212 totalWidth = Math.Max(totalWidth, SuggestedMinimumWidth.AsDecimal());
213 totalHeight = Math.Max(totalHeight, SuggestedMinimumHeight.AsDecimal());
215 widthSizeAndState.State = childWidthState;
216 heightSizeAndState.State = childHeightState;
218 SetMeasuredDimensions(ResolveSizeAndState(new LayoutLength(totalWidth), widthMeasureSpec, childWidthState),
219 ResolveSizeAndState(new LayoutLength(totalHeight), heightMeasureSpec, childHeightState));
221 // Size of ScrollableBase is changed. Change Page width too.
222 if (scrollableBase != null)
224 scrollableBase.mPageWidth = (int)MeasuredWidth.Size.AsRoundedValue();
225 scrollableBase.OnScrollingChildRelayout(null, null);
228 } // ScrollableBaseCustomLayout
231 /// The direction axis to scroll.
233 /// <since_tizen> 8 </since_tizen>
234 public enum Direction
239 /// <since_tizen> 8 </since_tizen>
245 /// <since_tizen> 8 </since_tizen>
250 /// Scrolling direction mode.
251 /// Default is Vertical scrolling.
253 /// <since_tizen> 8 </since_tizen>
254 public Direction ScrollingDirection
258 return mScrollingDirection;
262 if (value != mScrollingDirection)
264 mScrollingDirection = value;
265 mPanGestureDetector.ClearAngles();
266 mPanGestureDetector.AddDirection(value == Direction.Horizontal ?
267 PanGestureDetector.DirectionHorizontal : PanGestureDetector.DirectionVertical);
269 ContentContainer.WidthSpecification = ScrollingDirection == Direction.Vertical ? LayoutParamPolicies.MatchParent : LayoutParamPolicies.WrapContent;
270 ContentContainer.HeightSpecification = ScrollingDirection == Direction.Vertical ? LayoutParamPolicies.WrapContent : LayoutParamPolicies.MatchParent;
277 /// Enable or disable scrolling.
279 /// <since_tizen> 8 </since_tizen>
280 public bool ScrollEnabled
284 return mScrollEnabled;
288 if (value != mScrollEnabled)
290 mScrollEnabled = value;
293 mPanGestureDetector.Detected += OnPanGestureDetected;
297 mPanGestureDetector.Detected -= OnPanGestureDetected;
304 /// Gets scrollable status.
306 [EditorBrowsable(EditorBrowsableState.Never)]
307 protected override bool AccessibilityIsScrollable()
313 /// Pages mode, enables moving to the next or return to current page depending on pan displacement.
314 /// Default is false.
316 /// <since_tizen> 8 </since_tizen>
317 public bool SnapToPage { set; get; } = false;
320 /// Get current page.
321 /// Working property with SnapToPage property.
323 /// <since_tizen> 8 </since_tizen>
324 public int CurrentPage { get; private set; } = 0;
327 /// Duration of scroll animation.
328 /// Default value is 125ms.
330 /// <since_tizen> 8 </since_tizen>
331 public int ScrollDuration
335 mScrollDuration = value >= 0 ? value : mScrollDuration;
339 return mScrollDuration;
344 /// Scroll Available area.
346 /// <since_tizen> 8 </since_tizen>
347 public Vector2 ScrollAvailableArea { set; get; }
350 /// An event emitted when user starts dragging ScrollableBase, user can subscribe or unsubscribe to this event handler.<br />
352 /// <since_tizen> 8 </since_tizen>
353 public event EventHandler<ScrollEventArgs> ScrollDragStarted;
356 /// An event emitted when user stops dragging ScrollableBase, user can subscribe or unsubscribe to this event handler.<br />
358 /// <since_tizen> 8 </since_tizen>
359 public event EventHandler<ScrollEventArgs> ScrollDragEnded;
362 /// An event emitted when the scrolling slide animation starts, user can subscribe or unsubscribe to this event handler.<br />
364 /// <since_tizen> 8 </since_tizen>
365 public event EventHandler<ScrollEventArgs> ScrollAnimationStarted;
368 /// An event emitted when the scrolling slide animation ends, user can subscribe or unsubscribe to this event handler.<br />
370 /// <since_tizen> 8 </since_tizen>
371 public event EventHandler<ScrollEventArgs> ScrollAnimationEnded;
374 /// An event emitted when scrolling, user can subscribe or unsubscribe to this event handler.<br />
376 /// <since_tizen> 8 </since_tizen>
377 public event EventHandler<ScrollEventArgs> Scrolling;
380 /// An event emitted when scrolling out of bound, user can subscribe or unsubscribe to this event handler.<br />
382 [EditorBrowsable(EditorBrowsableState.Never)]
383 public event EventHandler<ScrollOutOfBoundEventArgs> ScrollOutOfBound;
386 /// Scrollbar for ScrollableBase.
388 /// <since_tizen> 8 </since_tizen>
389 public ScrollbarBase Scrollbar
399 base.Remove(scrollBar);
403 if (scrollBar != null)
405 scrollBar.Name = "ScrollBar";
423 /// Always hide Scrollbar.
425 /// <since_tizen> 8 </since_tizen>
426 public bool HideScrollbar
430 return hideScrollbar;
434 hideScrollbar = value;
451 /// Container which has content of ScrollableBase.
453 /// <since_tizen> 8 </since_tizen>
454 public View ContentContainer { get; private set; }
457 /// Set the layout on this View. Replaces any existing Layout.
459 /// <since_tizen> 8 </since_tizen>
460 public new LayoutItem Layout
464 return ContentContainer.Layout;
468 ContentContainer.Layout = value;
473 /// List of children of Container.
475 /// <since_tizen> 8 </since_tizen>
476 public new List<View> Children
480 return ContentContainer.Children;
485 /// Deceleration rate of scrolling by finger.
486 /// Rate should be bigger than 0 and smaller than 1.
487 /// Default value is 0.998f;
489 /// <since_tizen> 8 </since_tizen>
490 public float DecelerationRate
494 return decelerationRate;
498 decelerationRate = (value < 1 && value > 0) ? value : decelerationRate;
499 logValueOfDeceleration = (float)Math.Log(value);
504 /// Threshold not to go infinite at the end of scrolling animation.
506 [EditorBrowsable(EditorBrowsableState.Never)]
507 public float DecelerationThreshold { get; set; } = 0.1f;
510 /// Scrolling event will be thrown when this amount of scroll position is changed.
511 /// If this threshold becomes smaller, the tracking detail increases but the scrolling range that can be tracked becomes smaller.
512 /// If large sized ContentContainer is required, please use larger threshold value.
513 /// Default ScrollingEventThreshold value is 0.001f.
515 [EditorBrowsable(EditorBrowsableState.Never)]
516 public float ScrollingEventThreshold
520 return mScrollingEventThreshold;
524 if (mScrollingEventThreshold != value && value > 0)
526 ContentContainer.RemovePropertyNotification(propertyNotification);
527 propertyNotification = ContentContainer.AddPropertyNotification("position", PropertyCondition.Step(value));
528 propertyNotification.Notified += OnPropertyChanged;
529 mScrollingEventThreshold = value;
535 /// Page will be changed when velocity of panning is over threshold.
536 /// The unit of threshold is pixel per millisecond.
538 /// <since_tizen> 8 </since_tizen>
539 public float PageFlickThreshold
543 return mPageFlickThreshold;
547 mPageFlickThreshold = value >= 0f ? value : mPageFlickThreshold;
552 /// Padding for the ScrollableBase
554 [EditorBrowsable(EditorBrowsableState.Never)]
555 public new Extents Padding
559 return ContentContainer.Padding;
563 ContentContainer.Padding = value;
568 /// Alphafunction for scroll animation.
570 [EditorBrowsable(EditorBrowsableState.Never)]
571 public AlphaFunction ScrollAlphaFunction { get; set; } = new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear);
573 private bool hideScrollbar = true;
574 private float maxScrollDistance;
575 private float childTargetPosition = 0.0f;
576 private PanGestureDetector mPanGestureDetector;
577 private View mInterruptTouchingChild;
578 private ScrollbarBase scrollBar;
579 private bool scrolling = false;
580 private float ratioOfScreenWidthToCompleteScroll = 0.5f;
581 private float totalDisplacementForPan = 0.0f;
582 private Size previousContainerSize = new Size();
583 private Size previousSize = new Size();
584 private PropertyNotification propertyNotification;
585 private float noticeAnimationEndBeforePosition = 0.0f;
586 private bool readyToNotice = false;
589 /// Notice before animation is finished.
591 [EditorBrowsable(EditorBrowsableState.Never)]
592 // Let's consider more whether this needs to be set as protected.
593 public float NoticeAnimationEndBeforePosition
595 get => noticeAnimationEndBeforePosition;
596 set => noticeAnimationEndBeforePosition = value;
599 // Let's consider more whether this needs to be set as protected.
600 private float finalTargetPosition;
602 private Animation scrollAnimation;
603 // Declare user alpha function delegate
604 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
605 private delegate float UserAlphaFunctionDelegate(float progress);
606 private UserAlphaFunctionDelegate customScrollAlphaFunction;
607 private float velocityOfLastPan = 0.0f;
608 private float panAnimationDuration = 0.0f;
609 private float panAnimationDelta = 0.0f;
610 private float logValueOfDeceleration = 0.0f;
611 private float decelerationRate = 0.0f;
613 private View topOverShootingShadowView;
614 private View bottomOverShootingShadowView;
615 private View leftOverShootingShadowView;
616 private View rightOverShootingShadowView;
617 private const int overShootingShadowScaleHeightLimit = 64 * 3;
618 private const int overShootingShadowAnimationDuration = 300;
619 private Animation overShootingShadowAnimation;
620 private bool isOverShootingShadowShown = false;
621 private float startShowShadowDisplacement;
624 /// Default Constructor
626 /// <since_tizen> 8 </since_tizen>
627 public ScrollableBase() : base()
629 DecelerationRate = 0.998f;
631 base.Layout = new ScrollableBaseCustomLayout();
632 mPanGestureDetector = new PanGestureDetector();
633 mPanGestureDetector.Attach(this);
634 mPanGestureDetector.AddDirection(PanGestureDetector.DirectionVertical);
635 if (mPanGestureDetector.GetMaximumTouchesRequired() < 2) mPanGestureDetector.SetMaximumTouchesRequired(2);
636 mPanGestureDetector.Detected += OnPanGestureDetected;
638 ClippingMode = ClippingModeType.ClipToBoundingBox;
640 //Default Scrolling child
641 ContentContainer = new View()
643 Name = "ContentContainer",
644 WidthSpecification = ScrollingDirection == Direction.Vertical ? LayoutParamPolicies.MatchParent : LayoutParamPolicies.WrapContent,
645 HeightSpecification = ScrollingDirection == Direction.Vertical ? LayoutParamPolicies.WrapContent : LayoutParamPolicies.MatchParent,
647 ContentContainer.Relayout += OnScrollingChildRelayout;
648 propertyNotification = ContentContainer.AddPropertyNotification("position", PropertyCondition.Step(mScrollingEventThreshold));
649 propertyNotification.Notified += OnPropertyChanged;
650 base.Add(ContentContainer);
652 //Interrupt touching when panning is started
653 mInterruptTouchingChild = new View()
655 Size = new Size(Window.Instance.WindowSize),
656 BackgroundColor = Color.Transparent,
658 mInterruptTouchingChild.TouchEvent += OnIterruptTouchingChildTouched;
659 Scrollbar = new Scrollbar();
661 //Show vertical shadow on the top (or bottom) of the scrollable when panning down (or up).
662 topOverShootingShadowView = new View
664 BackgroundImage = FrameworkInformation.ResourcePath + "nui_component_default_scroll_over_shooting_top.png",
667 PositionUsesPivotPoint = true,
668 ParentOrigin = NUI.ParentOrigin.TopCenter,
669 PivotPoint = NUI.PivotPoint.TopCenter,
671 bottomOverShootingShadowView = new View
673 BackgroundImage = FrameworkInformation.ResourcePath + "nui_component_default_scroll_over_shooting_bottom.png",
676 PositionUsesPivotPoint = true,
677 ParentOrigin = NUI.ParentOrigin.BottomCenter,
678 PivotPoint = NUI.PivotPoint.BottomCenter,
680 //Show horizontal shadow on the left (or right) of the scrollable when panning down (or up).
681 leftOverShootingShadowView = new View
683 BackgroundImage = FrameworkInformation.ResourcePath + "nui_component_default_scroll_over_shooting_left.png",
686 PositionUsesPivotPoint = true,
687 ParentOrigin = NUI.ParentOrigin.CenterLeft,
688 PivotPoint = NUI.PivotPoint.CenterLeft,
690 rightOverShootingShadowView = new View
692 BackgroundImage = FrameworkInformation.ResourcePath + "nui_component_default_scroll_over_shooting_right.png",
695 PositionUsesPivotPoint = true,
696 ParentOrigin = NUI.ParentOrigin.CenterRight,
697 PivotPoint = NUI.PivotPoint.CenterRight,
700 AccessibilityManager.Instance.SetAccessibilityAttribute(this, AccessibilityManager.AccessibilityAttribute.Trait, "ScrollableBase");
703 private bool OnIterruptTouchingChildTouched(object source, View.TouchEventArgs args)
705 if (args.Touch.GetState(0) == PointStateType.Down)
707 if (scrolling && !SnapToPage)
715 private void OnPropertyChanged(object source, PropertyNotification.NotifyEventArgs args)
721 /// Called after a child has been added to the owning view.
723 /// <param name="view">The child which has been added.</param>
724 /// <since_tizen> 8 </since_tizen>
725 public override void Add(View view)
727 ContentContainer.Add(view);
731 /// Called after a child has been removed from the owning view.
733 /// <param name="view">The child which has been removed.</param>
734 /// <since_tizen> 8 </since_tizen>
735 public override void Remove(View view)
737 if (SnapToPage && CurrentPage == Children.IndexOf(view) && CurrentPage == Children.Count - 1)
739 // Target View is current page and also last child.
740 // CurrentPage should be changed to previous page.
741 CurrentPage = Math.Max(0, CurrentPage - 1);
742 ScrollToIndex(CurrentPage);
745 ContentContainer.Remove(view);
748 private void OnScrollingChildRelayout(object source, EventArgs args)
750 // Size is changed. Calculate maxScrollDistance.
751 bool isSizeChanged = previousContainerSize.Width != ContentContainer.Size.Width || previousContainerSize.Height != ContentContainer.Size.Height ||
752 previousSize.Width != Size.Width || previousSize.Height != Size.Height;
756 maxScrollDistance = CalculateMaximumScrollDistance();
757 if (!ReviseContainerPositionIfNeed())
763 previousContainerSize = ContentContainer.Size;
767 private bool ReviseContainerPositionIfNeed()
769 bool isHorizontal = ScrollingDirection == Direction.Horizontal;
770 float currentPosition = isHorizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y;
772 if (Math.Abs(currentPosition) > maxScrollDistance)
775 var targetPosition = BoundScrollPosition(-maxScrollDistance);
776 if (isHorizontal) ContentContainer.PositionX = targetPosition;
777 else ContentContainer.PositionY = targetPosition;
785 /// The composition of a Scrollbar can vary depending on how you use ScrollableBase.
786 /// Set the composition that will go into the ScrollableBase according to your ScrollableBase.
788 /// <since_tizen> 8 </since_tizen>
789 [EditorBrowsable(EditorBrowsableState.Never)]
790 protected virtual void SetScrollbar()
794 bool isHorizontal = ScrollingDirection == Direction.Horizontal;
795 float contentLength = isHorizontal ? ContentContainer.Size.Width : ContentContainer.Size.Height;
796 float viewportLength = isHorizontal ? Size.Width : Size.Height;
797 float currentPosition = isHorizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y;
798 Scrollbar.Initialize(contentLength, viewportLength, -currentPosition, isHorizontal);
802 /// Update scrollbar position and size.
803 [EditorBrowsable(EditorBrowsableState.Never)]
804 protected virtual void UpdateScrollbar()
808 bool isHorizontal = ScrollingDirection == Direction.Horizontal;
809 float contentLength = isHorizontal ? ContentContainer.Size.Width : ContentContainer.Size.Height;
810 float viewportLength = isHorizontal ? Size.Width : Size.Height;
811 float currentPosition = isHorizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y;
812 Scrollbar.Update(contentLength, viewportLength, -currentPosition);
817 /// Scrolls to the item at the specified index.
819 /// <param name="index">Index of item.</param>
820 /// <since_tizen> 8 </since_tizen>
821 public void ScrollToIndex(int index)
823 if (ContentContainer.ChildCount - 1 < index || index < 0)
833 float targetPosition = Math.Min(ScrollingDirection == Direction.Vertical ? Children[index].Position.Y : Children[index].Position.X, maxScrollDistance);
834 AnimateChildTo(ScrollDuration, -targetPosition);
837 private void OnScrollDragStarted()
839 ScrollEventArgs eventArgs = new ScrollEventArgs(ContentContainer.CurrentPosition);
840 ScrollDragStarted?.Invoke(this, eventArgs);
843 private void OnScrollDragEnded()
845 ScrollEventArgs eventArgs = new ScrollEventArgs(ContentContainer.CurrentPosition);
846 ScrollDragEnded?.Invoke(this, eventArgs);
849 private void OnScrollAnimationStarted()
851 ScrollEventArgs eventArgs = new ScrollEventArgs(ContentContainer.CurrentPosition);
852 ScrollAnimationStarted?.Invoke(this, eventArgs);
855 private void OnScrollAnimationEnded()
858 base.Remove(mInterruptTouchingChild);
860 ScrollEventArgs eventArgs = new ScrollEventArgs(ContentContainer.CurrentPosition);
861 ScrollAnimationEnded?.Invoke(this, eventArgs);
864 private void OnScroll()
866 ScrollEventArgs eventArgs = new ScrollEventArgs(ContentContainer.CurrentPosition);
867 Scrolling?.Invoke(this, eventArgs);
869 bool isHorizontal = ScrollingDirection == Direction.Horizontal;
870 float contentLength = isHorizontal ? ContentContainer.Size.Width : ContentContainer.Size.Height;
871 float currentPosition = isHorizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y;
873 scrollBar?.Update(contentLength, Math.Abs(currentPosition));
874 CheckPreReachedTargetPosition();
877 private void CheckPreReachedTargetPosition()
879 // Check whether we reached pre-reached target position
881 ContentContainer.CurrentPosition.Y <= finalTargetPosition + NoticeAnimationEndBeforePosition &&
882 ContentContainer.CurrentPosition.Y >= finalTargetPosition - NoticeAnimationEndBeforePosition)
885 readyToNotice = false;
886 OnPreReachedTargetPosition(finalTargetPosition);
891 /// This helps developer who wants to know before scroll is reaching target position.
893 /// <param name="targetPosition">Index of item.</param>
894 /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
895 [EditorBrowsable(EditorBrowsableState.Never)]
896 protected virtual void OnPreReachedTargetPosition(float targetPosition)
901 private void StopScroll()
903 if (scrollAnimation != null)
905 if (scrollAnimation.State == Animation.States.Playing)
907 Debug.WriteLineIf(LayoutDebugScrollableBase, "StopScroll Animation Playing");
908 scrollAnimation.Stop(Animation.EndActions.Cancel);
909 OnScrollAnimationEnded();
911 scrollAnimation.Clear();
915 private void AnimateChildTo(int duration, float axisPosition)
917 Debug.WriteLineIf(LayoutDebugScrollableBase, "AnimationTo Animation Duration:" + duration + " Destination:" + axisPosition);
918 finalTargetPosition = axisPosition;
920 StopScroll(); // Will replace previous animation so will stop existing one.
922 if (scrollAnimation == null)
924 scrollAnimation = new Animation();
925 scrollAnimation.Finished += ScrollAnimationFinished;
928 scrollAnimation.Duration = duration;
929 scrollAnimation.DefaultAlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSquare);
930 scrollAnimation.AnimateTo(ContentContainer, (ScrollingDirection == Direction.Horizontal) ? "PositionX" : "PositionY", axisPosition, ScrollAlphaFunction);
932 OnScrollAnimationStarted();
933 scrollAnimation.Play();
937 /// Scroll to specific position with or without animation.
939 /// <param name="position">Destination.</param>
940 /// <param name="animate">Scroll with or without animation</param>
941 /// <since_tizen> 8 </since_tizen>
942 public void ScrollTo(float position, bool animate)
944 float currentPositionX = ContentContainer.CurrentPosition.X != 0 ? ContentContainer.CurrentPosition.X : ContentContainer.Position.X;
945 float currentPositionY = ContentContainer.CurrentPosition.Y != 0 ? ContentContainer.CurrentPosition.Y : ContentContainer.Position.Y;
946 float delta = ScrollingDirection == Direction.Horizontal ? currentPositionX : currentPositionY;
947 // The argument position is the new pan position. So the new position of ScrollableBase becomes (-position).
948 // To move ScrollableBase's position to (-position), it moves by (-position - currentPosition).
949 delta = -position - delta;
951 ScrollBy(delta, animate);
954 private float BoundScrollPosition(float targetPosition)
956 if (ScrollAvailableArea != null)
958 float minScrollPosition = ScrollAvailableArea.X;
959 float maxScrollPosition = ScrollAvailableArea.Y;
961 targetPosition = Math.Min(-minScrollPosition, targetPosition);
962 targetPosition = Math.Max(-maxScrollPosition, targetPosition);
966 targetPosition = Math.Min(0, targetPosition);
967 targetPosition = Math.Max(-maxScrollDistance, targetPosition);
970 return targetPosition;
973 private void ScrollBy(float displacement, bool animate)
975 if (GetChildCount() == 0 || maxScrollDistance < 0)
980 float childCurrentPosition = (ScrollingDirection == Direction.Horizontal) ? ContentContainer.PositionX : ContentContainer.PositionY;
982 Debug.WriteLineIf(LayoutDebugScrollableBase, "ScrollBy childCurrentPosition:" + childCurrentPosition +
983 " displacement:" + displacement,
984 " maxScrollDistance:" + maxScrollDistance);
986 childTargetPosition = childCurrentPosition + displacement; // child current position + gesture displacement
988 Debug.WriteLineIf(LayoutDebugScrollableBase, "ScrollBy currentAxisPosition:" + childCurrentPosition + "childTargetPosition:" + childTargetPosition);
992 // Calculate scroll animation duration
993 float scrollDistance = Math.Abs(displacement);
994 readyToNotice = true;
996 AnimateChildTo(ScrollDuration, BoundScrollPosition(AdjustTargetPositionOfScrollAnimation(BoundScrollPosition(childTargetPosition))));
1000 finalTargetPosition = BoundScrollPosition(childTargetPosition);
1002 // Set position of scrolling child without an animation
1003 if (ScrollingDirection == Direction.Horizontal)
1005 ContentContainer.PositionX = finalTargetPosition;
1009 ContentContainer.PositionY = finalTargetPosition;
1015 /// you can override it to clean-up your own resources.
1017 /// <param name="type">DisposeTypes</param>
1018 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1019 [EditorBrowsable(EditorBrowsableState.Never)]
1020 protected override void Dispose(DisposeTypes type)
1027 if (type == DisposeTypes.Explicit)
1029 StopOverShootingShadowAnimation();
1032 if (mPanGestureDetector != null)
1034 mPanGestureDetector.Detected -= OnPanGestureDetected;
1035 mPanGestureDetector.Dispose();
1036 mPanGestureDetector = null;
1039 propertyNotification.Dispose();
1044 private float CalculateMaximumScrollDistance()
1046 float scrollingChildLength = 0;
1047 float scrollerLength = 0;
1048 if (ScrollingDirection == Direction.Horizontal)
1050 Debug.WriteLineIf(LayoutDebugScrollableBase, "Horizontal");
1052 scrollingChildLength = ContentContainer.Size.Width;
1053 scrollerLength = Size.Width;
1057 Debug.WriteLineIf(LayoutDebugScrollableBase, "Vertical");
1058 scrollingChildLength = ContentContainer.Size.Height;
1059 scrollerLength = Size.Height;
1062 Debug.WriteLineIf(LayoutDebugScrollableBase, "ScrollBy maxScrollDistance:" + (scrollingChildLength - scrollerLength) +
1063 " parent length:" + scrollerLength +
1064 " scrolling child length:" + scrollingChildLength);
1066 return Math.Max(scrollingChildLength - scrollerLength, 0);
1069 private void PageSnap(float velocity)
1073 Debug.WriteLineIf(LayoutDebugScrollableBase, "PageSnap with pan candidate totalDisplacement:" + totalDisplacementForPan +
1074 " currentPage[" + CurrentPage + "]");
1076 //Increment current page if total displacement enough to warrant a page change.
1077 if (Math.Abs(totalDisplacementForPan) > (mPageWidth * ratioOfScreenWidthToCompleteScroll))
1079 if (totalDisplacementForPan < 0)
1081 CurrentPage = Math.Min(Math.Max(Children.Count - 1, 0), ++CurrentPage);
1085 CurrentPage = Math.Max(0, --CurrentPage);
1088 else if (Math.Abs(velocity) > PageFlickThreshold)
1092 CurrentPage = Math.Min(Math.Max(Children.Count - 1, 0), ++CurrentPage);
1096 CurrentPage = Math.Max(0, --CurrentPage);
1100 // Animate to new page or reposition to current page
1101 if (ScrollingDirection == Direction.Horizontal)
1102 destination = -(Children[CurrentPage].Position.X + Children[CurrentPage].CurrentSize.Width / 2 - CurrentSize.Width / 2); // set to middle of current page
1104 destination = -(Children[CurrentPage].Position.Y + Children[CurrentPage].CurrentSize.Height / 2 - CurrentSize.Height / 2);
1106 AnimateChildTo(ScrollDuration, destination);
1110 /// Enable/Disable overshooting effect. default is disabled.
1112 [EditorBrowsable(EditorBrowsableState.Never)]
1113 public bool EnableOverShootingEffect { get; set; } = false;
1115 private void AttachOverShootingShadowView()
1117 if (!EnableOverShootingEffect)
1120 // stop animation if necessary.
1121 StopOverShootingShadowAnimation();
1123 if (ScrollingDirection == Direction.Horizontal)
1125 base.Add(leftOverShootingShadowView);
1126 base.Add(rightOverShootingShadowView);
1128 leftOverShootingShadowView.Size = new Size(0.0f, SizeHeight);
1129 leftOverShootingShadowView.Opacity = 1.0f;
1130 leftOverShootingShadowView.RaiseToTop();
1132 rightOverShootingShadowView.Size = new Size(0.0f, SizeHeight);
1133 rightOverShootingShadowView.Opacity = 1.0f;
1134 rightOverShootingShadowView.RaiseToTop();
1138 base.Add(topOverShootingShadowView);
1139 base.Add(bottomOverShootingShadowView);
1141 topOverShootingShadowView.Size = new Size(SizeWidth, 0.0f);
1142 topOverShootingShadowView.Opacity = 1.0f;
1143 topOverShootingShadowView.RaiseToTop();
1145 bottomOverShootingShadowView.Size = new Size(SizeWidth, 0.0f);
1146 bottomOverShootingShadowView.Opacity = 1.0f;
1147 bottomOverShootingShadowView.RaiseToTop();
1150 // at the beginning, height or width of overshooting shadow is 0, so it is invisible.
1151 isOverShootingShadowShown = false;
1154 private void DragOverShootingShadow(float totalPanDisplacement, float panDisplacement)
1156 if (!EnableOverShootingEffect)
1159 if (totalPanDisplacement > 0) // downwards
1161 // check if reaching at the top / left.
1162 if ((int)finalTargetPosition != 0)
1164 isOverShootingShadowShown = false;
1168 // save start displacement, and re-calculate displacement.
1169 if (!isOverShootingShadowShown)
1171 startShowShadowDisplacement = totalPanDisplacement;
1173 isOverShootingShadowShown = true;
1175 float newDisplacement = (int)totalPanDisplacement < (int)startShowShadowDisplacement ? 0 : totalPanDisplacement - startShowShadowDisplacement;
1177 if (ScrollingDirection == Direction.Horizontal)
1179 // scale limit of height is 60%.
1180 float heightScale = newDisplacement / overShootingShadowScaleHeightLimit;
1181 leftOverShootingShadowView.SizeHeight = heightScale > 0.6f ? SizeHeight * 0.4f : SizeHeight * (1.0f - heightScale);
1183 // scale limit of width is 300%.
1184 leftOverShootingShadowView.SizeWidth = newDisplacement > overShootingShadowScaleHeightLimit ? overShootingShadowScaleHeightLimit : newDisplacement;
1187 ScrollOutOfBoundEventArgs.Direction scrollDirection = panDisplacement > 0 ?
1188 ScrollOutOfBoundEventArgs.Direction.Right : ScrollOutOfBoundEventArgs.Direction.Left;
1189 OnScrollOutOfBound(scrollDirection, totalPanDisplacement);
1193 // scale limit of width is 60%.
1194 float widthScale = newDisplacement / overShootingShadowScaleHeightLimit;
1195 topOverShootingShadowView.SizeWidth = widthScale > 0.6f ? SizeWidth * 0.4f : SizeWidth * (1.0f - widthScale);
1197 // scale limit of height is 300%.
1198 topOverShootingShadowView.SizeHeight = newDisplacement > overShootingShadowScaleHeightLimit ? overShootingShadowScaleHeightLimit : newDisplacement;
1201 ScrollOutOfBoundEventArgs.Direction scrollDirection = panDisplacement > 0 ?
1202 ScrollOutOfBoundEventArgs.Direction.Down : ScrollOutOfBoundEventArgs.Direction.Up;
1203 OnScrollOutOfBound(scrollDirection, totalPanDisplacement);
1206 else if (totalPanDisplacement < 0) // upwards
1208 // check if reaching at the bottom.
1209 if (-(int)finalTargetPosition != (int)maxScrollDistance)
1211 isOverShootingShadowShown = false;
1215 // save start displacement, and re-calculate displacement.
1216 if (!isOverShootingShadowShown)
1218 startShowShadowDisplacement = totalPanDisplacement;
1220 isOverShootingShadowShown = true;
1222 float newDisplacement = (int)startShowShadowDisplacement < (int)totalPanDisplacement ? 0 : startShowShadowDisplacement - totalPanDisplacement;
1224 if (ScrollingDirection == Direction.Horizontal)
1226 // scale limit of height is 60%.
1227 float heightScale = newDisplacement / overShootingShadowScaleHeightLimit;
1228 rightOverShootingShadowView.SizeHeight = heightScale > 0.6f ? SizeHeight * 0.4f : SizeHeight * (1.0f - heightScale);
1230 // scale limit of width is 300%.
1231 rightOverShootingShadowView.SizeWidth = newDisplacement > overShootingShadowScaleHeightLimit ? overShootingShadowScaleHeightLimit : newDisplacement;
1234 ScrollOutOfBoundEventArgs.Direction scrollDirection = panDisplacement > 0 ?
1235 ScrollOutOfBoundEventArgs.Direction.Right : ScrollOutOfBoundEventArgs.Direction.Left;
1236 OnScrollOutOfBound(scrollDirection, totalPanDisplacement);
1240 // scale limit of width is 60%.
1241 float widthScale = newDisplacement / overShootingShadowScaleHeightLimit;
1242 bottomOverShootingShadowView.SizeWidth = widthScale > 0.6f ? SizeWidth * 0.4f : SizeWidth * (1.0f - widthScale);
1244 // scale limit of height is 300%.
1245 bottomOverShootingShadowView.SizeHeight = newDisplacement > overShootingShadowScaleHeightLimit ? overShootingShadowScaleHeightLimit : newDisplacement;
1248 ScrollOutOfBoundEventArgs.Direction scrollDirection = panDisplacement > 0 ?
1249 ScrollOutOfBoundEventArgs.Direction.Down : ScrollOutOfBoundEventArgs.Direction.Up;
1250 OnScrollOutOfBound(scrollDirection, totalPanDisplacement);
1255 // if total displacement is 0, shadow would become invisible.
1256 isOverShootingShadowShown = false;
1260 private void PlayOverShootingShadowAnimation()
1262 if (!EnableOverShootingEffect)
1265 // stop animation if necessary.
1266 StopOverShootingShadowAnimation();
1268 if (overShootingShadowAnimation == null)
1270 overShootingShadowAnimation = new Animation(overShootingShadowAnimationDuration);
1271 overShootingShadowAnimation.Finished += OnOverShootingShadowAnimationFinished;
1274 if (ScrollingDirection == Direction.Horizontal)
1276 View targetView = totalDisplacementForPan < 0 ? rightOverShootingShadowView : leftOverShootingShadowView;
1277 overShootingShadowAnimation.AnimateTo(targetView, "SizeHeight", SizeHeight);
1278 overShootingShadowAnimation.AnimateTo(targetView, "SizeWidth", 0.0f);
1279 overShootingShadowAnimation.AnimateTo(targetView, "Opacity", 0.0f);
1283 View targetView = totalDisplacementForPan < 0 ? bottomOverShootingShadowView : topOverShootingShadowView;
1284 overShootingShadowAnimation.AnimateTo(targetView, "SizeWidth", SizeWidth);
1285 overShootingShadowAnimation.AnimateTo(targetView, "SizeHeight", 0.0f);
1286 overShootingShadowAnimation.AnimateTo(targetView, "Opacity", 0.0f);
1288 overShootingShadowAnimation.Play();
1291 private void StopOverShootingShadowAnimation()
1293 if (overShootingShadowAnimation == null || overShootingShadowAnimation.State != Animation.States.Playing)
1296 overShootingShadowAnimation.Stop(Animation.EndActions.Cancel);
1297 OnOverShootingShadowAnimationFinished(null, null);
1298 overShootingShadowAnimation.Clear();
1301 private void OnOverShootingShadowAnimationFinished(object sender, EventArgs e)
1303 if (ScrollingDirection == Direction.Horizontal)
1305 base.Remove(leftOverShootingShadowView);
1306 base.Remove(rightOverShootingShadowView);
1308 leftOverShootingShadowView.Size = new Size(0.0f, SizeHeight);
1309 rightOverShootingShadowView.Size = new Size(0.0f, SizeHeight);
1313 base.Remove(topOverShootingShadowView);
1314 base.Remove(bottomOverShootingShadowView);
1316 topOverShootingShadowView.Size = new Size(SizeWidth, 0.0f);
1317 bottomOverShootingShadowView.Size = new Size(SizeWidth, 0.0f);
1320 // after animation finished, height/width & opacity of vertical shadow both are 0, so it is invisible.
1321 isOverShootingShadowShown = false;
1324 private void OnScrollOutOfBound(ScrollOutOfBoundEventArgs.Direction direction, float displacement)
1326 ScrollOutOfBoundEventArgs args = new ScrollOutOfBoundEventArgs(direction, displacement);
1327 ScrollOutOfBound?.Invoke(this, args);
1330 private void OnPanGestureDetected(object source, PanGestureDetector.DetectedEventArgs e)
1332 OnPanGesture(e.PanGesture);
1335 private void OnPanGesture(PanGesture panGesture)
1337 if (SnapToPage && scrollAnimation != null && scrollAnimation.State == Animation.States.Playing)
1342 if (panGesture.State == Gesture.StateType.Started)
1344 readyToNotice = false;
1345 base.Add(mInterruptTouchingChild);
1346 AttachOverShootingShadowView();
1347 Debug.WriteLineIf(LayoutDebugScrollableBase, "Gesture Start");
1348 if (scrolling && !SnapToPage)
1352 totalDisplacementForPan = 0.0f;
1353 OnScrollDragStarted();
1355 else if (panGesture.State == Gesture.StateType.Continuing)
1357 if (ScrollingDirection == Direction.Horizontal)
1359 // if vertical shadow is shown, does not scroll.
1360 if (!isOverShootingShadowShown)
1362 ScrollBy(panGesture.Displacement.X, false);
1364 totalDisplacementForPan += panGesture.Displacement.X;
1365 DragOverShootingShadow(totalDisplacementForPan, panGesture.Displacement.X);
1369 // if vertical shadow is shown, does not scroll.
1370 if (!isOverShootingShadowShown)
1372 ScrollBy(panGesture.Displacement.Y, false);
1374 totalDisplacementForPan += panGesture.Displacement.Y;
1375 DragOverShootingShadow(totalDisplacementForPan, panGesture.Displacement.Y);
1377 Debug.WriteLineIf(LayoutDebugScrollableBase, "OnPanGestureDetected Continue totalDisplacementForPan:" + totalDisplacementForPan);
1379 else if (panGesture.State == Gesture.StateType.Finished || panGesture.State == Gesture.StateType.Cancelled)
1381 PlayOverShootingShadowAnimation();
1382 OnScrollDragEnded();
1383 StopScroll(); // Will replace previous animation so will stop existing one.
1385 if (scrollAnimation == null)
1387 scrollAnimation = new Animation();
1388 scrollAnimation.Finished += ScrollAnimationFinished;
1391 float panVelocity = (ScrollingDirection == Direction.Horizontal) ? panGesture.Velocity.X : panGesture.Velocity.Y;
1395 PageSnap(panVelocity);
1399 if (panVelocity == 0)
1401 float currentScrollPosition = (ScrollingDirection == Direction.Horizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y);
1402 scrollAnimation.DefaultAlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear);
1403 scrollAnimation.Duration = 0;
1404 scrollAnimation.AnimateTo(ContentContainer, (ScrollingDirection == Direction.Horizontal) ? "PositionX" : "PositionY", currentScrollPosition);
1405 scrollAnimation.Play();
1409 Decelerating(panVelocity, scrollAnimation);
1413 totalDisplacementForPan = 0;
1415 readyToNotice = true;
1416 OnScrollAnimationStarted();
1420 internal void BaseRemove(View view)
1425 internal override bool OnAccessibilityPan(PanGesture gestures)
1427 if (SnapToPage && scrollAnimation != null && scrollAnimation.State == Animation.States.Playing)
1432 OnPanGesture(gestures);
1436 private float CustomScrollAlphaFunction(float progress)
1438 if (panAnimationDelta == 0)
1444 // Parameter "progress" is normalized value. We need to multiply target duration to calculate distance.
1445 // Can get real distance using equation of deceleration (check Decelerating function)
1446 // After get real distance, normalize it
1447 float realDuration = progress * panAnimationDuration;
1448 float realDistance = velocityOfLastPan * ((float)Math.Pow(decelerationRate, realDuration) - 1) / logValueOfDeceleration;
1449 float result = Math.Min(realDistance / Math.Abs(panAnimationDelta), 1.0f);
1455 /// you can override it to custom your decelerating
1457 /// <param name="velocity">Velocity of current pan.</param>
1458 /// <param name="animation">Scroll animation.</param>
1459 [EditorBrowsable(EditorBrowsableState.Never)]
1460 protected virtual void Decelerating(float velocity, Animation animation)
1462 // Decelerating using deceleration equation ===========
1464 // V : velocity (pixel per millisecond)
1465 // V0 : initial velocity
1466 // d : deceleration rate,
1468 // X : final position after decelerating
1469 // log : natural logarithm
1471 // V(t) = V0 * d pow t;
1472 // X(t) = V0 * (d pow t - 1) / log d; <-- Integrate the velocity function
1473 // X(∞) = V0 * d / (1 - d); <-- Result using infinite T can be final position because T is tending to infinity.
1475 // Because of final T is tending to infinity, we should use threshold value to finish.
1476 // Final T = log(-threshold * log d / |V0| ) / log d;
1478 velocityOfLastPan = Math.Abs(velocity);
1480 float currentScrollPosition = -(ScrollingDirection == Direction.Horizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y);
1481 panAnimationDelta = (velocityOfLastPan * decelerationRate) / (1 - decelerationRate);
1482 panAnimationDelta = velocity > 0 ? -panAnimationDelta : panAnimationDelta;
1484 float destination = -(panAnimationDelta + currentScrollPosition);
1485 float adjustDestination = AdjustTargetPositionOfScrollAnimation(destination);
1486 float maxPosition = ScrollAvailableArea != null ? ScrollAvailableArea.Y : maxScrollDistance;
1487 float minPosition = ScrollAvailableArea != null ? ScrollAvailableArea.X : 0;
1489 if (destination < -maxPosition || destination > minPosition)
1491 panAnimationDelta = velocity > 0 ? (currentScrollPosition - minPosition) : (maxPosition - currentScrollPosition);
1492 destination = velocity > 0 ? minPosition : -maxPosition;
1494 if (panAnimationDelta == 0)
1496 panAnimationDuration = 0.0f;
1500 panAnimationDuration = (float)Math.Log((panAnimationDelta * logValueOfDeceleration / velocityOfLastPan + 1), decelerationRate);
1503 Debug.WriteLineIf(LayoutDebugScrollableBase, "\n" +
1504 "OverRange======================= \n" +
1505 "[decelerationRate] " + decelerationRate + "\n" +
1506 "[logValueOfDeceleration] " + logValueOfDeceleration + "\n" +
1507 "[Velocity] " + velocityOfLastPan + "\n" +
1508 "[CurrentPosition] " + currentScrollPosition + "\n" +
1509 "[CandidateDelta] " + panAnimationDelta + "\n" +
1510 "[Destination] " + destination + "\n" +
1511 "[Duration] " + panAnimationDuration + "\n" +
1512 "================================ \n"
1517 panAnimationDuration = (float)Math.Log(-DecelerationThreshold * logValueOfDeceleration / velocityOfLastPan) / logValueOfDeceleration;
1519 if (adjustDestination != destination)
1521 destination = adjustDestination;
1522 panAnimationDelta = destination + currentScrollPosition;
1523 velocityOfLastPan = Math.Abs(panAnimationDelta * logValueOfDeceleration / ((float)Math.Pow(decelerationRate, panAnimationDuration) - 1));
1524 panAnimationDuration = (float)Math.Log(-DecelerationThreshold * logValueOfDeceleration / velocityOfLastPan) / logValueOfDeceleration;
1527 Debug.WriteLineIf(LayoutDebugScrollableBase, "\n" +
1528 "================================ \n" +
1529 "[decelerationRate] " + decelerationRate + "\n" +
1530 "[logValueOfDeceleration] " + logValueOfDeceleration + "\n" +
1531 "[Velocity] " + velocityOfLastPan + "\n" +
1532 "[CurrentPosition] " + currentScrollPosition + "\n" +
1533 "[CandidateDelta] " + panAnimationDelta + "\n" +
1534 "[Destination] " + destination + "\n" +
1535 "[Duration] " + panAnimationDuration + "\n" +
1536 "================================ \n"
1540 finalTargetPosition = destination;
1542 customScrollAlphaFunction = new UserAlphaFunctionDelegate(CustomScrollAlphaFunction);
1543 animation.DefaultAlphaFunction = new AlphaFunction(customScrollAlphaFunction);
1544 GC.KeepAlive(customScrollAlphaFunction);
1545 animation.Duration = (int)panAnimationDuration;
1546 animation.AnimateTo(ContentContainer, (ScrollingDirection == Direction.Horizontal) ? "PositionX" : "PositionY", destination);
1550 private void ScrollAnimationFinished(object sender, EventArgs e)
1552 OnScrollAnimationEnded();
1556 /// Adjust scrolling position by own scrolling rules.
1557 /// Override this function when developer wants to change destination of flicking.(e.g. always snap to center of item)
1559 /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
1560 [EditorBrowsable(EditorBrowsableState.Never)]
1561 protected virtual float AdjustTargetPositionOfScrollAnimation(float position)
1567 /// Scroll position given to ScrollTo.
1568 /// This is the position in the opposite direction to the position of ContentContainer.
1570 /// <since_tizen> 8 </since_tizen>
1571 public Position ScrollPosition
1575 return new Position(-ContentContainer.Position);
1580 /// Current scroll position in the middle of ScrollTo animation.
1581 /// This is the position in the opposite direction to the current position of ContentContainer.
1583 /// <since_tizen> 8 </since_tizen>
1584 public Position ScrollCurrentPosition
1588 return new Position(-ContentContainer.CurrentPosition);
1593 /// Remove all children in ContentContainer.
1595 /// <param name="dispose">If true, removed child is disposed.</param>
1596 [EditorBrowsable(EditorBrowsableState.Never)]
1597 public void RemoveAllChildren(bool dispose = false)
1599 RecursiveRemoveChildren(ContentContainer, dispose);
1602 private void RecursiveRemoveChildren(View parent, bool dispose)
1608 int maxChild = (int)parent.GetChildCount();
1609 for (int i = maxChild - 1; i >= 0; --i)
1611 View child = parent.GetChildAt((uint)i);
1616 RecursiveRemoveChildren(child, dispose);
1617 parent.Remove(child);