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 base.Remove(scrollBar);
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 StopOverShootingShadowAnimation();
973 if (mPanGestureDetector != null)
975 mPanGestureDetector.Detected -= OnPanGestureDetected;
976 mPanGestureDetector.Dispose();
977 mPanGestureDetector = null;
980 propertyNotification.Dispose();
985 private float CalculateMaximumScrollDistance()
987 float scrollingChildLength = 0;
988 float scrollerLength = 0;
989 if (ScrollingDirection == Direction.Horizontal)
991 Debug.WriteLineIf(LayoutDebugScrollableBase, "Horizontal");
993 scrollingChildLength = ContentContainer.Size.Width;
994 scrollerLength = Size.Width;
998 Debug.WriteLineIf(LayoutDebugScrollableBase, "Vertical");
999 scrollingChildLength = ContentContainer.Size.Height;
1000 scrollerLength = Size.Height;
1003 Debug.WriteLineIf(LayoutDebugScrollableBase, "ScrollBy maxScrollDistance:" + (scrollingChildLength - scrollerLength) +
1004 " parent length:" + scrollerLength +
1005 " scrolling child length:" + scrollingChildLength);
1007 return Math.Max(scrollingChildLength - scrollerLength, 0);
1010 private void PageSnap(float velocity)
1012 Debug.WriteLineIf(LayoutDebugScrollableBase, "PageSnap with pan candidate totalDisplacement:" + totalDisplacementForPan +
1013 " currentPage[" + CurrentPage + "]");
1015 //Increment current page if total displacement enough to warrant a page change.
1016 if (Math.Abs(totalDisplacementForPan) > (mPageWidth * ratioOfScreenWidthToCompleteScroll))
1018 if (totalDisplacementForPan < 0)
1020 CurrentPage = Math.Min(Math.Max(Children.Count - 1, 0), ++CurrentPage);
1024 CurrentPage = Math.Max(0, --CurrentPage);
1027 else if (Math.Abs(velocity) > PageFlickThreshold)
1031 CurrentPage = Math.Min(Math.Max(Children.Count - 1, 0), ++CurrentPage);
1035 CurrentPage = Math.Max(0, --CurrentPage);
1039 // Animate to new page or reposition to current page
1040 float destinationX = -(Children[CurrentPage].Position.X + Children[CurrentPage].CurrentSize.Width / 2 - CurrentSize.Width / 2); // set to middle of current page
1041 Debug.WriteLineIf(LayoutDebugScrollableBase, "Snapping to page[" + CurrentPage + "] to:" + destinationX + " from:" + ContentContainer.PositionX);
1042 AnimateChildTo(ScrollDuration, destinationX);
1046 /// Enable/Disable overshooting effect. default is disabled.
1048 [EditorBrowsable(EditorBrowsableState.Never)]
1049 public bool EnableOverShootingEffect { get; set; } = false;
1051 private void AttachOverShootingShadowView()
1053 if (!EnableOverShootingEffect)
1056 // stop animation if necessary.
1057 StopOverShootingShadowAnimation();
1059 if (ScrollingDirection == Direction.Horizontal)
1061 base.Add(leftOverShootingShadowView);
1062 base.Add(rightOverShootingShadowView);
1064 leftOverShootingShadowView.Size = new Size(0.0f, SizeHeight);
1065 leftOverShootingShadowView.Opacity = 1.0f;
1066 leftOverShootingShadowView.RaiseToTop();
1068 rightOverShootingShadowView.Size = new Size(0.0f, SizeHeight);
1069 rightOverShootingShadowView.Opacity = 1.0f;
1070 rightOverShootingShadowView.RaiseToTop();
1074 base.Add(topOverShootingShadowView);
1075 base.Add(bottomOverShootingShadowView);
1077 topOverShootingShadowView.Size = new Size(SizeWidth, 0.0f);
1078 topOverShootingShadowView.Opacity = 1.0f;
1079 topOverShootingShadowView.RaiseToTop();
1081 bottomOverShootingShadowView.Size = new Size(SizeWidth, 0.0f);
1082 bottomOverShootingShadowView.Opacity = 1.0f;
1083 bottomOverShootingShadowView.RaiseToTop();
1086 // at the beginning, height or width of overshooting shadow is 0, so it is invisible.
1087 isOverShootingShadowShown = false;
1090 private void DragOverShootingShadow(float totalPanDisplacement, float panDisplacement)
1092 if (!EnableOverShootingEffect)
1095 if (totalPanDisplacement > 0) // downwards
1097 // check if reaching at the top / left.
1098 if ((int)finalTargetPosition != 0)
1100 isOverShootingShadowShown = false;
1104 // save start displacement, and re-calculate displacement.
1105 if (!isOverShootingShadowShown)
1107 startShowShadowDisplacement = totalPanDisplacement;
1109 isOverShootingShadowShown = true;
1111 float newDisplacement = (int)totalPanDisplacement < (int)startShowShadowDisplacement ? 0 : totalPanDisplacement - startShowShadowDisplacement;
1113 if (ScrollingDirection == Direction.Horizontal)
1115 // scale limit of height is 60%.
1116 float heightScale = newDisplacement / overShootingShadowScaleHeightLimit;
1117 leftOverShootingShadowView.SizeHeight = heightScale > 0.6f ? SizeHeight * 0.4f : SizeHeight * (1.0f - heightScale);
1119 // scale limit of width is 300%.
1120 leftOverShootingShadowView.SizeWidth = newDisplacement > overShootingShadowScaleHeightLimit ? overShootingShadowScaleHeightLimit : newDisplacement;
1123 ScrollOutOfBoundEventArgs.Direction scrollDirection = panDisplacement > 0 ?
1124 ScrollOutOfBoundEventArgs.Direction.Right : ScrollOutOfBoundEventArgs.Direction.Left;
1125 OnScrollOutOfBound(scrollDirection, totalPanDisplacement);
1129 // scale limit of width is 60%.
1130 float widthScale = newDisplacement / overShootingShadowScaleHeightLimit;
1131 topOverShootingShadowView.SizeWidth = widthScale > 0.6f ? SizeWidth * 0.4f : SizeWidth * (1.0f - widthScale);
1133 // scale limit of height is 300%.
1134 topOverShootingShadowView.SizeHeight = newDisplacement > overShootingShadowScaleHeightLimit ? overShootingShadowScaleHeightLimit : newDisplacement;
1137 ScrollOutOfBoundEventArgs.Direction scrollDirection = panDisplacement > 0 ?
1138 ScrollOutOfBoundEventArgs.Direction.Down : ScrollOutOfBoundEventArgs.Direction.Up;
1139 OnScrollOutOfBound(scrollDirection, totalPanDisplacement);
1142 else if (totalPanDisplacement < 0) // upwards
1144 // check if reaching at the bottom.
1145 if (-(int)finalTargetPosition != (int)maxScrollDistance)
1147 isOverShootingShadowShown = false;
1151 // save start displacement, and re-calculate displacement.
1152 if (!isOverShootingShadowShown)
1154 startShowShadowDisplacement = totalPanDisplacement;
1156 isOverShootingShadowShown = true;
1158 float newDisplacement = (int)startShowShadowDisplacement < (int)totalPanDisplacement ? 0 : startShowShadowDisplacement - totalPanDisplacement;
1160 if (ScrollingDirection == Direction.Horizontal)
1162 // scale limit of height is 60%.
1163 float heightScale = newDisplacement / overShootingShadowScaleHeightLimit;
1164 rightOverShootingShadowView.SizeHeight = heightScale > 0.6f ? SizeHeight * 0.4f : SizeHeight * (1.0f - heightScale);
1166 // scale limit of width is 300%.
1167 rightOverShootingShadowView.SizeWidth = newDisplacement > overShootingShadowScaleHeightLimit ? overShootingShadowScaleHeightLimit : newDisplacement;
1170 ScrollOutOfBoundEventArgs.Direction scrollDirection = panDisplacement > 0 ?
1171 ScrollOutOfBoundEventArgs.Direction.Right : ScrollOutOfBoundEventArgs.Direction.Left;
1172 OnScrollOutOfBound(scrollDirection, totalPanDisplacement);
1176 // scale limit of width is 60%.
1177 float widthScale = newDisplacement / overShootingShadowScaleHeightLimit;
1178 bottomOverShootingShadowView.SizeWidth = widthScale > 0.6f ? SizeWidth * 0.4f : SizeWidth * (1.0f - widthScale);
1180 // scale limit of height is 300%.
1181 bottomOverShootingShadowView.SizeHeight = newDisplacement > overShootingShadowScaleHeightLimit ? overShootingShadowScaleHeightLimit : newDisplacement;
1184 ScrollOutOfBoundEventArgs.Direction scrollDirection = panDisplacement > 0 ?
1185 ScrollOutOfBoundEventArgs.Direction.Down : ScrollOutOfBoundEventArgs.Direction.Up;
1186 OnScrollOutOfBound(scrollDirection, totalPanDisplacement);
1191 // if total displacement is 0, shadow would become invisible.
1192 isOverShootingShadowShown = false;
1196 private void PlayOverShootingShadowAnimation()
1198 if (!EnableOverShootingEffect)
1201 // stop animation if necessary.
1202 StopOverShootingShadowAnimation();
1204 if (overShootingShadowAnimation == null)
1206 overShootingShadowAnimation = new Animation(overShootingShadowAnimationDuration);
1207 overShootingShadowAnimation.Finished += OnOverShootingShadowAnimationFinished;
1210 if (ScrollingDirection == Direction.Horizontal)
1212 View targetView = totalDisplacementForPan < 0 ? rightOverShootingShadowView : leftOverShootingShadowView;
1213 overShootingShadowAnimation.AnimateTo(targetView, "SizeHeight", SizeHeight);
1214 overShootingShadowAnimation.AnimateTo(targetView, "SizeWidth", 0.0f);
1215 overShootingShadowAnimation.AnimateTo(targetView, "Opacity", 0.0f);
1219 View targetView = totalDisplacementForPan < 0 ? bottomOverShootingShadowView : topOverShootingShadowView;
1220 overShootingShadowAnimation.AnimateTo(targetView, "SizeWidth", SizeWidth);
1221 overShootingShadowAnimation.AnimateTo(targetView, "SizeHeight", 0.0f);
1222 overShootingShadowAnimation.AnimateTo(targetView, "Opacity", 0.0f);
1224 overShootingShadowAnimation.Play();
1227 private void StopOverShootingShadowAnimation()
1229 if (overShootingShadowAnimation == null || overShootingShadowAnimation.State != Animation.States.Playing)
1232 overShootingShadowAnimation.Stop(Animation.EndActions.Cancel);
1233 OnOverShootingShadowAnimationFinished(null, null);
1234 overShootingShadowAnimation.Clear();
1237 private void OnOverShootingShadowAnimationFinished(object sender, EventArgs e)
1239 if (ScrollingDirection == Direction.Horizontal)
1241 base.Remove(leftOverShootingShadowView);
1242 base.Remove(rightOverShootingShadowView);
1244 leftOverShootingShadowView.Size = new Size(0.0f, SizeHeight);
1245 rightOverShootingShadowView.Size = new Size(0.0f, SizeHeight);
1249 base.Remove(topOverShootingShadowView);
1250 base.Remove(bottomOverShootingShadowView);
1252 topOverShootingShadowView.Size = new Size(SizeWidth, 0.0f);
1253 bottomOverShootingShadowView.Size = new Size(SizeWidth, 0.0f);
1256 // after animation finished, height/width & opacity of vertical shadow both are 0, so it is invisible.
1257 isOverShootingShadowShown = false;
1260 private void OnScrollOutOfBound(ScrollOutOfBoundEventArgs.Direction direction, float displacement)
1262 ScrollOutOfBoundEventArgs args = new ScrollOutOfBoundEventArgs(direction, displacement);
1263 ScrollOutOfBound?.Invoke(this, args);
1266 private void OnPanGestureDetected(object source, PanGestureDetector.DetectedEventArgs e)
1268 OnPanGesture(e.PanGesture);
1271 private void OnPanGesture(PanGesture panGesture)
1273 if (SnapToPage && scrollAnimation != null && scrollAnimation.State == Animation.States.Playing)
1278 if (panGesture.State == Gesture.StateType.Started)
1280 readyToNotice = false;
1281 base.Add(mInterruptTouchingChild);
1282 AttachOverShootingShadowView();
1283 Debug.WriteLineIf(LayoutDebugScrollableBase, "Gesture Start");
1284 if (scrolling && !SnapToPage)
1288 totalDisplacementForPan = 0.0f;
1289 OnScrollDragStarted();
1291 else if (panGesture.State == Gesture.StateType.Continuing)
1293 if (ScrollingDirection == Direction.Horizontal)
1295 // if vertical shadow is shown, does not scroll.
1296 if (!isOverShootingShadowShown)
1298 ScrollBy(panGesture.Displacement.X, false);
1300 totalDisplacementForPan += panGesture.Displacement.X;
1301 DragOverShootingShadow(totalDisplacementForPan, panGesture.Displacement.X);
1305 // if vertical shadow is shown, does not scroll.
1306 if (!isOverShootingShadowShown)
1308 ScrollBy(panGesture.Displacement.Y, false);
1310 totalDisplacementForPan += panGesture.Displacement.Y;
1311 DragOverShootingShadow(totalDisplacementForPan, panGesture.Displacement.Y);
1313 Debug.WriteLineIf(LayoutDebugScrollableBase, "OnPanGestureDetected Continue totalDisplacementForPan:" + totalDisplacementForPan);
1315 else if (panGesture.State == Gesture.StateType.Finished || panGesture.State == Gesture.StateType.Cancelled)
1317 PlayOverShootingShadowAnimation();
1318 OnScrollDragEnded();
1319 StopScroll(); // Will replace previous animation so will stop existing one.
1321 if (scrollAnimation == null)
1323 scrollAnimation = new Animation();
1324 scrollAnimation.Finished += ScrollAnimationFinished;
1327 float panVelocity = (ScrollingDirection == Direction.Horizontal) ? panGesture.Velocity.X : panGesture.Velocity.Y;
1331 PageSnap(panVelocity);
1335 if (panVelocity == 0)
1337 float currentScrollPosition = (ScrollingDirection == Direction.Horizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y);
1338 scrollAnimation.DefaultAlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear);
1339 scrollAnimation.Duration = 0;
1340 scrollAnimation.AnimateTo(ContentContainer, (ScrollingDirection == Direction.Horizontal) ? "PositionX" : "PositionY", currentScrollPosition);
1341 scrollAnimation.Play();
1345 Decelerating(panVelocity, scrollAnimation);
1349 totalDisplacementForPan = 0;
1351 readyToNotice = true;
1352 OnScrollAnimationStarted();
1356 internal void BaseRemove(View view)
1361 internal override bool OnAccessibilityPan(PanGesture gestures)
1363 if (SnapToPage && scrollAnimation != null && scrollAnimation.State == Animation.States.Playing)
1368 OnPanGesture(gestures);
1372 private float CustomScrollAlphaFunction(float progress)
1374 if (panAnimationDelta == 0)
1380 // Parameter "progress" is normalized value. We need to multiply target duration to calculate distance.
1381 // Can get real distance using equation of deceleration (check Decelerating function)
1382 // After get real distance, normalize it
1383 float realDuration = progress * panAnimationDuration;
1384 float realDistance = velocityOfLastPan * ((float)Math.Pow(decelerationRate, realDuration) - 1) / logValueOfDeceleration;
1385 float result = Math.Min(realDistance / Math.Abs(panAnimationDelta), 1.0f);
1391 /// you can override it to custom your decelerating
1393 /// <param name="velocity">Velocity of current pan.</param>
1394 /// <param name="animation">Scroll animation.</param>
1395 [EditorBrowsable(EditorBrowsableState.Never)]
1396 protected virtual void Decelerating(float velocity, Animation animation)
1398 // Decelerating using deceleration equation ===========
1400 // V : velocity (pixel per milisecond)
1401 // V0 : initial velocity
1402 // d : deceleration rate,
1404 // X : final position after decelerating
1405 // log : natural logarithm
1407 // V(t) = V0 * d pow t;
1408 // X(t) = V0 * (d pow t - 1) / log d; <-- Integrate the velocity function
1409 // X(∞) = V0 * d / (1 - d); <-- Result using inifit T can be final position because T is tending to infinity.
1411 // Because of final T is tending to inifity, we should use threshold value to finish.
1412 // Final T = log(-threshold * log d / |V0| ) / log d;
1414 velocityOfLastPan = Math.Abs(velocity);
1416 float currentScrollPosition = -(ScrollingDirection == Direction.Horizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y);
1417 panAnimationDelta = (velocityOfLastPan * decelerationRate) / (1 - decelerationRate);
1418 panAnimationDelta = velocity > 0 ? -panAnimationDelta : panAnimationDelta;
1420 float destination = -(panAnimationDelta + currentScrollPosition);
1421 float adjustDestination = AdjustTargetPositionOfScrollAnimation(destination);
1422 float maxPosition = ScrollAvailableArea != null ? ScrollAvailableArea.Y : maxScrollDistance;
1423 float minPosition = ScrollAvailableArea != null ? ScrollAvailableArea.X : 0;
1425 if (destination < -maxPosition || destination > minPosition)
1427 panAnimationDelta = velocity > 0 ? (currentScrollPosition - minPosition) : (maxPosition - currentScrollPosition);
1428 destination = velocity > 0 ? minPosition : -maxPosition;
1430 if (panAnimationDelta == 0)
1432 panAnimationDuration = 0.0f;
1436 panAnimationDuration = (float)Math.Log((panAnimationDelta * logValueOfDeceleration / velocityOfLastPan + 1), decelerationRate);
1439 Debug.WriteLineIf(LayoutDebugScrollableBase, "\n" +
1440 "OverRange======================= \n" +
1441 "[decelerationRate] " + decelerationRate + "\n" +
1442 "[logValueOfDeceleration] " + logValueOfDeceleration + "\n" +
1443 "[Velocity] " + velocityOfLastPan + "\n" +
1444 "[CurrentPosition] " + currentScrollPosition + "\n" +
1445 "[CandidateDelta] " + panAnimationDelta + "\n" +
1446 "[Destination] " + destination + "\n" +
1447 "[Duration] " + panAnimationDuration + "\n" +
1448 "================================ \n"
1453 panAnimationDuration = (float)Math.Log(-DecelerationThreshold * logValueOfDeceleration / velocityOfLastPan) / logValueOfDeceleration;
1455 if (adjustDestination != destination)
1457 destination = adjustDestination;
1458 panAnimationDelta = destination + currentScrollPosition;
1459 velocityOfLastPan = Math.Abs(panAnimationDelta * logValueOfDeceleration / ((float)Math.Pow(decelerationRate, panAnimationDuration) - 1));
1460 panAnimationDuration = (float)Math.Log(-DecelerationThreshold * logValueOfDeceleration / velocityOfLastPan) / logValueOfDeceleration;
1463 Debug.WriteLineIf(LayoutDebugScrollableBase, "\n" +
1464 "================================ \n" +
1465 "[decelerationRate] " + decelerationRate + "\n" +
1466 "[logValueOfDeceleration] " + logValueOfDeceleration + "\n" +
1467 "[Velocity] " + velocityOfLastPan + "\n" +
1468 "[CurrentPosition] " + currentScrollPosition + "\n" +
1469 "[CandidateDelta] " + panAnimationDelta + "\n" +
1470 "[Destination] " + destination + "\n" +
1471 "[Duration] " + panAnimationDuration + "\n" +
1472 "================================ \n"
1476 finalTargetPosition = destination;
1478 customScrollAlphaFunction = new UserAlphaFunctionDelegate(CustomScrollAlphaFunction);
1479 animation.DefaultAlphaFunction = new AlphaFunction(customScrollAlphaFunction);
1480 GC.KeepAlive(customScrollAlphaFunction);
1481 animation.Duration = (int)panAnimationDuration;
1482 animation.AnimateTo(ContentContainer, (ScrollingDirection == Direction.Horizontal) ? "PositionX" : "PositionY", destination);
1486 private void ScrollAnimationFinished(object sender, EventArgs e)
1488 OnScrollAnimationEnded();
1492 /// Adjust scrolling position by own scrolling rules.
1493 /// Override this function when developer wants to change destination of flicking.(e.g. always snap to center of item)
1495 /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
1496 [EditorBrowsable(EditorBrowsableState.Never)]
1497 protected virtual float AdjustTargetPositionOfScrollAnimation(float position)
1503 /// Scroll position given to ScrollTo.
1504 /// This is the position in the opposite direction to the position of ContentContainer.
1506 /// <since_tizen> 8 </since_tizen>
1507 public Position ScrollPosition
1511 return new Position(-ContentContainer.Position);
1516 /// Current scroll position in the middle of ScrollTo animation.
1517 /// This is the position in the opposite direction to the current position of ContentContainer.
1519 /// <since_tizen> 8 </since_tizen>
1520 public Position ScrollCurrentPosition
1524 return new Position(-ContentContainer.CurrentPosition);
1529 /// Remove all children in ContentContainer.
1531 /// <param name="dispose">If true, removed child is disposed.</param>
1532 [EditorBrowsable(EditorBrowsableState.Never)]
1533 public void RemoveAllChildren(bool dispose = false)
1535 RecursiveRemoveChildren(ContentContainer, dispose);
1538 private void RecursiveRemoveChildren(View parent, bool dispose)
1544 int maxChild = (int)parent.GetChildCount();
1545 for (int i = maxChild - 1; i >= 0; --i)
1547 View child = parent.GetChildAt((uint)i);
1552 RecursiveRemoveChildren(child, dispose);
1553 parent.Remove(child);