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;
36 /// Default constructor.
38 /// <param name="position">Current scroll position</param>
39 /// <since_tizen> 8 </since_tizen>
40 public ScrollEventArgs(Position position)
42 this.position = position;
46 /// Current position of ContentContainer.
48 /// <since_tizen> 8 </since_tizen>
49 public Position Position
59 /// ScrollOutofBoundEventArgs is to record scroll out-of-bound event arguments which will be sent to user.
61 [EditorBrowsable(EditorBrowsableState.Never)]
62 public class ScrollOutOfBoundEventArgs : EventArgs
65 /// The direction to be touched.
67 [EditorBrowsable(EditorBrowsableState.Never)]
73 [EditorBrowsable(EditorBrowsableState.Never)]
79 [EditorBrowsable(EditorBrowsableState.Never)]
85 [EditorBrowsable(EditorBrowsableState.Never)]
91 [EditorBrowsable(EditorBrowsableState.Never)]
98 /// <param name="direction">Current pan direction</param>
99 /// <param name="displacement">Current total displacement</param>
100 [EditorBrowsable(EditorBrowsableState.Never)]
101 public ScrollOutOfBoundEventArgs(Direction direction, float displacement)
103 PanDirection = direction;
104 Displacement = displacement;
108 /// Current pan direction of ContentContainer.
110 [EditorBrowsable(EditorBrowsableState.Never)]
111 public Direction PanDirection
117 /// Current total displacement of ContentContainer.
118 /// if its value is greater than 0, it is at the top/left;
119 /// if less than 0, it is at the bottom/right.
121 [EditorBrowsable(EditorBrowsableState.Never)]
122 public float Displacement
129 /// This class provides a View that can scroll a single View with a layout. This View can be a nest of Views.
131 /// <since_tizen> 8 </since_tizen>
132 public class ScrollableBase : Control
134 static bool LayoutDebugScrollableBase = false; // Debug flag
135 private Direction mScrollingDirection = Direction.Vertical;
136 private bool mScrollEnabled = true;
137 private int mScrollDuration = 125;
138 private int mPageWidth = 0;
139 private float mPageFlickThreshold = 0.4f;
140 private float mScrollingEventThreshold = 0.001f;
142 private class ScrollableBaseCustomLayout : AbsoluteLayout
144 protected override void OnMeasure(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec)
146 MeasuredSize.StateType childWidthState = MeasuredSize.StateType.MeasuredSizeOK;
147 MeasuredSize.StateType childHeightState = MeasuredSize.StateType.MeasuredSizeOK;
149 Direction scrollingDirection = Direction.Vertical;
150 ScrollableBase scrollableBase = this.Owner as ScrollableBase;
151 if (scrollableBase != null)
153 scrollingDirection = scrollableBase.ScrollingDirection;
156 float totalWidth = 0.0f;
157 float totalHeight = 0.0f;
159 // measure child, should be a single scrolling child
160 foreach (LayoutItem childLayout in LayoutChildren)
162 if (childLayout != null && childLayout.Owner.Name == "ContentContainer")
165 // Use an Unspecified MeasureSpecification mode so scrolling child is not restricted to it's parents size in Height (for vertical scrolling)
166 // or Width for horizontal scrolling
167 if (scrollingDirection == Direction.Vertical)
169 MeasureSpecification unrestrictedMeasureSpec = new MeasureSpecification(heightMeasureSpec.Size, MeasureSpecification.ModeType.Unspecified);
170 MeasureChildWithMargins(childLayout, widthMeasureSpec, new LayoutLength(0), unrestrictedMeasureSpec, new LayoutLength(0)); // Height unrestricted by parent
174 MeasureSpecification unrestrictedMeasureSpec = new MeasureSpecification(widthMeasureSpec.Size, MeasureSpecification.ModeType.Unspecified);
175 MeasureChildWithMargins(childLayout, unrestrictedMeasureSpec, new LayoutLength(0), heightMeasureSpec, new LayoutLength(0)); // Width unrestricted by parent
178 totalWidth = (childLayout.MeasuredWidth.Size + (childLayout.Padding.Start + childLayout.Padding.End)).AsDecimal();
179 totalHeight = (childLayout.MeasuredHeight.Size + (childLayout.Padding.Top + childLayout.Padding.Bottom)).AsDecimal();
181 if (childLayout.MeasuredWidth.State == MeasuredSize.StateType.MeasuredSizeTooSmall)
183 childWidthState = MeasuredSize.StateType.MeasuredSizeTooSmall;
185 if (childLayout.MeasuredHeight.State == MeasuredSize.StateType.MeasuredSizeTooSmall)
187 childHeightState = MeasuredSize.StateType.MeasuredSizeTooSmall;
192 MeasuredSize widthSizeAndState = ResolveSizeAndState(new LayoutLength(totalWidth), widthMeasureSpec, MeasuredSize.StateType.MeasuredSizeOK);
193 MeasuredSize heightSizeAndState = ResolveSizeAndState(new LayoutLength(totalHeight), heightMeasureSpec, MeasuredSize.StateType.MeasuredSizeOK);
194 totalWidth = widthSizeAndState.Size.AsDecimal();
195 totalHeight = heightSizeAndState.Size.AsDecimal();
197 // Ensure layout respects it's given minimum size
198 totalWidth = Math.Max(totalWidth, SuggestedMinimumWidth.AsDecimal());
199 totalHeight = Math.Max(totalHeight, SuggestedMinimumHeight.AsDecimal());
201 widthSizeAndState.State = childWidthState;
202 heightSizeAndState.State = childHeightState;
204 SetMeasuredDimensions(ResolveSizeAndState(new LayoutLength(totalWidth), widthMeasureSpec, childWidthState),
205 ResolveSizeAndState(new LayoutLength(totalHeight), heightMeasureSpec, childHeightState));
207 // Size of ScrollableBase is changed. Change Page width too.
208 if (scrollableBase != null)
210 scrollableBase.mPageWidth = (int)MeasuredWidth.Size.AsRoundedValue();
211 scrollableBase.OnScrollingChildRelayout(null, null);
214 } // ScrollableBaseCustomLayout
217 /// The direction axis to scroll.
219 /// <since_tizen> 8 </since_tizen>
220 public enum Direction
225 /// <since_tizen> 8 </since_tizen>
231 /// <since_tizen> 8 </since_tizen>
236 /// Scrolling direction mode.
237 /// Default is Vertical scrolling.
239 /// <since_tizen> 8 </since_tizen>
240 public Direction ScrollingDirection
244 return mScrollingDirection;
248 if (value != mScrollingDirection)
250 mScrollingDirection = value;
251 mPanGestureDetector.ClearAngles();
252 mPanGestureDetector.AddDirection(value == Direction.Horizontal ?
253 PanGestureDetector.DirectionHorizontal : PanGestureDetector.DirectionVertical);
255 ContentContainer.WidthSpecification = ScrollingDirection == Direction.Vertical ? LayoutParamPolicies.MatchParent : LayoutParamPolicies.WrapContent;
256 ContentContainer.HeightSpecification = ScrollingDirection == Direction.Vertical ? LayoutParamPolicies.WrapContent : LayoutParamPolicies.MatchParent;
262 /// Enable or disable scrolling.
264 /// <since_tizen> 8 </since_tizen>
265 public bool ScrollEnabled
269 return mScrollEnabled;
273 if (value != mScrollEnabled)
275 mScrollEnabled = value;
278 mPanGestureDetector.Detected += OnPanGestureDetected;
282 mPanGestureDetector.Detected -= OnPanGestureDetected;
289 /// Pages mode, enables moving to the next or return to current page depending on pan displacement.
290 /// Default is false.
292 /// <since_tizen> 8 </since_tizen>
293 public bool SnapToPage { set; get; } = false;
296 /// Get current page.
297 /// Working property with SnapToPage property.
299 /// <since_tizen> 8 </since_tizen>
300 public int CurrentPage { get; private set; } = 0;
303 /// Duration of scroll animation.
304 /// Default value is 125ms.
306 /// <since_tizen> 8 </since_tizen>
307 public int ScrollDuration
311 mScrollDuration = value >= 0 ? value : mScrollDuration;
315 return mScrollDuration;
320 /// Scroll Available area.
322 /// <since_tizen> 8 </since_tizen>
323 public Vector2 ScrollAvailableArea { set; get; }
326 /// An event emitted when user starts dragging ScrollableBase, user can subscribe or unsubscribe to this event handler.<br />
328 /// <since_tizen> 8 </since_tizen>
329 public event EventHandler<ScrollEventArgs> ScrollDragStarted;
332 /// An event emitted when user stops dragging ScrollableBase, user can subscribe or unsubscribe to this event handler.<br />
334 /// <since_tizen> 8 </since_tizen>
335 public event EventHandler<ScrollEventArgs> ScrollDragEnded;
338 /// An event emitted when the scrolling slide animation starts, user can subscribe or unsubscribe to this event handler.<br />
340 /// <since_tizen> 8 </since_tizen>
341 public event EventHandler<ScrollEventArgs> ScrollAnimationStarted;
344 /// An event emitted when the scrolling slide animation ends, user can subscribe or unsubscribe to this event handler.<br />
346 /// <since_tizen> 8 </since_tizen>
347 public event EventHandler<ScrollEventArgs> ScrollAnimationEnded;
350 /// An event emitted when scrolling, user can subscribe or unsubscribe to this event handler.<br />
352 /// <since_tizen> 8 </since_tizen>
353 public event EventHandler<ScrollEventArgs> Scrolling;
356 /// An event emitted when scrolling out of bound, user can subscribe or unsubscribe to this event handler.<br />
358 [EditorBrowsable(EditorBrowsableState.Never)]
359 public event EventHandler<ScrollOutOfBoundEventArgs> ScrollOutOfBound;
362 /// Scrollbar for ScrollableBase.
364 /// <since_tizen> 8 </since_tizen>
365 public ScrollbarBase Scrollbar
375 scrollBar.Unparent();
379 if (scrollBar != null)
381 scrollBar.Name = "ScrollBar";
399 /// Always hide Scrollbar.
401 /// <since_tizen> 8 </since_tizen>
402 public bool HideScrollbar
406 return hideScrollbar;
410 hideScrollbar = value;
427 /// Container which has content of ScrollableBase.
429 /// <since_tizen> 8 </since_tizen>
430 public View ContentContainer { get; private set; }
433 /// Set the layout on this View. Replaces any existing Layout.
435 /// <since_tizen> 8 </since_tizen>
436 public new LayoutItem Layout
440 return ContentContainer.Layout;
444 ContentContainer.Layout = value;
449 /// List of children of Container.
451 /// <since_tizen> 8 </since_tizen>
452 public new List<View> Children
456 return ContentContainer.Children;
461 /// Deceleration rate of scrolling by finger.
462 /// Rate should be bigger than 0 and smaller than 1.
463 /// Default value is 0.998f;
465 /// <since_tizen> 8 </since_tizen>
466 public float DecelerationRate
470 return decelerationRate;
474 decelerationRate = (value < 1 && value > 0) ? value : decelerationRate;
475 logValueOfDeceleration = (float)Math.Log(value);
480 /// Threashold not to go infinit at the end of scrolling animation.
482 [EditorBrowsable(EditorBrowsableState.Never)]
483 public float DecelerationThreshold { get; set; } = 0.1f;
486 /// Scrolling event will be thrown when this amount of scroll position is changed.
487 /// If this threshold becomes smaller, the tracking detail increases but the scrolling range that can be tracked becomes smaller.
488 /// If large sized ContentContainer is required, please use larger threshold value.
489 /// Default ScrollingEventThreshold value is 0.001f.
491 [EditorBrowsable(EditorBrowsableState.Never)]
492 public float ScrollingEventThreshold
496 return mScrollingEventThreshold;
500 if (mScrollingEventThreshold != value && value > 0)
502 ContentContainer.RemovePropertyNotification(propertyNotification);
503 propertyNotification = ContentContainer.AddPropertyNotification("position", PropertyCondition.Step(value));
504 propertyNotification.Notified += OnPropertyChanged;
505 mScrollingEventThreshold = value;
511 /// Page will be changed when velocity of panning is over threshold.
512 /// The unit of threshold is pixel per milisec.
514 /// <since_tizen> 8 </since_tizen>
515 public float PageFlickThreshold
519 return mPageFlickThreshold;
523 mPageFlickThreshold = value >= 0f ? value : mPageFlickThreshold;
528 /// Padding for the ScrollableBase
530 [EditorBrowsable(EditorBrowsableState.Never)]
531 public Extents Padding
535 return ContentContainer.Padding;
539 ContentContainer.Padding = value;
544 /// Alphafunction for scroll animation.
546 [EditorBrowsable(EditorBrowsableState.Never)]
547 public AlphaFunction ScrollAlphaFunction { get; set; } = new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear);
549 private bool hideScrollbar = true;
550 private float maxScrollDistance;
551 private float childTargetPosition = 0.0f;
552 private PanGestureDetector mPanGestureDetector;
553 private View mInterruptTouchingChild;
554 private ScrollbarBase scrollBar;
555 private bool scrolling = false;
556 private float ratioOfScreenWidthToCompleteScroll = 0.5f;
557 private float totalDisplacementForPan = 0.0f;
558 private Size previousContainerSize = new Size();
559 private Size previousSize = new Size();
560 private PropertyNotification propertyNotification;
561 private float noticeAnimationEndBeforePosition = 0.0f;
562 private bool readyToNotice = false;
565 /// Notice before animation is finished.
567 [EditorBrowsable(EditorBrowsableState.Never)]
568 // Let's consider more whether this needs to be set as protected.
569 public float NoticeAnimationEndBeforePosition
571 get => noticeAnimationEndBeforePosition;
572 set => noticeAnimationEndBeforePosition = value;
575 // Let's consider more whether this needs to be set as protected.
576 private float finalTargetPosition;
578 private Animation scrollAnimation;
579 // Declare user alpha function delegate
580 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
581 private delegate float UserAlphaFunctionDelegate(float progress);
582 private UserAlphaFunctionDelegate customScrollAlphaFunction;
583 private float velocityOfLastPan = 0.0f;
584 private float panAnimationDuration = 0.0f;
585 private float panAnimationDelta = 0.0f;
586 private float logValueOfDeceleration = 0.0f;
587 private float decelerationRate = 0.0f;
589 private View topOverShootingShadowView;
590 private View bottomOverShootingShadowView;
591 private View leftOverShootingShadowView;
592 private View rightOverShootingShadowView;
593 private const int overShootingShadowScaleHeightLimit = 64 * 3;
594 private const int overShootingShadowAnimationDuration = 300;
595 private Animation overShootingShadowAnimation;
596 private bool isOverShootingShadowShown = false;
597 private float startShowShadowDisplacement;
600 /// Default Constructor
602 /// <since_tizen> 8 </since_tizen>
603 public ScrollableBase() : base()
605 DecelerationRate = 0.998f;
607 base.Layout = new ScrollableBaseCustomLayout();
608 mPanGestureDetector = new PanGestureDetector();
609 mPanGestureDetector.Attach(this);
610 mPanGestureDetector.AddDirection(PanGestureDetector.DirectionVertical);
611 mPanGestureDetector.Detected += OnPanGestureDetected;
613 ClippingMode = ClippingModeType.ClipToBoundingBox;
615 //Default Scrolling child
616 ContentContainer = new View()
618 Name = "ContentContainer",
619 WidthSpecification = ScrollingDirection == Direction.Vertical ? LayoutParamPolicies.MatchParent : LayoutParamPolicies.WrapContent,
620 HeightSpecification = ScrollingDirection == Direction.Vertical ? LayoutParamPolicies.WrapContent : LayoutParamPolicies.MatchParent,
622 ContentContainer.Relayout += OnScrollingChildRelayout;
623 propertyNotification = ContentContainer.AddPropertyNotification("position", PropertyCondition.Step(mScrollingEventThreshold));
624 propertyNotification.Notified += OnPropertyChanged;
625 base.Add(ContentContainer);
627 //Interrupt touching when panning is started
628 mInterruptTouchingChild = new View()
630 Size = new Size(Window.Instance.WindowSize),
631 BackgroundColor = Color.Transparent,
633 mInterruptTouchingChild.TouchEvent += OnIterruptTouchingChildTouched;
634 Scrollbar = new Scrollbar();
636 //Show vertical shadow on the top (or bottom) of the scrollable when panning down (or up).
637 topOverShootingShadowView = new View
639 BackgroundImage = FrameworkInformation.ResourcePath + "nui_component_default_scroll_over_shooting_top.png",
642 PositionUsesPivotPoint = true,
643 ParentOrigin = NUI.ParentOrigin.TopCenter,
644 PivotPoint = NUI.PivotPoint.TopCenter,
646 bottomOverShootingShadowView = new View
648 BackgroundImage = FrameworkInformation.ResourcePath + "nui_component_default_scroll_over_shooting_bottom.png",
651 PositionUsesPivotPoint = true,
652 ParentOrigin = NUI.ParentOrigin.BottomCenter,
653 PivotPoint = NUI.PivotPoint.BottomCenter,
655 //Show horizontal shadow on the left (or right) of the scrollable when panning down (or up).
656 leftOverShootingShadowView = new View
658 BackgroundImage = FrameworkInformation.ResourcePath + "nui_component_default_scroll_over_shooting_left.png",
661 PositionUsesPivotPoint = true,
662 ParentOrigin = NUI.ParentOrigin.CenterLeft,
663 PivotPoint = NUI.PivotPoint.CenterLeft,
665 rightOverShootingShadowView = new View
667 BackgroundImage = FrameworkInformation.ResourcePath + "nui_component_default_scroll_over_shooting_right.png",
670 PositionUsesPivotPoint = true,
671 ParentOrigin = NUI.ParentOrigin.CenterRight,
672 PivotPoint = NUI.PivotPoint.CenterRight,
675 AccessibilityManager.Instance.SetAccessibilityAttribute(this, AccessibilityManager.AccessibilityAttribute.Trait, "ScrollableBase");
678 private bool OnIterruptTouchingChildTouched(object source, View.TouchEventArgs args)
680 if (args.Touch.GetState(0) == PointStateType.Down)
682 if (scrolling && !SnapToPage)
690 private void OnPropertyChanged(object source, PropertyNotification.NotifyEventArgs args)
696 /// Called after a child has been added to the owning view.
698 /// <param name="view">The child which has been added.</param>
699 /// <since_tizen> 8 </since_tizen>
700 public override void Add(View view)
702 ContentContainer.Add(view);
706 /// Called after a child has been removed from the owning view.
708 /// <param name="view">The child which has been removed.</param>
709 /// <since_tizen> 8 </since_tizen>
710 public override void Remove(View view)
712 if (SnapToPage && CurrentPage == Children.IndexOf(view) && CurrentPage == Children.Count - 1)
714 // Target View is current page and also last child.
715 // CurrentPage should be changed to previous page.
716 CurrentPage = Math.Max(0, CurrentPage - 1);
717 ScrollToIndex(CurrentPage);
720 ContentContainer.Remove(view);
723 private void OnScrollingChildRelayout(object source, EventArgs args)
725 // Size is changed. Calculate maxScrollDistance.
726 bool isSizeChanged = previousContainerSize.Width != ContentContainer.Size.Width || previousContainerSize.Height != ContentContainer.Size.Height ||
727 previousSize.Width != Size.Width || previousSize.Height != Size.Height;
731 maxScrollDistance = CalculateMaximumScrollDistance();
735 previousContainerSize = ContentContainer.Size;
740 /// The composition of a Scrollbar can vary depending on how you use ScrollableBase.
741 /// Set the composition that will go into the ScrollableBase according to your ScrollableBase.
743 /// <since_tizen> 8 </since_tizen>
744 [EditorBrowsable(EditorBrowsableState.Never)]
745 protected virtual void SetScrollbar()
749 bool isHorizontal = ScrollingDirection == Direction.Horizontal;
750 float contentLength = isHorizontal ? ContentContainer.Size.Width : ContentContainer.Size.Height;
751 float viewportLength = isHorizontal ? Size.Width : Size.Height;
752 float currentPosition = isHorizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y;
753 Scrollbar.Initialize(contentLength, viewportLength, currentPosition, isHorizontal);
758 /// Scrolls to the item at the specified index.
760 /// <param name="index">Index of item.</param>
761 /// <since_tizen> 8 </since_tizen>
762 public void ScrollToIndex(int index)
764 if (ContentContainer.ChildCount - 1 < index || index < 0)
774 float targetPosition = Math.Min(ScrollingDirection == Direction.Vertical ? Children[index].Position.Y : Children[index].Position.X, maxScrollDistance);
775 AnimateChildTo(ScrollDuration, -targetPosition);
778 private void OnScrollDragStarted()
780 ScrollEventArgs eventArgs = new ScrollEventArgs(ContentContainer.CurrentPosition);
781 ScrollDragStarted?.Invoke(this, eventArgs);
784 private void OnScrollDragEnded()
786 ScrollEventArgs eventArgs = new ScrollEventArgs(ContentContainer.CurrentPosition);
787 ScrollDragEnded?.Invoke(this, eventArgs);
790 private void OnScrollAnimationStarted()
792 ScrollEventArgs eventArgs = new ScrollEventArgs(ContentContainer.CurrentPosition);
793 ScrollAnimationStarted?.Invoke(this, eventArgs);
796 private void OnScrollAnimationEnded()
799 base.Remove(mInterruptTouchingChild);
801 ScrollEventArgs eventArgs = new ScrollEventArgs(ContentContainer.CurrentPosition);
802 ScrollAnimationEnded?.Invoke(this, eventArgs);
805 private void OnScroll()
807 ScrollEventArgs eventArgs = new ScrollEventArgs(ContentContainer.CurrentPosition);
808 Scrolling?.Invoke(this, eventArgs);
810 bool isHorizontal = ScrollingDirection == Direction.Horizontal;
811 float contentLength = isHorizontal ? ContentContainer.Size.Width : ContentContainer.Size.Height;
812 float currentPosition = isHorizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y;
814 scrollBar?.Update(contentLength, Math.Abs(currentPosition));
815 CheckPreReachedTargetPosition();
818 private void CheckPreReachedTargetPosition()
820 // Check whether we reached pre-reached target position
822 ContentContainer.CurrentPosition.Y <= finalTargetPosition + NoticeAnimationEndBeforePosition &&
823 ContentContainer.CurrentPosition.Y >= finalTargetPosition - NoticeAnimationEndBeforePosition)
826 readyToNotice = false;
827 OnPreReachedTargetPosition(finalTargetPosition);
832 /// This helps developer who wants to know before scroll is reaching target position.
834 /// <param name="targetPosition">Index of item.</param>
835 /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
836 [EditorBrowsable(EditorBrowsableState.Never)]
837 protected virtual void OnPreReachedTargetPosition(float targetPosition)
842 private void StopScroll()
844 if (scrollAnimation != null)
846 if (scrollAnimation.State == Animation.States.Playing)
848 Debug.WriteLineIf(LayoutDebugScrollableBase, "StopScroll Animation Playing");
849 scrollAnimation.Stop(Animation.EndActions.Cancel);
850 OnScrollAnimationEnded();
852 scrollAnimation.Clear();
856 private void AnimateChildTo(int duration, float axisPosition)
858 Debug.WriteLineIf(LayoutDebugScrollableBase, "AnimationTo Animation Duration:" + duration + " Destination:" + axisPosition);
859 finalTargetPosition = axisPosition;
861 StopScroll(); // Will replace previous animation so will stop existing one.
863 if (scrollAnimation == null)
865 scrollAnimation = new Animation();
866 scrollAnimation.Finished += ScrollAnimationFinished;
869 scrollAnimation.Duration = duration;
870 scrollAnimation.DefaultAlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSquare);
871 scrollAnimation.AnimateTo(ContentContainer, (ScrollingDirection == Direction.Horizontal) ? "PositionX" : "PositionY", axisPosition, ScrollAlphaFunction);
873 OnScrollAnimationStarted();
874 scrollAnimation.Play();
878 /// Scroll to specific position with or without animation.
880 /// <param name="position">Destination.</param>
881 /// <param name="animate">Scroll with or without animation</param>
882 /// <since_tizen> 8 </since_tizen>
883 public void ScrollTo(float position, bool animate)
885 float currentPositionX = ContentContainer.CurrentPosition.X != 0 ? ContentContainer.CurrentPosition.X : ContentContainer.Position.X;
886 float currentPositionY = ContentContainer.CurrentPosition.Y != 0 ? ContentContainer.CurrentPosition.Y : ContentContainer.Position.Y;
887 float delta = ScrollingDirection == Direction.Horizontal ? currentPositionX : currentPositionY;
888 // The argument position is the new pan position. So the new position of ScrollableBase becomes (-position).
889 // To move ScrollableBase's position to (-position), it moves by (-position - currentPosition).
890 delta = -position - delta;
892 ScrollBy(delta, animate);
895 private float BoundScrollPosition(float targetPosition)
897 if (ScrollAvailableArea != null)
899 float minScrollPosition = ScrollAvailableArea.X;
900 float maxScrollPosition = ScrollAvailableArea.Y;
902 targetPosition = Math.Min(-minScrollPosition, targetPosition);
903 targetPosition = Math.Max(-maxScrollPosition, targetPosition);
907 targetPosition = Math.Min(0, targetPosition);
908 targetPosition = Math.Max(-maxScrollDistance, targetPosition);
911 return targetPosition;
914 private void ScrollBy(float displacement, bool animate)
916 if (GetChildCount() == 0 || maxScrollDistance < 0)
921 float childCurrentPosition = (ScrollingDirection == Direction.Horizontal) ? ContentContainer.PositionX : ContentContainer.PositionY;
923 Debug.WriteLineIf(LayoutDebugScrollableBase, "ScrollBy childCurrentPosition:" + childCurrentPosition +
924 " displacement:" + displacement,
925 " maxScrollDistance:" + maxScrollDistance);
927 childTargetPosition = childCurrentPosition + displacement; // child current position + gesture displacement
929 Debug.WriteLineIf(LayoutDebugScrollableBase, "ScrollBy currentAxisPosition:" + childCurrentPosition + "childTargetPosition:" + childTargetPosition);
933 // Calculate scroll animaton duration
934 float scrollDistance = Math.Abs(displacement);
935 readyToNotice = true;
937 AnimateChildTo(ScrollDuration, BoundScrollPosition(AdjustTargetPositionOfScrollAnimation(BoundScrollPosition(childTargetPosition))));
941 finalTargetPosition = BoundScrollPosition(childTargetPosition);
943 // Set position of scrolling child without an animation
944 if (ScrollingDirection == Direction.Horizontal)
946 ContentContainer.PositionX = finalTargetPosition;
950 ContentContainer.PositionY = finalTargetPosition;
956 /// you can override it to clean-up your own resources.
958 /// <param name="type">DisposeTypes</param>
959 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
960 [EditorBrowsable(EditorBrowsableState.Never)]
961 protected override void Dispose(DisposeTypes type)
968 if (type == DisposeTypes.Explicit)
970 AccessibilityManager.Instance.DeleteAccessibilityAttribute(this);
971 StopOverShootingShadowAnimation();
974 if (mPanGestureDetector != null)
976 mPanGestureDetector.Detected -= OnPanGestureDetected;
977 mPanGestureDetector.Dispose();
978 mPanGestureDetector = null;
981 propertyNotification.Dispose();
986 private float CalculateMaximumScrollDistance()
988 float scrollingChildLength = 0;
989 float scrollerLength = 0;
990 if (ScrollingDirection == Direction.Horizontal)
992 Debug.WriteLineIf(LayoutDebugScrollableBase, "Horizontal");
994 scrollingChildLength = ContentContainer.Size.Width;
995 scrollerLength = Size.Width;
999 Debug.WriteLineIf(LayoutDebugScrollableBase, "Vertical");
1000 scrollingChildLength = ContentContainer.Size.Height;
1001 scrollerLength = Size.Height;
1004 Debug.WriteLineIf(LayoutDebugScrollableBase, "ScrollBy maxScrollDistance:" + (scrollingChildLength - scrollerLength) +
1005 " parent length:" + scrollerLength +
1006 " scrolling child length:" + scrollingChildLength);
1008 return Math.Max(scrollingChildLength - scrollerLength, 0);
1011 private void PageSnap(float velocity)
1013 Debug.WriteLineIf(LayoutDebugScrollableBase, "PageSnap with pan candidate totalDisplacement:" + totalDisplacementForPan +
1014 " currentPage[" + CurrentPage + "]");
1016 //Increment current page if total displacement enough to warrant a page change.
1017 if (Math.Abs(totalDisplacementForPan) > (mPageWidth * ratioOfScreenWidthToCompleteScroll))
1019 if (totalDisplacementForPan < 0)
1021 CurrentPage = Math.Min(Math.Max(Children.Count - 1, 0), ++CurrentPage);
1025 CurrentPage = Math.Max(0, --CurrentPage);
1028 else if (Math.Abs(velocity) > PageFlickThreshold)
1032 CurrentPage = Math.Min(Math.Max(Children.Count - 1, 0), ++CurrentPage);
1036 CurrentPage = Math.Max(0, --CurrentPage);
1040 // Animate to new page or reposition to current page
1041 float destinationX = -(Children[CurrentPage].Position.X + Children[CurrentPage].CurrentSize.Width / 2 - CurrentSize.Width / 2); // set to middle of current page
1042 Debug.WriteLineIf(LayoutDebugScrollableBase, "Snapping to page[" + CurrentPage + "] to:" + destinationX + " from:" + ContentContainer.PositionX);
1043 AnimateChildTo(ScrollDuration, destinationX);
1047 /// Enable/Disable overshooting effect. default is disabled.
1049 [EditorBrowsable(EditorBrowsableState.Never)]
1050 public bool EnableOverShootingEffect { get; set; } = false;
1052 private void AttachOverShootingShadowView()
1054 if (!EnableOverShootingEffect)
1057 // stop animation if necessary.
1058 StopOverShootingShadowAnimation();
1060 if (ScrollingDirection == Direction.Horizontal)
1062 base.Add(leftOverShootingShadowView);
1063 base.Add(rightOverShootingShadowView);
1065 leftOverShootingShadowView.Size = new Size(0.0f, SizeHeight);
1066 leftOverShootingShadowView.Opacity = 1.0f;
1067 leftOverShootingShadowView.RaiseToTop();
1069 rightOverShootingShadowView.Size = new Size(0.0f, SizeHeight);
1070 rightOverShootingShadowView.Opacity = 1.0f;
1071 rightOverShootingShadowView.RaiseToTop();
1075 base.Add(topOverShootingShadowView);
1076 base.Add(bottomOverShootingShadowView);
1078 topOverShootingShadowView.Size = new Size(SizeWidth, 0.0f);
1079 topOverShootingShadowView.Opacity = 1.0f;
1080 topOverShootingShadowView.RaiseToTop();
1082 bottomOverShootingShadowView.Size = new Size(SizeWidth, 0.0f);
1083 bottomOverShootingShadowView.Opacity = 1.0f;
1084 bottomOverShootingShadowView.RaiseToTop();
1087 // at the beginning, height or width of overshooting shadow is 0, so it is invisible.
1088 isOverShootingShadowShown = false;
1091 private void DragOverShootingShadow(float totalPanDisplacement, float panDisplacement)
1093 if (!EnableOverShootingEffect)
1096 if (totalPanDisplacement > 0) // downwards
1098 // check if reaching at the top / left.
1099 if ((int)finalTargetPosition != 0)
1101 isOverShootingShadowShown = false;
1105 // save start displacement, and re-calculate displacement.
1106 if (!isOverShootingShadowShown)
1108 startShowShadowDisplacement = totalPanDisplacement;
1110 isOverShootingShadowShown = true;
1112 float newDisplacement = (int)totalPanDisplacement < (int)startShowShadowDisplacement ? 0 : totalPanDisplacement - startShowShadowDisplacement;
1114 if (ScrollingDirection == Direction.Horizontal)
1116 // scale limit of height is 60%.
1117 float heightScale = newDisplacement / overShootingShadowScaleHeightLimit;
1118 leftOverShootingShadowView.SizeHeight = heightScale > 0.6f ? SizeHeight * 0.4f : SizeHeight * (1.0f - heightScale);
1120 // scale limit of width is 300%.
1121 leftOverShootingShadowView.SizeWidth = newDisplacement > overShootingShadowScaleHeightLimit ? overShootingShadowScaleHeightLimit : newDisplacement;
1124 ScrollOutOfBoundEventArgs.Direction scrollDirection = panDisplacement > 0 ?
1125 ScrollOutOfBoundEventArgs.Direction.Right : ScrollOutOfBoundEventArgs.Direction.Left;
1126 OnScrollOutOfBound(scrollDirection, totalPanDisplacement);
1130 // scale limit of width is 60%.
1131 float widthScale = newDisplacement / overShootingShadowScaleHeightLimit;
1132 topOverShootingShadowView.SizeWidth = widthScale > 0.6f ? SizeWidth * 0.4f : SizeWidth * (1.0f - widthScale);
1134 // scale limit of height is 300%.
1135 topOverShootingShadowView.SizeHeight = newDisplacement > overShootingShadowScaleHeightLimit ? overShootingShadowScaleHeightLimit : newDisplacement;
1138 ScrollOutOfBoundEventArgs.Direction scrollDirection = panDisplacement > 0 ?
1139 ScrollOutOfBoundEventArgs.Direction.Down : ScrollOutOfBoundEventArgs.Direction.Up;
1140 OnScrollOutOfBound(scrollDirection, totalPanDisplacement);
1143 else if (totalPanDisplacement < 0) // upwards
1145 // check if reaching at the bottom.
1146 if (-(int)finalTargetPosition != (int)maxScrollDistance)
1148 isOverShootingShadowShown = false;
1152 // save start displacement, and re-calculate displacement.
1153 if (!isOverShootingShadowShown)
1155 startShowShadowDisplacement = totalPanDisplacement;
1157 isOverShootingShadowShown = true;
1159 float newDisplacement = (int)startShowShadowDisplacement < (int)totalPanDisplacement ? 0 : startShowShadowDisplacement - totalPanDisplacement;
1161 if (ScrollingDirection == Direction.Horizontal)
1163 // scale limit of height is 60%.
1164 float heightScale = newDisplacement / overShootingShadowScaleHeightLimit;
1165 rightOverShootingShadowView.SizeHeight = heightScale > 0.6f ? SizeHeight * 0.4f : SizeHeight * (1.0f - heightScale);
1167 // scale limit of width is 300%.
1168 rightOverShootingShadowView.SizeWidth = newDisplacement > overShootingShadowScaleHeightLimit ? overShootingShadowScaleHeightLimit : newDisplacement;
1171 ScrollOutOfBoundEventArgs.Direction scrollDirection = panDisplacement > 0 ?
1172 ScrollOutOfBoundEventArgs.Direction.Right : ScrollOutOfBoundEventArgs.Direction.Left;
1173 OnScrollOutOfBound(scrollDirection, totalPanDisplacement);
1177 // scale limit of width is 60%.
1178 float widthScale = newDisplacement / overShootingShadowScaleHeightLimit;
1179 bottomOverShootingShadowView.SizeWidth = widthScale > 0.6f ? SizeWidth * 0.4f : SizeWidth * (1.0f - widthScale);
1181 // scale limit of height is 300%.
1182 bottomOverShootingShadowView.SizeHeight = newDisplacement > overShootingShadowScaleHeightLimit ? overShootingShadowScaleHeightLimit : newDisplacement;
1185 ScrollOutOfBoundEventArgs.Direction scrollDirection = panDisplacement > 0 ?
1186 ScrollOutOfBoundEventArgs.Direction.Down : ScrollOutOfBoundEventArgs.Direction.Up;
1187 OnScrollOutOfBound(scrollDirection, totalPanDisplacement);
1192 // if total displacement is 0, shadow would become invisible.
1193 isOverShootingShadowShown = false;
1197 private void PlayOverShootingShadowAnimation()
1199 if (!EnableOverShootingEffect)
1202 // stop animation if necessary.
1203 StopOverShootingShadowAnimation();
1205 if (overShootingShadowAnimation == null)
1207 overShootingShadowAnimation = new Animation(overShootingShadowAnimationDuration);
1208 overShootingShadowAnimation.Finished += OnOverShootingShadowAnimationFinished;
1211 if (ScrollingDirection == Direction.Horizontal)
1213 View targetView = totalDisplacementForPan < 0 ? rightOverShootingShadowView : leftOverShootingShadowView;
1214 overShootingShadowAnimation.AnimateTo(targetView, "SizeHeight", SizeHeight);
1215 overShootingShadowAnimation.AnimateTo(targetView, "SizeWidth", 0.0f);
1216 overShootingShadowAnimation.AnimateTo(targetView, "Opacity", 0.0f);
1220 View targetView = totalDisplacementForPan < 0 ? bottomOverShootingShadowView : topOverShootingShadowView;
1221 overShootingShadowAnimation.AnimateTo(targetView, "SizeWidth", SizeWidth);
1222 overShootingShadowAnimation.AnimateTo(targetView, "SizeHeight", 0.0f);
1223 overShootingShadowAnimation.AnimateTo(targetView, "Opacity", 0.0f);
1225 overShootingShadowAnimation.Play();
1228 private void StopOverShootingShadowAnimation()
1230 if (overShootingShadowAnimation == null || overShootingShadowAnimation.State != Animation.States.Playing)
1233 overShootingShadowAnimation.Stop(Animation.EndActions.Cancel);
1234 OnOverShootingShadowAnimationFinished(null, null);
1235 overShootingShadowAnimation.Clear();
1238 private void OnOverShootingShadowAnimationFinished(object sender, EventArgs e)
1240 if (ScrollingDirection == Direction.Horizontal)
1242 base.Remove(leftOverShootingShadowView);
1243 base.Remove(rightOverShootingShadowView);
1245 leftOverShootingShadowView.Size = new Size(0.0f, SizeHeight);
1246 rightOverShootingShadowView.Size = new Size(0.0f, SizeHeight);
1250 base.Remove(topOverShootingShadowView);
1251 base.Remove(bottomOverShootingShadowView);
1253 topOverShootingShadowView.Size = new Size(SizeWidth, 0.0f);
1254 bottomOverShootingShadowView.Size = new Size(SizeWidth, 0.0f);
1257 // after animation finished, height/width & opacity of vertical shadow both are 0, so it is invisible.
1258 isOverShootingShadowShown = false;
1261 private void OnScrollOutOfBound(ScrollOutOfBoundEventArgs.Direction direction, float displacement)
1263 ScrollOutOfBoundEventArgs args = new ScrollOutOfBoundEventArgs(direction, displacement);
1264 ScrollOutOfBound?.Invoke(this, args);
1267 private void OnPanGestureDetected(object source, PanGestureDetector.DetectedEventArgs e)
1269 OnPanGesture(e.PanGesture);
1272 private void OnPanGesture(PanGesture panGesture)
1274 if (SnapToPage && scrollAnimation != null && scrollAnimation.State == Animation.States.Playing)
1279 if (panGesture.State == Gesture.StateType.Started)
1281 readyToNotice = false;
1282 base.Add(mInterruptTouchingChild);
1283 AttachOverShootingShadowView();
1284 Debug.WriteLineIf(LayoutDebugScrollableBase, "Gesture Start");
1285 if (scrolling && !SnapToPage)
1289 totalDisplacementForPan = 0.0f;
1290 OnScrollDragStarted();
1292 else if (panGesture.State == Gesture.StateType.Continuing)
1294 if (ScrollingDirection == Direction.Horizontal)
1296 // if vertical shadow is shown, does not scroll.
1297 if (!isOverShootingShadowShown)
1299 ScrollBy(panGesture.Displacement.X, false);
1301 totalDisplacementForPan += panGesture.Displacement.X;
1302 DragOverShootingShadow(totalDisplacementForPan, panGesture.Displacement.X);
1306 // if vertical shadow is shown, does not scroll.
1307 if (!isOverShootingShadowShown)
1309 ScrollBy(panGesture.Displacement.Y, false);
1311 totalDisplacementForPan += panGesture.Displacement.Y;
1312 DragOverShootingShadow(totalDisplacementForPan, panGesture.Displacement.Y);
1314 Debug.WriteLineIf(LayoutDebugScrollableBase, "OnPanGestureDetected Continue totalDisplacementForPan:" + totalDisplacementForPan);
1316 else if (panGesture.State == Gesture.StateType.Finished || panGesture.State == Gesture.StateType.Cancelled)
1318 PlayOverShootingShadowAnimation();
1319 OnScrollDragEnded();
1320 StopScroll(); // Will replace previous animation so will stop existing one.
1322 if (scrollAnimation == null)
1324 scrollAnimation = new Animation();
1325 scrollAnimation.Finished += ScrollAnimationFinished;
1328 float panVelocity = (ScrollingDirection == Direction.Horizontal) ? panGesture.Velocity.X : panGesture.Velocity.Y;
1332 PageSnap(panVelocity);
1336 if (panVelocity == 0)
1338 float currentScrollPosition = (ScrollingDirection == Direction.Horizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y);
1339 scrollAnimation.DefaultAlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear);
1340 scrollAnimation.Duration = 0;
1341 scrollAnimation.AnimateTo(ContentContainer, (ScrollingDirection == Direction.Horizontal) ? "PositionX" : "PositionY", currentScrollPosition);
1342 scrollAnimation.Play();
1346 Decelerating(panVelocity, scrollAnimation);
1350 totalDisplacementForPan = 0;
1352 readyToNotice = true;
1353 OnScrollAnimationStarted();
1357 internal void BaseRemove(View view)
1362 internal override bool OnAccessibilityPan(PanGesture gestures)
1364 if (SnapToPage && scrollAnimation != null && scrollAnimation.State == Animation.States.Playing)
1369 OnPanGesture(gestures);
1373 private float CustomScrollAlphaFunction(float progress)
1375 if (panAnimationDelta == 0)
1381 // Parameter "progress" is normalized value. We need to multiply target duration to calculate distance.
1382 // Can get real distance using equation of deceleration (check Decelerating function)
1383 // After get real distance, normalize it
1384 float realDuration = progress * panAnimationDuration;
1385 float realDistance = velocityOfLastPan * ((float)Math.Pow(decelerationRate, realDuration) - 1) / logValueOfDeceleration;
1386 float result = Math.Min(realDistance / Math.Abs(panAnimationDelta), 1.0f);
1392 /// you can override it to custom your decelerating
1394 /// <param name="velocity">Velocity of current pan.</param>
1395 /// <param name="animation">Scroll animation.</param>
1396 [EditorBrowsable(EditorBrowsableState.Never)]
1397 protected virtual void Decelerating(float velocity, Animation animation)
1399 // Decelerating using deceleration equation ===========
1401 // V : velocity (pixel per milisecond)
1402 // V0 : initial velocity
1403 // d : deceleration rate,
1405 // X : final position after decelerating
1406 // log : natural logarithm
1408 // V(t) = V0 * d pow t;
1409 // X(t) = V0 * (d pow t - 1) / log d; <-- Integrate the velocity function
1410 // X(∞) = V0 * d / (1 - d); <-- Result using inifit T can be final position because T is tending to infinity.
1412 // Because of final T is tending to inifity, we should use threshold value to finish.
1413 // Final T = log(-threshold * log d / |V0| ) / log d;
1415 velocityOfLastPan = Math.Abs(velocity);
1417 float currentScrollPosition = -(ScrollingDirection == Direction.Horizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y);
1418 panAnimationDelta = (velocityOfLastPan * decelerationRate) / (1 - decelerationRate);
1419 panAnimationDelta = velocity > 0 ? -panAnimationDelta : panAnimationDelta;
1421 float destination = -(panAnimationDelta + currentScrollPosition);
1422 float adjustDestination = AdjustTargetPositionOfScrollAnimation(destination);
1423 float maxPosition = ScrollAvailableArea != null ? ScrollAvailableArea.Y : maxScrollDistance;
1424 float minPosition = ScrollAvailableArea != null ? ScrollAvailableArea.X : 0;
1426 if (destination < -maxPosition || destination > minPosition)
1428 panAnimationDelta = velocity > 0 ? (currentScrollPosition - minPosition) : (maxPosition - currentScrollPosition);
1429 destination = velocity > 0 ? minPosition : -maxPosition;
1431 if (panAnimationDelta == 0)
1433 panAnimationDuration = 0.0f;
1437 panAnimationDuration = (float)Math.Log((panAnimationDelta * logValueOfDeceleration / velocityOfLastPan + 1), decelerationRate);
1440 Debug.WriteLineIf(LayoutDebugScrollableBase, "\n" +
1441 "OverRange======================= \n" +
1442 "[decelerationRate] " + decelerationRate + "\n" +
1443 "[logValueOfDeceleration] " + logValueOfDeceleration + "\n" +
1444 "[Velocity] " + velocityOfLastPan + "\n" +
1445 "[CurrentPosition] " + currentScrollPosition + "\n" +
1446 "[CandidateDelta] " + panAnimationDelta + "\n" +
1447 "[Destination] " + destination + "\n" +
1448 "[Duration] " + panAnimationDuration + "\n" +
1449 "================================ \n"
1454 panAnimationDuration = (float)Math.Log(-DecelerationThreshold * logValueOfDeceleration / velocityOfLastPan) / logValueOfDeceleration;
1456 if (adjustDestination != destination)
1458 destination = adjustDestination;
1459 panAnimationDelta = destination + currentScrollPosition;
1460 velocityOfLastPan = Math.Abs(panAnimationDelta * logValueOfDeceleration / ((float)Math.Pow(decelerationRate, panAnimationDuration) - 1));
1461 panAnimationDuration = (float)Math.Log(-DecelerationThreshold * logValueOfDeceleration / velocityOfLastPan) / logValueOfDeceleration;
1464 Debug.WriteLineIf(LayoutDebugScrollableBase, "\n" +
1465 "================================ \n" +
1466 "[decelerationRate] " + decelerationRate + "\n" +
1467 "[logValueOfDeceleration] " + logValueOfDeceleration + "\n" +
1468 "[Velocity] " + velocityOfLastPan + "\n" +
1469 "[CurrentPosition] " + currentScrollPosition + "\n" +
1470 "[CandidateDelta] " + panAnimationDelta + "\n" +
1471 "[Destination] " + destination + "\n" +
1472 "[Duration] " + panAnimationDuration + "\n" +
1473 "================================ \n"
1477 finalTargetPosition = destination;
1479 customScrollAlphaFunction = new UserAlphaFunctionDelegate(CustomScrollAlphaFunction);
1480 animation.DefaultAlphaFunction = new AlphaFunction(customScrollAlphaFunction);
1481 GC.KeepAlive(customScrollAlphaFunction);
1482 animation.Duration = (int)panAnimationDuration;
1483 animation.AnimateTo(ContentContainer, (ScrollingDirection == Direction.Horizontal) ? "PositionX" : "PositionY", destination);
1487 private void ScrollAnimationFinished(object sender, EventArgs e)
1489 OnScrollAnimationEnded();
1493 /// Adjust scrolling position by own scrolling rules.
1494 /// Override this function when developer wants to change destination of flicking.(e.g. always snap to center of item)
1496 /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
1497 [EditorBrowsable(EditorBrowsableState.Never)]
1498 protected virtual float AdjustTargetPositionOfScrollAnimation(float position)
1504 /// Scroll position given to ScrollTo.
1505 /// This is the position in the opposite direction to the position of ContentContainer.
1507 /// <since_tizen> 8 </since_tizen>
1508 public Position ScrollPosition
1512 return new Position(-ContentContainer.Position);
1517 /// Current scroll position in the middle of ScrollTo animation.
1518 /// This is the position in the opposite direction to the current position of ContentContainer.
1520 /// <since_tizen> 8 </since_tizen>
1521 public Position ScrollCurrentPosition
1525 return new Position(-ContentContainer.CurrentPosition);
1530 /// Remove all children in ContentContainer.
1532 /// <param name="dispose">If true, removed child is disposed.</param>
1533 [EditorBrowsable(EditorBrowsableState.Never)]
1534 public void RemoveAllChildren(bool dispose = false)
1536 RecursiveRemoveChildren(ContentContainer, dispose);
1539 private void RecursiveRemoveChildren(View parent, bool dispose)
1545 int maxChild = (int)parent.GetChildCount();
1546 for (int i = maxChild - 1; i >= 0; --i)
1548 View child = parent.GetChildAt((uint)i);
1553 RecursiveRemoveChildren(child, dispose);
1554 parent.Remove(child);