1 /* Copyright (c) 2021 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.
17 using Tizen.NUI.BaseComponents;
18 using System.Collections.Generic;
19 using System.ComponentModel;
20 using System.Diagnostics;
21 using System.Runtime.InteropServices;
22 using Tizen.NUI.Accessibility;
24 namespace Tizen.NUI.Components
27 /// ScrollEventArgs is a class to record scroll event arguments which will sent to user.
29 /// <since_tizen> 8 </since_tizen>
30 public class ScrollEventArgs : EventArgs
32 private Position position;
33 private Position scrollPosition;
36 /// Default constructor.
38 /// <param name="position">Current container position</param>
39 /// <since_tizen> 8 </since_tizen>
40 public ScrollEventArgs(Position position)
42 this.position = position;
43 this.scrollPosition = new Position(-position);
47 /// Current position of ContentContainer.
49 /// <since_tizen> 8 </since_tizen>
50 public Position Position
58 /// Current scroll position of scrollableBase pan.
59 /// This is the position in the opposite direction to the current position of ContentContainer.
61 [EditorBrowsable(EditorBrowsableState.Never)]
62 public Position ScrollPosition
66 return scrollPosition;
72 /// ScrollOutofBoundEventArgs is to record scroll out-of-bound event arguments which will be sent to user.
74 [EditorBrowsable(EditorBrowsableState.Never)]
75 public class ScrollOutOfBoundEventArgs : EventArgs
78 /// The direction to be touched.
80 [EditorBrowsable(EditorBrowsableState.Never)]
86 [EditorBrowsable(EditorBrowsableState.Never)]
92 [EditorBrowsable(EditorBrowsableState.Never)]
98 [EditorBrowsable(EditorBrowsableState.Never)]
104 [EditorBrowsable(EditorBrowsableState.Never)]
111 /// <param name="direction">Current pan direction</param>
112 /// <param name="displacement">Current total displacement</param>
113 [EditorBrowsable(EditorBrowsableState.Never)]
114 public ScrollOutOfBoundEventArgs(Direction direction, float displacement)
116 PanDirection = direction;
117 Displacement = displacement;
121 /// Current pan direction of ContentContainer.
123 [EditorBrowsable(EditorBrowsableState.Never)]
124 public Direction PanDirection
130 /// Current total displacement of ContentContainer.
131 /// if its value is greater than 0, it is at the top/left;
132 /// if less than 0, it is at the bottom/right.
134 [EditorBrowsable(EditorBrowsableState.Never)]
135 public float Displacement
142 /// This class provides a View that can scroll a single View with a layout. This View can be a nest of Views.
144 /// <since_tizen> 8 </since_tizen>
145 public class ScrollableBase : Control
147 static bool LayoutDebugScrollableBase = false; // Debug flag
148 private Direction mScrollingDirection = Direction.Vertical;
149 private bool mScrollEnabled = true;
150 private int mScrollDuration = 125;
151 private int mPageWidth = 0;
152 private float mPageFlickThreshold = 0.4f;
153 private float mScrollingEventThreshold = 0.001f;
155 private class ScrollableBaseCustomLayout : AbsoluteLayout
157 protected override void OnMeasure(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec)
159 MeasuredSize.StateType childWidthState = MeasuredSize.StateType.MeasuredSizeOK;
160 MeasuredSize.StateType childHeightState = MeasuredSize.StateType.MeasuredSizeOK;
162 Direction scrollingDirection = Direction.Vertical;
163 ScrollableBase scrollableBase = this.Owner as ScrollableBase;
164 if (scrollableBase != null)
166 scrollingDirection = scrollableBase.ScrollingDirection;
169 float totalWidth = 0.0f;
170 float totalHeight = 0.0f;
172 // measure child, should be a single scrolling child
173 foreach (LayoutItem childLayout in LayoutChildren)
175 if (childLayout != null && childLayout.Owner.Name == "ContentContainer")
178 // Use an Unspecified MeasureSpecification mode so scrolling child is not restricted to it's parents size in Height (for vertical scrolling)
179 // or Width for horizontal scrolling
180 if (scrollingDirection == Direction.Vertical)
182 MeasureSpecification unrestrictedMeasureSpec = new MeasureSpecification(heightMeasureSpec.Size, MeasureSpecification.ModeType.Unspecified);
183 MeasureChildWithMargins(childLayout, widthMeasureSpec, new LayoutLength(0), unrestrictedMeasureSpec, new LayoutLength(0)); // Height unrestricted by parent
187 MeasureSpecification unrestrictedMeasureSpec = new MeasureSpecification(widthMeasureSpec.Size, MeasureSpecification.ModeType.Unspecified);
188 MeasureChildWithMargins(childLayout, unrestrictedMeasureSpec, new LayoutLength(0), heightMeasureSpec, new LayoutLength(0)); // Width unrestricted by parent
191 totalWidth = (childLayout.MeasuredWidth.Size + (childLayout.Padding.Start + childLayout.Padding.End)).AsDecimal();
192 totalHeight = (childLayout.MeasuredHeight.Size + (childLayout.Padding.Top + childLayout.Padding.Bottom)).AsDecimal();
194 if (childLayout.MeasuredWidth.State == MeasuredSize.StateType.MeasuredSizeTooSmall)
196 childWidthState = MeasuredSize.StateType.MeasuredSizeTooSmall;
198 if (childLayout.MeasuredHeight.State == MeasuredSize.StateType.MeasuredSizeTooSmall)
200 childHeightState = MeasuredSize.StateType.MeasuredSizeTooSmall;
205 MeasuredSize widthSizeAndState = ResolveSizeAndState(new LayoutLength(totalWidth), widthMeasureSpec, MeasuredSize.StateType.MeasuredSizeOK);
206 MeasuredSize heightSizeAndState = ResolveSizeAndState(new LayoutLength(totalHeight), heightMeasureSpec, MeasuredSize.StateType.MeasuredSizeOK);
207 totalWidth = widthSizeAndState.Size.AsDecimal();
208 totalHeight = heightSizeAndState.Size.AsDecimal();
210 // Ensure layout respects it's given minimum size
211 totalWidth = Math.Max(totalWidth, SuggestedMinimumWidth.AsDecimal());
212 totalHeight = Math.Max(totalHeight, SuggestedMinimumHeight.AsDecimal());
214 widthSizeAndState.State = childWidthState;
215 heightSizeAndState.State = childHeightState;
217 SetMeasuredDimensions(ResolveSizeAndState(new LayoutLength(totalWidth), widthMeasureSpec, childWidthState),
218 ResolveSizeAndState(new LayoutLength(totalHeight), heightMeasureSpec, childHeightState));
220 // Size of ScrollableBase is changed. Change Page width too.
221 if (scrollableBase != null)
223 scrollableBase.mPageWidth = (int)MeasuredWidth.Size.AsRoundedValue();
224 scrollableBase.OnScrollingChildRelayout(null, null);
227 } // ScrollableBaseCustomLayout
230 /// The direction axis to scroll.
232 /// <since_tizen> 8 </since_tizen>
233 public enum Direction
238 /// <since_tizen> 8 </since_tizen>
244 /// <since_tizen> 8 </since_tizen>
249 /// Scrolling direction mode.
250 /// Default is Vertical scrolling.
252 /// <since_tizen> 8 </since_tizen>
253 public Direction ScrollingDirection
257 return mScrollingDirection;
261 if (value != mScrollingDirection)
263 mScrollingDirection = value;
264 mPanGestureDetector.ClearAngles();
265 mPanGestureDetector.AddDirection(value == Direction.Horizontal ?
266 PanGestureDetector.DirectionHorizontal : PanGestureDetector.DirectionVertical);
268 ContentContainer.WidthSpecification = ScrollingDirection == Direction.Vertical ? LayoutParamPolicies.MatchParent : LayoutParamPolicies.WrapContent;
269 ContentContainer.HeightSpecification = ScrollingDirection == Direction.Vertical ? LayoutParamPolicies.WrapContent : LayoutParamPolicies.MatchParent;
276 /// Enable or disable scrolling.
278 /// <since_tizen> 8 </since_tizen>
279 public bool ScrollEnabled
283 return mScrollEnabled;
287 if (value != mScrollEnabled)
289 mScrollEnabled = value;
292 mPanGestureDetector.Detected += OnPanGestureDetected;
296 mPanGestureDetector.Detected -= OnPanGestureDetected;
303 /// Gets scrollable status.
305 [EditorBrowsable(EditorBrowsableState.Never)]
306 protected override bool AccessibilityIsScrollable()
312 /// Pages mode, enables moving to the next or return to current page depending on pan displacement.
313 /// Default is false.
315 /// <since_tizen> 8 </since_tizen>
316 public bool SnapToPage { set; get; } = false;
319 /// Get current page.
320 /// Working property with SnapToPage property.
322 /// <since_tizen> 8 </since_tizen>
323 public int CurrentPage { get; private set; } = 0;
326 /// Duration of scroll animation.
327 /// Default value is 125ms.
329 /// <since_tizen> 8 </since_tizen>
330 public int ScrollDuration
334 mScrollDuration = value >= 0 ? value : mScrollDuration;
338 return mScrollDuration;
343 /// Scroll Available area.
345 /// <since_tizen> 8 </since_tizen>
346 public Vector2 ScrollAvailableArea { set; get; }
349 /// An event emitted when user starts dragging ScrollableBase, user can subscribe or unsubscribe to this event handler.<br />
351 /// <since_tizen> 8 </since_tizen>
352 public event EventHandler<ScrollEventArgs> ScrollDragStarted;
355 /// An event emitted when user stops dragging ScrollableBase, user can subscribe or unsubscribe to this event handler.<br />
357 /// <since_tizen> 8 </since_tizen>
358 public event EventHandler<ScrollEventArgs> ScrollDragEnded;
361 /// An event emitted when the scrolling slide animation starts, user can subscribe or unsubscribe to this event handler.<br />
363 /// <since_tizen> 8 </since_tizen>
364 public event EventHandler<ScrollEventArgs> ScrollAnimationStarted;
367 /// An event emitted when the scrolling slide animation ends, user can subscribe or unsubscribe to this event handler.<br />
369 /// <since_tizen> 8 </since_tizen>
370 public event EventHandler<ScrollEventArgs> ScrollAnimationEnded;
373 /// An event emitted when scrolling, user can subscribe or unsubscribe to this event handler.<br />
375 /// <since_tizen> 8 </since_tizen>
376 public event EventHandler<ScrollEventArgs> Scrolling;
379 /// An event emitted when scrolling out of bound, user can subscribe or unsubscribe to this event handler.<br />
381 [EditorBrowsable(EditorBrowsableState.Never)]
382 public event EventHandler<ScrollOutOfBoundEventArgs> ScrollOutOfBound;
385 /// Scrollbar for ScrollableBase.
387 /// <since_tizen> 8 </since_tizen>
388 public ScrollbarBase Scrollbar
398 base.Remove(scrollBar);
402 if (scrollBar != null)
404 scrollBar.Name = "ScrollBar";
422 /// Always hide Scrollbar.
424 /// <since_tizen> 8 </since_tizen>
425 public bool HideScrollbar
429 return hideScrollbar;
433 hideScrollbar = value;
450 /// Container which has content of ScrollableBase.
452 /// <since_tizen> 8 </since_tizen>
453 public View ContentContainer { get; private set; }
456 /// Set the layout on this View. Replaces any existing Layout.
458 /// <since_tizen> 8 </since_tizen>
459 public new LayoutItem Layout
463 return ContentContainer.Layout;
467 ContentContainer.Layout = value;
472 /// List of children of Container.
474 /// <since_tizen> 8 </since_tizen>
475 public new List<View> Children
479 return ContentContainer.Children;
484 /// Deceleration rate of scrolling by finger.
485 /// Rate should be bigger than 0 and smaller than 1.
486 /// Default value is 0.998f;
488 /// <since_tizen> 8 </since_tizen>
489 public float DecelerationRate
493 return decelerationRate;
497 decelerationRate = (value < 1 && value > 0) ? value : decelerationRate;
498 logValueOfDeceleration = (float)Math.Log(value);
503 /// Threshold not to go infinite at the end of scrolling animation.
505 [EditorBrowsable(EditorBrowsableState.Never)]
506 public float DecelerationThreshold { get; set; } = 0.1f;
509 /// Scrolling event will be thrown when this amount of scroll position is changed.
510 /// If this threshold becomes smaller, the tracking detail increases but the scrolling range that can be tracked becomes smaller.
511 /// If large sized ContentContainer is required, please use larger threshold value.
512 /// Default ScrollingEventThreshold value is 0.001f.
514 [EditorBrowsable(EditorBrowsableState.Never)]
515 public float ScrollingEventThreshold
519 return mScrollingEventThreshold;
523 if (mScrollingEventThreshold != value && value > 0)
525 ContentContainer.RemovePropertyNotification(propertyNotification);
526 propertyNotification = ContentContainer.AddPropertyNotification("position", PropertyCondition.Step(value));
527 propertyNotification.Notified += OnPropertyChanged;
528 mScrollingEventThreshold = value;
534 /// Page will be changed when velocity of panning is over threshold.
535 /// The unit of threshold is pixel per millisecond.
537 /// <since_tizen> 8 </since_tizen>
538 public float PageFlickThreshold
542 return mPageFlickThreshold;
546 mPageFlickThreshold = value >= 0f ? value : mPageFlickThreshold;
551 /// Padding for the ScrollableBase
553 [EditorBrowsable(EditorBrowsableState.Never)]
554 public new Extents Padding
558 return ContentContainer.Padding;
562 ContentContainer.Padding = value;
567 /// Alphafunction for scroll animation.
569 [EditorBrowsable(EditorBrowsableState.Never)]
570 public AlphaFunction ScrollAlphaFunction { get; set; } = new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear);
572 private bool hideScrollbar = true;
573 private float maxScrollDistance;
574 private float childTargetPosition = 0.0f;
575 private PanGestureDetector mPanGestureDetector;
576 private ScrollbarBase scrollBar;
577 private bool scrolling = false;
578 private float ratioOfScreenWidthToCompleteScroll = 0.5f;
579 private float totalDisplacementForPan = 0.0f;
580 private Size previousContainerSize = new Size();
581 private Size previousSize = new Size();
582 private PropertyNotification propertyNotification;
583 private float noticeAnimationEndBeforePosition = 0.0f;
584 private bool readyToNotice = false;
587 /// Notice before animation is finished.
589 [EditorBrowsable(EditorBrowsableState.Never)]
590 // Let's consider more whether this needs to be set as protected.
591 public float NoticeAnimationEndBeforePosition
593 get => noticeAnimationEndBeforePosition;
594 set => noticeAnimationEndBeforePosition = value;
597 // Let's consider more whether this needs to be set as protected.
598 private float finalTargetPosition;
600 private Animation scrollAnimation;
601 // Declare user alpha function delegate
602 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
603 private delegate float UserAlphaFunctionDelegate(float progress);
604 private UserAlphaFunctionDelegate customScrollAlphaFunction;
605 private float velocityOfLastPan = 0.0f;
606 private float panAnimationDuration = 0.0f;
607 private float panAnimationDelta = 0.0f;
608 private float logValueOfDeceleration = 0.0f;
609 private float decelerationRate = 0.0f;
611 private View topOverShootingShadowView;
612 private View bottomOverShootingShadowView;
613 private View leftOverShootingShadowView;
614 private View rightOverShootingShadowView;
615 private const int overShootingShadowScaleHeightLimit = 64 * 3;
616 private const int overShootingShadowAnimationDuration = 300;
617 private Animation overShootingShadowAnimation;
618 private bool isOverShootingShadowShown = false;
619 private float startShowShadowDisplacement;
622 /// Default Constructor
624 /// <since_tizen> 8 </since_tizen>
625 public ScrollableBase() : base()
627 DecelerationRate = 0.998f;
629 base.Layout = new ScrollableBaseCustomLayout();
630 mPanGestureDetector = new PanGestureDetector();
631 mPanGestureDetector.Attach(this);
632 mPanGestureDetector.AddDirection(PanGestureDetector.DirectionVertical);
633 if (mPanGestureDetector.GetMaximumTouchesRequired() < 2) mPanGestureDetector.SetMaximumTouchesRequired(2);
634 mPanGestureDetector.Detected += OnPanGestureDetected;
636 ClippingMode = ClippingModeType.ClipToBoundingBox;
638 //Default Scrolling child
639 ContentContainer = new View()
641 Name = "ContentContainer",
642 WidthSpecification = ScrollingDirection == Direction.Vertical ? LayoutParamPolicies.MatchParent : LayoutParamPolicies.WrapContent,
643 HeightSpecification = ScrollingDirection == Direction.Vertical ? LayoutParamPolicies.WrapContent : LayoutParamPolicies.MatchParent,
645 ContentContainer.Relayout += OnScrollingChildRelayout;
646 propertyNotification = ContentContainer.AddPropertyNotification("position", PropertyCondition.Step(mScrollingEventThreshold));
647 propertyNotification.Notified += OnPropertyChanged;
648 base.Add(ContentContainer);
650 Scrollbar = new Scrollbar();
652 //Show vertical shadow on the top (or bottom) of the scrollable when panning down (or up).
653 topOverShootingShadowView = new View
655 BackgroundImage = FrameworkInformation.ResourcePath + "nui_component_default_scroll_over_shooting_top.png",
658 PositionUsesPivotPoint = true,
659 ParentOrigin = NUI.ParentOrigin.TopCenter,
660 PivotPoint = NUI.PivotPoint.TopCenter,
662 bottomOverShootingShadowView = new View
664 BackgroundImage = FrameworkInformation.ResourcePath + "nui_component_default_scroll_over_shooting_bottom.png",
667 PositionUsesPivotPoint = true,
668 ParentOrigin = NUI.ParentOrigin.BottomCenter,
669 PivotPoint = NUI.PivotPoint.BottomCenter,
671 //Show horizontal shadow on the left (or right) of the scrollable when panning down (or up).
672 leftOverShootingShadowView = new View
674 BackgroundImage = FrameworkInformation.ResourcePath + "nui_component_default_scroll_over_shooting_left.png",
677 PositionUsesPivotPoint = true,
678 ParentOrigin = NUI.ParentOrigin.CenterLeft,
679 PivotPoint = NUI.PivotPoint.CenterLeft,
681 rightOverShootingShadowView = new View
683 BackgroundImage = FrameworkInformation.ResourcePath + "nui_component_default_scroll_over_shooting_right.png",
686 PositionUsesPivotPoint = true,
687 ParentOrigin = NUI.ParentOrigin.CenterRight,
688 PivotPoint = NUI.PivotPoint.CenterRight,
691 AccessibilityManager.Instance.SetAccessibilityAttribute(this, AccessibilityManager.AccessibilityAttribute.Trait, "ScrollableBase");
694 private bool OnInterruptTouchingChildTouched(object source, View.TouchEventArgs args)
696 if (args.Touch.GetState(0) == PointStateType.Down)
698 if (scrolling && !SnapToPage)
706 private void OnPropertyChanged(object source, PropertyNotification.NotifyEventArgs args)
712 /// Called after a child has been added to the owning view.
714 /// <param name="view">The child which has been added.</param>
715 /// <since_tizen> 8 </since_tizen>
716 public override void Add(View view)
718 ContentContainer.Add(view);
722 /// Called after a child has been removed from the owning view.
724 /// <param name="view">The child which has been removed.</param>
725 /// <since_tizen> 8 </since_tizen>
726 public override void Remove(View view)
728 if (SnapToPage && CurrentPage == Children.IndexOf(view) && CurrentPage == Children.Count - 1)
730 // Target View is current page and also last child.
731 // CurrentPage should be changed to previous page.
732 CurrentPage = Math.Max(0, CurrentPage - 1);
733 ScrollToIndex(CurrentPage);
736 ContentContainer.Remove(view);
739 private void OnScrollingChildRelayout(object source, EventArgs args)
741 // Size is changed. Calculate maxScrollDistance.
742 bool isSizeChanged = previousContainerSize.Width != ContentContainer.Size.Width || previousContainerSize.Height != ContentContainer.Size.Height ||
743 previousSize.Width != Size.Width || previousSize.Height != Size.Height;
747 maxScrollDistance = CalculateMaximumScrollDistance();
748 if (!ReviseContainerPositionIfNeed())
754 previousContainerSize = ContentContainer.Size;
758 private bool ReviseContainerPositionIfNeed()
760 bool isHorizontal = ScrollingDirection == Direction.Horizontal;
761 float currentPosition = isHorizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y;
763 if (Math.Abs(currentPosition) > maxScrollDistance)
766 var targetPosition = BoundScrollPosition(-maxScrollDistance);
767 if (isHorizontal) ContentContainer.PositionX = targetPosition;
768 else ContentContainer.PositionY = targetPosition;
776 /// The composition of a Scrollbar can vary depending on how you use ScrollableBase.
777 /// Set the composition that will go into the ScrollableBase according to your ScrollableBase.
779 /// <since_tizen> 8 </since_tizen>
780 [EditorBrowsable(EditorBrowsableState.Never)]
781 protected virtual void SetScrollbar()
785 bool isHorizontal = ScrollingDirection == Direction.Horizontal;
786 float contentLength = isHorizontal ? ContentContainer.Size.Width : ContentContainer.Size.Height;
787 float viewportLength = isHorizontal ? Size.Width : Size.Height;
788 float currentPosition = isHorizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y;
789 Scrollbar.Initialize(contentLength, viewportLength, -currentPosition, isHorizontal);
793 /// Update scrollbar position and size.
794 [EditorBrowsable(EditorBrowsableState.Never)]
795 protected virtual void UpdateScrollbar()
799 bool isHorizontal = ScrollingDirection == Direction.Horizontal;
800 float contentLength = isHorizontal ? ContentContainer.Size.Width : ContentContainer.Size.Height;
801 float viewportLength = isHorizontal ? Size.Width : Size.Height;
802 float currentPosition = isHorizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y;
803 Scrollbar.Update(contentLength, viewportLength, -currentPosition);
808 /// Scrolls to the item at the specified index.
810 /// <param name="index">Index of item.</param>
811 /// <since_tizen> 8 </since_tizen>
812 public void ScrollToIndex(int index)
814 if (ContentContainer.ChildCount - 1 < index || index < 0)
824 float targetPosition = Math.Min(ScrollingDirection == Direction.Vertical ? Children[index].Position.Y : Children[index].Position.X, maxScrollDistance);
825 AnimateChildTo(ScrollDuration, -targetPosition);
828 private void OnScrollDragStarted()
830 ScrollEventArgs eventArgs = new ScrollEventArgs(ContentContainer.CurrentPosition);
831 ScrollDragStarted?.Invoke(this, eventArgs);
834 private void OnScrollDragEnded()
836 ScrollEventArgs eventArgs = new ScrollEventArgs(ContentContainer.CurrentPosition);
837 ScrollDragEnded?.Invoke(this, eventArgs);
840 private void OnScrollAnimationStarted()
842 ScrollEventArgs eventArgs = new ScrollEventArgs(ContentContainer.CurrentPosition);
843 ScrollAnimationStarted?.Invoke(this, eventArgs);
846 private void OnScrollAnimationEnded()
849 this.InterceptTouchEvent -= OnInterruptTouchingChildTouched;
851 ScrollEventArgs eventArgs = new ScrollEventArgs(ContentContainer.CurrentPosition);
852 ScrollAnimationEnded?.Invoke(this, eventArgs);
855 private void OnScroll()
857 ScrollEventArgs eventArgs = new ScrollEventArgs(ContentContainer.CurrentPosition);
858 Scrolling?.Invoke(this, eventArgs);
860 bool isHorizontal = ScrollingDirection == Direction.Horizontal;
861 float contentLength = isHorizontal ? ContentContainer.Size.Width : ContentContainer.Size.Height;
862 float currentPosition = isHorizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y;
864 scrollBar?.Update(contentLength, Math.Abs(currentPosition));
865 CheckPreReachedTargetPosition();
868 private void CheckPreReachedTargetPosition()
870 // Check whether we reached pre-reached target position
872 ContentContainer.CurrentPosition.Y <= finalTargetPosition + NoticeAnimationEndBeforePosition &&
873 ContentContainer.CurrentPosition.Y >= finalTargetPosition - NoticeAnimationEndBeforePosition)
876 readyToNotice = false;
877 OnPreReachedTargetPosition(finalTargetPosition);
882 /// This helps developer who wants to know before scroll is reaching target position.
884 /// <param name="targetPosition">Index of item.</param>
885 /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
886 [EditorBrowsable(EditorBrowsableState.Never)]
887 protected virtual void OnPreReachedTargetPosition(float targetPosition)
892 private void StopScroll()
894 if (scrollAnimation != null)
896 if (scrollAnimation.State == Animation.States.Playing)
898 Debug.WriteLineIf(LayoutDebugScrollableBase, "StopScroll Animation Playing");
899 scrollAnimation.Stop(Animation.EndActions.Cancel);
900 OnScrollAnimationEnded();
902 scrollAnimation.Clear();
906 private void AnimateChildTo(int duration, float axisPosition)
908 Debug.WriteLineIf(LayoutDebugScrollableBase, "AnimationTo Animation Duration:" + duration + " Destination:" + axisPosition);
909 finalTargetPosition = axisPosition;
911 StopScroll(); // Will replace previous animation so will stop existing one.
913 if (scrollAnimation == null)
915 scrollAnimation = new Animation();
916 scrollAnimation.Finished += ScrollAnimationFinished;
919 scrollAnimation.Duration = duration;
920 scrollAnimation.DefaultAlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSquare);
921 scrollAnimation.AnimateTo(ContentContainer, (ScrollingDirection == Direction.Horizontal) ? "PositionX" : "PositionY", axisPosition, ScrollAlphaFunction);
923 OnScrollAnimationStarted();
924 scrollAnimation.Play();
928 /// Scroll to specific position with or without animation.
930 /// <param name="position">Destination.</param>
931 /// <param name="animate">Scroll with or without animation</param>
932 /// <since_tizen> 8 </since_tizen>
933 public void ScrollTo(float position, bool animate)
935 float currentPositionX = ContentContainer.CurrentPosition.X != 0 ? ContentContainer.CurrentPosition.X : ContentContainer.Position.X;
936 float currentPositionY = ContentContainer.CurrentPosition.Y != 0 ? ContentContainer.CurrentPosition.Y : ContentContainer.Position.Y;
937 float delta = ScrollingDirection == Direction.Horizontal ? currentPositionX : currentPositionY;
938 // The argument position is the new pan position. So the new position of ScrollableBase becomes (-position).
939 // To move ScrollableBase's position to (-position), it moves by (-position - currentPosition).
940 delta = -position - delta;
942 ScrollBy(delta, animate);
945 private float BoundScrollPosition(float targetPosition)
947 if (ScrollAvailableArea != null)
949 float minScrollPosition = ScrollAvailableArea.X;
950 float maxScrollPosition = ScrollAvailableArea.Y;
952 targetPosition = Math.Min(-minScrollPosition, targetPosition);
953 targetPosition = Math.Max(-maxScrollPosition, targetPosition);
957 targetPosition = Math.Min(0, targetPosition);
958 targetPosition = Math.Max(-maxScrollDistance, targetPosition);
961 return targetPosition;
964 private void ScrollBy(float displacement, bool animate)
966 if (GetChildCount() == 0 || maxScrollDistance < 0)
971 float childCurrentPosition = (ScrollingDirection == Direction.Horizontal) ? ContentContainer.PositionX : ContentContainer.PositionY;
973 Debug.WriteLineIf(LayoutDebugScrollableBase, "ScrollBy childCurrentPosition:" + childCurrentPosition +
974 " displacement:" + displacement,
975 " maxScrollDistance:" + maxScrollDistance);
977 childTargetPosition = childCurrentPosition + displacement; // child current position + gesture displacement
979 Debug.WriteLineIf(LayoutDebugScrollableBase, "ScrollBy currentAxisPosition:" + childCurrentPosition + "childTargetPosition:" + childTargetPosition);
983 // Calculate scroll animation duration
984 float scrollDistance = Math.Abs(displacement);
985 readyToNotice = true;
987 AnimateChildTo(ScrollDuration, BoundScrollPosition(AdjustTargetPositionOfScrollAnimation(BoundScrollPosition(childTargetPosition))));
991 finalTargetPosition = BoundScrollPosition(childTargetPosition);
993 // Set position of scrolling child without an animation
994 if (ScrollingDirection == Direction.Horizontal)
996 ContentContainer.PositionX = finalTargetPosition;
1000 ContentContainer.PositionY = finalTargetPosition;
1006 /// you can override it to clean-up your own resources.
1008 /// <param name="type">DisposeTypes</param>
1009 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1010 [EditorBrowsable(EditorBrowsableState.Never)]
1011 protected override void Dispose(DisposeTypes type)
1018 if (type == DisposeTypes.Explicit)
1020 StopOverShootingShadowAnimation();
1023 if (mPanGestureDetector != null)
1025 mPanGestureDetector.Detected -= OnPanGestureDetected;
1026 mPanGestureDetector.Dispose();
1027 mPanGestureDetector = null;
1030 propertyNotification.Dispose();
1035 private float CalculateMaximumScrollDistance()
1037 float scrollingChildLength = 0;
1038 float scrollerLength = 0;
1039 if (ScrollingDirection == Direction.Horizontal)
1041 Debug.WriteLineIf(LayoutDebugScrollableBase, "Horizontal");
1043 scrollingChildLength = ContentContainer.Size.Width;
1044 scrollerLength = Size.Width;
1048 Debug.WriteLineIf(LayoutDebugScrollableBase, "Vertical");
1049 scrollingChildLength = ContentContainer.Size.Height;
1050 scrollerLength = Size.Height;
1053 Debug.WriteLineIf(LayoutDebugScrollableBase, "ScrollBy maxScrollDistance:" + (scrollingChildLength - scrollerLength) +
1054 " parent length:" + scrollerLength +
1055 " scrolling child length:" + scrollingChildLength);
1057 return Math.Max(scrollingChildLength - scrollerLength, 0);
1060 private void PageSnap(float velocity)
1064 Debug.WriteLineIf(LayoutDebugScrollableBase, "PageSnap with pan candidate totalDisplacement:" + totalDisplacementForPan +
1065 " currentPage[" + CurrentPage + "]");
1067 //Increment current page if total displacement enough to warrant a page change.
1068 if (Math.Abs(totalDisplacementForPan) > (mPageWidth * ratioOfScreenWidthToCompleteScroll))
1070 if (totalDisplacementForPan < 0)
1072 CurrentPage = Math.Min(Math.Max(Children.Count - 1, 0), ++CurrentPage);
1076 CurrentPage = Math.Max(0, --CurrentPage);
1079 else if (Math.Abs(velocity) > PageFlickThreshold)
1083 CurrentPage = Math.Min(Math.Max(Children.Count - 1, 0), ++CurrentPage);
1087 CurrentPage = Math.Max(0, --CurrentPage);
1091 // Animate to new page or reposition to current page
1092 if (ScrollingDirection == Direction.Horizontal)
1093 destination = -(Children[CurrentPage].Position.X + Children[CurrentPage].CurrentSize.Width / 2 - CurrentSize.Width / 2); // set to middle of current page
1095 destination = -(Children[CurrentPage].Position.Y + Children[CurrentPage].CurrentSize.Height / 2 - CurrentSize.Height / 2);
1097 AnimateChildTo(ScrollDuration, destination);
1101 /// Enable/Disable overshooting effect. default is disabled.
1103 [EditorBrowsable(EditorBrowsableState.Never)]
1104 public bool EnableOverShootingEffect { get; set; } = false;
1106 private void AttachOverShootingShadowView()
1108 if (!EnableOverShootingEffect)
1111 // stop animation if necessary.
1112 StopOverShootingShadowAnimation();
1114 if (ScrollingDirection == Direction.Horizontal)
1116 base.Add(leftOverShootingShadowView);
1117 base.Add(rightOverShootingShadowView);
1119 leftOverShootingShadowView.Size = new Size(0.0f, SizeHeight);
1120 leftOverShootingShadowView.Opacity = 1.0f;
1121 leftOverShootingShadowView.RaiseToTop();
1123 rightOverShootingShadowView.Size = new Size(0.0f, SizeHeight);
1124 rightOverShootingShadowView.Opacity = 1.0f;
1125 rightOverShootingShadowView.RaiseToTop();
1129 base.Add(topOverShootingShadowView);
1130 base.Add(bottomOverShootingShadowView);
1132 topOverShootingShadowView.Size = new Size(SizeWidth, 0.0f);
1133 topOverShootingShadowView.Opacity = 1.0f;
1134 topOverShootingShadowView.RaiseToTop();
1136 bottomOverShootingShadowView.Size = new Size(SizeWidth, 0.0f);
1137 bottomOverShootingShadowView.Opacity = 1.0f;
1138 bottomOverShootingShadowView.RaiseToTop();
1141 // at the beginning, height or width of overshooting shadow is 0, so it is invisible.
1142 isOverShootingShadowShown = false;
1145 private void DragOverShootingShadow(float totalPanDisplacement, float panDisplacement)
1147 if (!EnableOverShootingEffect)
1150 if (totalPanDisplacement > 0) // downwards
1152 // check if reaching at the top / left.
1153 if ((int)finalTargetPosition != 0)
1155 isOverShootingShadowShown = false;
1159 // save start displacement, and re-calculate displacement.
1160 if (!isOverShootingShadowShown)
1162 startShowShadowDisplacement = totalPanDisplacement;
1164 isOverShootingShadowShown = true;
1166 float newDisplacement = (int)totalPanDisplacement < (int)startShowShadowDisplacement ? 0 : totalPanDisplacement - startShowShadowDisplacement;
1168 if (ScrollingDirection == Direction.Horizontal)
1170 // scale limit of height is 60%.
1171 float heightScale = newDisplacement / overShootingShadowScaleHeightLimit;
1172 leftOverShootingShadowView.SizeHeight = heightScale > 0.6f ? SizeHeight * 0.4f : SizeHeight * (1.0f - heightScale);
1174 // scale limit of width is 300%.
1175 leftOverShootingShadowView.SizeWidth = newDisplacement > overShootingShadowScaleHeightLimit ? overShootingShadowScaleHeightLimit : newDisplacement;
1178 ScrollOutOfBoundEventArgs.Direction scrollDirection = panDisplacement > 0 ?
1179 ScrollOutOfBoundEventArgs.Direction.Right : ScrollOutOfBoundEventArgs.Direction.Left;
1180 OnScrollOutOfBound(scrollDirection, totalPanDisplacement);
1184 // scale limit of width is 60%.
1185 float widthScale = newDisplacement / overShootingShadowScaleHeightLimit;
1186 topOverShootingShadowView.SizeWidth = widthScale > 0.6f ? SizeWidth * 0.4f : SizeWidth * (1.0f - widthScale);
1188 // scale limit of height is 300%.
1189 topOverShootingShadowView.SizeHeight = newDisplacement > overShootingShadowScaleHeightLimit ? overShootingShadowScaleHeightLimit : newDisplacement;
1192 ScrollOutOfBoundEventArgs.Direction scrollDirection = panDisplacement > 0 ?
1193 ScrollOutOfBoundEventArgs.Direction.Down : ScrollOutOfBoundEventArgs.Direction.Up;
1194 OnScrollOutOfBound(scrollDirection, totalPanDisplacement);
1197 else if (totalPanDisplacement < 0) // upwards
1199 // check if reaching at the bottom.
1200 if (-(int)finalTargetPosition != (int)maxScrollDistance)
1202 isOverShootingShadowShown = false;
1206 // save start displacement, and re-calculate displacement.
1207 if (!isOverShootingShadowShown)
1209 startShowShadowDisplacement = totalPanDisplacement;
1211 isOverShootingShadowShown = true;
1213 float newDisplacement = (int)startShowShadowDisplacement < (int)totalPanDisplacement ? 0 : startShowShadowDisplacement - totalPanDisplacement;
1215 if (ScrollingDirection == Direction.Horizontal)
1217 // scale limit of height is 60%.
1218 float heightScale = newDisplacement / overShootingShadowScaleHeightLimit;
1219 rightOverShootingShadowView.SizeHeight = heightScale > 0.6f ? SizeHeight * 0.4f : SizeHeight * (1.0f - heightScale);
1221 // scale limit of width is 300%.
1222 rightOverShootingShadowView.SizeWidth = newDisplacement > overShootingShadowScaleHeightLimit ? overShootingShadowScaleHeightLimit : newDisplacement;
1225 ScrollOutOfBoundEventArgs.Direction scrollDirection = panDisplacement > 0 ?
1226 ScrollOutOfBoundEventArgs.Direction.Right : ScrollOutOfBoundEventArgs.Direction.Left;
1227 OnScrollOutOfBound(scrollDirection, totalPanDisplacement);
1231 // scale limit of width is 60%.
1232 float widthScale = newDisplacement / overShootingShadowScaleHeightLimit;
1233 bottomOverShootingShadowView.SizeWidth = widthScale > 0.6f ? SizeWidth * 0.4f : SizeWidth * (1.0f - widthScale);
1235 // scale limit of height is 300%.
1236 bottomOverShootingShadowView.SizeHeight = newDisplacement > overShootingShadowScaleHeightLimit ? overShootingShadowScaleHeightLimit : newDisplacement;
1239 ScrollOutOfBoundEventArgs.Direction scrollDirection = panDisplacement > 0 ?
1240 ScrollOutOfBoundEventArgs.Direction.Down : ScrollOutOfBoundEventArgs.Direction.Up;
1241 OnScrollOutOfBound(scrollDirection, totalPanDisplacement);
1246 // if total displacement is 0, shadow would become invisible.
1247 isOverShootingShadowShown = false;
1251 private void PlayOverShootingShadowAnimation()
1253 if (!EnableOverShootingEffect)
1256 // stop animation if necessary.
1257 StopOverShootingShadowAnimation();
1259 if (overShootingShadowAnimation == null)
1261 overShootingShadowAnimation = new Animation(overShootingShadowAnimationDuration);
1262 overShootingShadowAnimation.Finished += OnOverShootingShadowAnimationFinished;
1265 if (ScrollingDirection == Direction.Horizontal)
1267 View targetView = totalDisplacementForPan < 0 ? rightOverShootingShadowView : leftOverShootingShadowView;
1268 overShootingShadowAnimation.AnimateTo(targetView, "SizeHeight", SizeHeight);
1269 overShootingShadowAnimation.AnimateTo(targetView, "SizeWidth", 0.0f);
1270 overShootingShadowAnimation.AnimateTo(targetView, "Opacity", 0.0f);
1274 View targetView = totalDisplacementForPan < 0 ? bottomOverShootingShadowView : topOverShootingShadowView;
1275 overShootingShadowAnimation.AnimateTo(targetView, "SizeWidth", SizeWidth);
1276 overShootingShadowAnimation.AnimateTo(targetView, "SizeHeight", 0.0f);
1277 overShootingShadowAnimation.AnimateTo(targetView, "Opacity", 0.0f);
1279 overShootingShadowAnimation.Play();
1282 private void StopOverShootingShadowAnimation()
1284 if (overShootingShadowAnimation == null || overShootingShadowAnimation.State != Animation.States.Playing)
1287 overShootingShadowAnimation.Stop(Animation.EndActions.Cancel);
1288 OnOverShootingShadowAnimationFinished(null, null);
1289 overShootingShadowAnimation.Clear();
1292 private void OnOverShootingShadowAnimationFinished(object sender, EventArgs e)
1294 if (ScrollingDirection == Direction.Horizontal)
1296 base.Remove(leftOverShootingShadowView);
1297 base.Remove(rightOverShootingShadowView);
1299 leftOverShootingShadowView.Size = new Size(0.0f, SizeHeight);
1300 rightOverShootingShadowView.Size = new Size(0.0f, SizeHeight);
1304 base.Remove(topOverShootingShadowView);
1305 base.Remove(bottomOverShootingShadowView);
1307 topOverShootingShadowView.Size = new Size(SizeWidth, 0.0f);
1308 bottomOverShootingShadowView.Size = new Size(SizeWidth, 0.0f);
1311 // after animation finished, height/width & opacity of vertical shadow both are 0, so it is invisible.
1312 isOverShootingShadowShown = false;
1315 private void OnScrollOutOfBound(ScrollOutOfBoundEventArgs.Direction direction, float displacement)
1317 ScrollOutOfBoundEventArgs args = new ScrollOutOfBoundEventArgs(direction, displacement);
1318 ScrollOutOfBound?.Invoke(this, args);
1321 private void OnPanGestureDetected(object source, PanGestureDetector.DetectedEventArgs e)
1323 OnPanGesture(e.PanGesture);
1326 private void OnPanGesture(PanGesture panGesture)
1328 if (SnapToPage && scrollAnimation != null && scrollAnimation.State == Animation.States.Playing)
1333 if (panGesture.State == Gesture.StateType.Started)
1335 readyToNotice = false;
1336 //Interrupt touching when panning is started
1337 this.InterceptTouchEvent += OnInterruptTouchingChildTouched;
1338 AttachOverShootingShadowView();
1339 Debug.WriteLineIf(LayoutDebugScrollableBase, "Gesture Start");
1340 if (scrolling && !SnapToPage)
1344 totalDisplacementForPan = 0.0f;
1345 OnScrollDragStarted();
1347 else if (panGesture.State == Gesture.StateType.Continuing)
1349 if (ScrollingDirection == Direction.Horizontal)
1351 // if vertical shadow is shown, does not scroll.
1352 if (!isOverShootingShadowShown)
1354 ScrollBy(panGesture.Displacement.X, false);
1356 totalDisplacementForPan += panGesture.Displacement.X;
1357 DragOverShootingShadow(totalDisplacementForPan, panGesture.Displacement.X);
1361 // if vertical shadow is shown, does not scroll.
1362 if (!isOverShootingShadowShown)
1364 ScrollBy(panGesture.Displacement.Y, false);
1366 totalDisplacementForPan += panGesture.Displacement.Y;
1367 DragOverShootingShadow(totalDisplacementForPan, panGesture.Displacement.Y);
1369 Debug.WriteLineIf(LayoutDebugScrollableBase, "OnPanGestureDetected Continue totalDisplacementForPan:" + totalDisplacementForPan);
1371 else if (panGesture.State == Gesture.StateType.Finished || panGesture.State == Gesture.StateType.Cancelled)
1373 PlayOverShootingShadowAnimation();
1374 OnScrollDragEnded();
1375 StopScroll(); // Will replace previous animation so will stop existing one.
1377 if (scrollAnimation == null)
1379 scrollAnimation = new Animation();
1380 scrollAnimation.Finished += ScrollAnimationFinished;
1383 float panVelocity = (ScrollingDirection == Direction.Horizontal) ? panGesture.Velocity.X : panGesture.Velocity.Y;
1387 PageSnap(panVelocity);
1391 if (panVelocity == 0)
1393 float currentScrollPosition = (ScrollingDirection == Direction.Horizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y);
1394 scrollAnimation.DefaultAlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear);
1395 scrollAnimation.Duration = 0;
1396 scrollAnimation.AnimateTo(ContentContainer, (ScrollingDirection == Direction.Horizontal) ? "PositionX" : "PositionY", currentScrollPosition);
1397 scrollAnimation.Play();
1401 Decelerating(panVelocity, scrollAnimation);
1405 totalDisplacementForPan = 0;
1407 readyToNotice = true;
1408 OnScrollAnimationStarted();
1412 internal void BaseRemove(View view)
1417 internal override bool OnAccessibilityPan(PanGesture gestures)
1419 if (SnapToPage && scrollAnimation != null && scrollAnimation.State == Animation.States.Playing)
1424 OnPanGesture(gestures);
1428 private float CustomScrollAlphaFunction(float progress)
1430 if (panAnimationDelta == 0)
1436 // Parameter "progress" is normalized value. We need to multiply target duration to calculate distance.
1437 // Can get real distance using equation of deceleration (check Decelerating function)
1438 // After get real distance, normalize it
1439 float realDuration = progress * panAnimationDuration;
1440 float realDistance = velocityOfLastPan * ((float)Math.Pow(decelerationRate, realDuration) - 1) / logValueOfDeceleration;
1441 float result = Math.Min(realDistance / Math.Abs(panAnimationDelta), 1.0f);
1447 /// you can override it to custom your decelerating
1449 /// <param name="velocity">Velocity of current pan.</param>
1450 /// <param name="animation">Scroll animation.</param>
1451 [EditorBrowsable(EditorBrowsableState.Never)]
1452 protected virtual void Decelerating(float velocity, Animation animation)
1454 // Decelerating using deceleration equation ===========
1456 // V : velocity (pixel per millisecond)
1457 // V0 : initial velocity
1458 // d : deceleration rate,
1460 // X : final position after decelerating
1461 // log : natural logarithm
1463 // V(t) = V0 * d pow t;
1464 // X(t) = V0 * (d pow t - 1) / log d; <-- Integrate the velocity function
1465 // X(∞) = V0 * d / (1 - d); <-- Result using infinite T can be final position because T is tending to infinity.
1467 // Because of final T is tending to infinity, we should use threshold value to finish.
1468 // Final T = log(-threshold * log d / |V0| ) / log d;
1470 velocityOfLastPan = Math.Abs(velocity);
1472 float currentScrollPosition = -(ScrollingDirection == Direction.Horizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y);
1473 panAnimationDelta = (velocityOfLastPan * decelerationRate) / (1 - decelerationRate);
1474 panAnimationDelta = velocity > 0 ? -panAnimationDelta : panAnimationDelta;
1476 float destination = -(panAnimationDelta + currentScrollPosition);
1477 float adjustDestination = AdjustTargetPositionOfScrollAnimation(destination);
1478 float maxPosition = ScrollAvailableArea != null ? ScrollAvailableArea.Y : maxScrollDistance;
1479 float minPosition = ScrollAvailableArea != null ? ScrollAvailableArea.X : 0;
1481 if (destination < -maxPosition || destination > minPosition)
1483 panAnimationDelta = velocity > 0 ? (currentScrollPosition - minPosition) : (maxPosition - currentScrollPosition);
1484 destination = velocity > 0 ? minPosition : -maxPosition;
1486 if (panAnimationDelta == 0)
1488 panAnimationDuration = 0.0f;
1492 panAnimationDuration = (float)Math.Log((panAnimationDelta * logValueOfDeceleration / velocityOfLastPan + 1), decelerationRate);
1495 Debug.WriteLineIf(LayoutDebugScrollableBase, "\n" +
1496 "OverRange======================= \n" +
1497 "[decelerationRate] " + decelerationRate + "\n" +
1498 "[logValueOfDeceleration] " + logValueOfDeceleration + "\n" +
1499 "[Velocity] " + velocityOfLastPan + "\n" +
1500 "[CurrentPosition] " + currentScrollPosition + "\n" +
1501 "[CandidateDelta] " + panAnimationDelta + "\n" +
1502 "[Destination] " + destination + "\n" +
1503 "[Duration] " + panAnimationDuration + "\n" +
1504 "================================ \n"
1509 panAnimationDuration = (float)Math.Log(-DecelerationThreshold * logValueOfDeceleration / velocityOfLastPan) / logValueOfDeceleration;
1511 if (adjustDestination != destination)
1513 destination = adjustDestination;
1514 panAnimationDelta = destination + currentScrollPosition;
1515 velocityOfLastPan = Math.Abs(panAnimationDelta * logValueOfDeceleration / ((float)Math.Pow(decelerationRate, panAnimationDuration) - 1));
1516 panAnimationDuration = (float)Math.Log(-DecelerationThreshold * logValueOfDeceleration / velocityOfLastPan) / logValueOfDeceleration;
1519 Debug.WriteLineIf(LayoutDebugScrollableBase, "\n" +
1520 "================================ \n" +
1521 "[decelerationRate] " + decelerationRate + "\n" +
1522 "[logValueOfDeceleration] " + logValueOfDeceleration + "\n" +
1523 "[Velocity] " + velocityOfLastPan + "\n" +
1524 "[CurrentPosition] " + currentScrollPosition + "\n" +
1525 "[CandidateDelta] " + panAnimationDelta + "\n" +
1526 "[Destination] " + destination + "\n" +
1527 "[Duration] " + panAnimationDuration + "\n" +
1528 "================================ \n"
1532 finalTargetPosition = destination;
1534 customScrollAlphaFunction = new UserAlphaFunctionDelegate(CustomScrollAlphaFunction);
1535 animation.DefaultAlphaFunction = new AlphaFunction(customScrollAlphaFunction);
1536 GC.KeepAlive(customScrollAlphaFunction);
1537 animation.Duration = (int)panAnimationDuration;
1538 animation.AnimateTo(ContentContainer, (ScrollingDirection == Direction.Horizontal) ? "PositionX" : "PositionY", destination);
1542 private void ScrollAnimationFinished(object sender, EventArgs e)
1544 OnScrollAnimationEnded();
1548 /// Adjust scrolling position by own scrolling rules.
1549 /// Override this function when developer wants to change destination of flicking.(e.g. always snap to center of item)
1551 /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
1552 [EditorBrowsable(EditorBrowsableState.Never)]
1553 protected virtual float AdjustTargetPositionOfScrollAnimation(float position)
1559 /// Scroll position given to ScrollTo.
1560 /// This is the position in the opposite direction to the position of ContentContainer.
1562 /// <since_tizen> 8 </since_tizen>
1563 public Position ScrollPosition
1567 return new Position(-ContentContainer.Position);
1572 /// Current scroll position in the middle of ScrollTo animation.
1573 /// This is the position in the opposite direction to the current position of ContentContainer.
1575 /// <since_tizen> 8 </since_tizen>
1576 public Position ScrollCurrentPosition
1580 return new Position(-ContentContainer.CurrentPosition);
1585 /// Remove all children in ContentContainer.
1587 /// <param name="dispose">If true, removed child is disposed.</param>
1588 [EditorBrowsable(EditorBrowsableState.Never)]
1589 public void RemoveAllChildren(bool dispose = false)
1591 RecursiveRemoveChildren(ContentContainer, dispose);
1594 private void RecursiveRemoveChildren(View parent, bool dispose)
1600 int maxChild = (int)parent.GetChildCount();
1601 for (int i = maxChild - 1; i >= 0; --i)
1603 View child = parent.GetChildAt((uint)i);
1608 RecursiveRemoveChildren(child, dispose);
1609 parent.Remove(child);