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 //Reset scroll position and stop scroll animation
266 mScrollingDirection = value;
267 mPanGestureDetector.ClearAngles();
268 mPanGestureDetector.AddDirection(value == Direction.Horizontal ?
269 PanGestureDetector.DirectionHorizontal : PanGestureDetector.DirectionVertical);
271 ContentContainer.WidthSpecification = ScrollingDirection == Direction.Vertical ? LayoutParamPolicies.MatchParent : LayoutParamPolicies.WrapContent;
272 ContentContainer.HeightSpecification = ScrollingDirection == Direction.Vertical ? LayoutParamPolicies.WrapContent : LayoutParamPolicies.MatchParent;
279 /// Enable or disable scrolling.
281 /// <since_tizen> 8 </since_tizen>
282 public bool ScrollEnabled
286 return mScrollEnabled;
290 if (value != mScrollEnabled)
292 mScrollEnabled = value;
295 mPanGestureDetector.Detected += OnPanGestureDetected;
299 mPanGestureDetector.Detected -= OnPanGestureDetected;
306 /// Gets scrollable status.
308 [EditorBrowsable(EditorBrowsableState.Never)]
309 protected override bool AccessibilityIsScrollable()
315 /// Pages mode, enables moving to the next or return to current page depending on pan displacement.
316 /// Default is false.
318 /// <since_tizen> 8 </since_tizen>
319 public bool SnapToPage { set; get; } = false;
322 /// Get current page.
323 /// Working property with SnapToPage property.
325 /// <since_tizen> 8 </since_tizen>
326 public int CurrentPage { get; private set; } = 0;
329 /// Duration of scroll animation.
330 /// Default value is 125ms.
332 /// <since_tizen> 8 </since_tizen>
333 public int ScrollDuration
337 mScrollDuration = value >= 0 ? value : mScrollDuration;
341 return mScrollDuration;
346 /// Scroll Available area.
348 /// <since_tizen> 8 </since_tizen>
349 public Vector2 ScrollAvailableArea { set; get; }
352 /// An event emitted when user starts dragging ScrollableBase, user can subscribe or unsubscribe to this event handler.<br />
354 /// <since_tizen> 8 </since_tizen>
355 public event EventHandler<ScrollEventArgs> ScrollDragStarted;
358 /// An event emitted when user stops dragging ScrollableBase, user can subscribe or unsubscribe to this event handler.<br />
360 /// <since_tizen> 8 </since_tizen>
361 public event EventHandler<ScrollEventArgs> ScrollDragEnded;
364 /// An event emitted when the scrolling slide animation starts, user can subscribe or unsubscribe to this event handler.<br />
366 /// <since_tizen> 8 </since_tizen>
367 public event EventHandler<ScrollEventArgs> ScrollAnimationStarted;
370 /// An event emitted when the scrolling slide animation ends, user can subscribe or unsubscribe to this event handler.<br />
372 /// <since_tizen> 8 </since_tizen>
373 public event EventHandler<ScrollEventArgs> ScrollAnimationEnded;
376 /// An event emitted when scrolling, user can subscribe or unsubscribe to this event handler.<br />
378 /// <since_tizen> 8 </since_tizen>
379 public event EventHandler<ScrollEventArgs> Scrolling;
382 /// An event emitted when scrolling out of bound, user can subscribe or unsubscribe to this event handler.<br />
384 [EditorBrowsable(EditorBrowsableState.Never)]
385 public event EventHandler<ScrollOutOfBoundEventArgs> ScrollOutOfBound;
388 /// Scrollbar for ScrollableBase.
390 /// <since_tizen> 8 </since_tizen>
391 public ScrollbarBase Scrollbar
401 base.Remove(scrollBar);
405 if (scrollBar != null)
407 scrollBar.Name = "ScrollBar";
425 /// Always hide Scrollbar.
427 /// <since_tizen> 8 </since_tizen>
428 public bool HideScrollbar
432 return hideScrollbar;
436 hideScrollbar = value;
453 /// Container which has content of ScrollableBase.
455 /// <since_tizen> 8 </since_tizen>
456 public View ContentContainer { get; private set; }
459 /// Set the layout on this View. Replaces any existing Layout.
461 /// <since_tizen> 8 </since_tizen>
462 public new LayoutItem Layout
466 return ContentContainer.Layout;
470 ContentContainer.Layout = value;
475 /// List of children of Container.
477 /// <since_tizen> 8 </since_tizen>
478 public new List<View> Children
482 return ContentContainer.Children;
487 /// Deceleration rate of scrolling by finger.
488 /// Rate should be bigger than 0 and smaller than 1.
489 /// Default value is 0.998f;
491 /// <since_tizen> 8 </since_tizen>
492 public float DecelerationRate
496 return decelerationRate;
500 decelerationRate = (value < 1 && value > 0) ? value : decelerationRate;
501 logValueOfDeceleration = (float)Math.Log(value);
506 /// Threshold not to go infinite at the end of scrolling animation.
508 [EditorBrowsable(EditorBrowsableState.Never)]
509 public float DecelerationThreshold { get; set; } = 0.1f;
512 /// Scrolling event will be thrown when this amount of scroll position is changed.
513 /// If this threshold becomes smaller, the tracking detail increases but the scrolling range that can be tracked becomes smaller.
514 /// If large sized ContentContainer is required, please use larger threshold value.
515 /// Default ScrollingEventThreshold value is 0.001f.
517 [EditorBrowsable(EditorBrowsableState.Never)]
518 public float ScrollingEventThreshold
522 return mScrollingEventThreshold;
526 if (mScrollingEventThreshold != value && value > 0)
528 ContentContainer.RemovePropertyNotification(propertyNotification);
529 propertyNotification = ContentContainer.AddPropertyNotification("position", PropertyCondition.Step(value));
530 propertyNotification.Notified += OnPropertyChanged;
531 mScrollingEventThreshold = value;
537 /// Page will be changed when velocity of panning is over threshold.
538 /// The unit of threshold is pixel per millisecond.
540 /// <since_tizen> 8 </since_tizen>
541 public float PageFlickThreshold
545 return mPageFlickThreshold;
549 mPageFlickThreshold = value >= 0f ? value : mPageFlickThreshold;
554 /// Padding for the ScrollableBase
556 [EditorBrowsable(EditorBrowsableState.Never)]
557 public new Extents Padding
561 return ContentContainer.Padding;
565 ContentContainer.Padding = value;
570 /// Alphafunction for scroll animation.
572 [EditorBrowsable(EditorBrowsableState.Never)]
573 public AlphaFunction ScrollAlphaFunction { get; set; } = new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear);
575 private bool hideScrollbar = true;
576 private float maxScrollDistance;
577 private float childTargetPosition = 0.0f;
578 private PanGestureDetector mPanGestureDetector;
579 private ScrollbarBase scrollBar;
580 private bool scrolling = false;
581 private float ratioOfScreenWidthToCompleteScroll = 0.5f;
582 private float totalDisplacementForPan = 0.0f;
583 private Size previousContainerSize = new Size();
584 private Size previousSize = new Size();
585 private PropertyNotification propertyNotification;
586 private float noticeAnimationEndBeforePosition = 0.0f;
587 private bool readyToNotice = false;
590 /// Notice before animation is finished.
592 [EditorBrowsable(EditorBrowsableState.Never)]
593 // Let's consider more whether this needs to be set as protected.
594 public float NoticeAnimationEndBeforePosition
596 get => noticeAnimationEndBeforePosition;
597 set => noticeAnimationEndBeforePosition = value;
600 // Let's consider more whether this needs to be set as protected.
601 private float finalTargetPosition;
603 private Animation scrollAnimation;
604 // Declare user alpha function delegate
605 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
606 private delegate float UserAlphaFunctionDelegate(float progress);
607 private UserAlphaFunctionDelegate customScrollAlphaFunction;
608 private float velocityOfLastPan = 0.0f;
609 private float panAnimationDuration = 0.0f;
610 private float panAnimationDelta = 0.0f;
611 private float logValueOfDeceleration = 0.0f;
612 private float decelerationRate = 0.0f;
614 private View topOverShootingShadowView;
615 private View bottomOverShootingShadowView;
616 private View leftOverShootingShadowView;
617 private View rightOverShootingShadowView;
618 private const int overShootingShadowScaleHeightLimit = 64 * 3;
619 private const int overShootingShadowAnimationDuration = 300;
620 private Animation overShootingShadowAnimation;
621 private bool isOverShootingShadowShown = false;
622 private float startShowShadowDisplacement;
625 /// Default Constructor
627 /// <since_tizen> 8 </since_tizen>
628 public ScrollableBase() : base()
630 DecelerationRate = 0.998f;
632 base.Layout = new ScrollableBaseCustomLayout();
633 mPanGestureDetector = new PanGestureDetector();
634 mPanGestureDetector.Attach(this);
635 mPanGestureDetector.AddDirection(PanGestureDetector.DirectionVertical);
636 if (mPanGestureDetector.GetMaximumTouchesRequired() < 2) mPanGestureDetector.SetMaximumTouchesRequired(2);
637 mPanGestureDetector.Detected += OnPanGestureDetected;
639 ClippingMode = ClippingModeType.ClipToBoundingBox;
641 //Default Scrolling child
642 ContentContainer = new View()
644 Name = "ContentContainer",
645 WidthSpecification = ScrollingDirection == Direction.Vertical ? LayoutParamPolicies.MatchParent : LayoutParamPolicies.WrapContent,
646 HeightSpecification = ScrollingDirection == Direction.Vertical ? LayoutParamPolicies.WrapContent : LayoutParamPolicies.MatchParent,
648 ContentContainer.Relayout += OnScrollingChildRelayout;
649 propertyNotification = ContentContainer.AddPropertyNotification("position", PropertyCondition.Step(mScrollingEventThreshold));
650 propertyNotification.Notified += OnPropertyChanged;
651 base.Add(ContentContainer);
653 Scrollbar = new Scrollbar();
655 //Show vertical shadow on the top (or bottom) of the scrollable when panning down (or up).
656 topOverShootingShadowView = new View
658 BackgroundImage = FrameworkInformation.ResourcePath + "nui_component_default_scroll_over_shooting_top.png",
661 PositionUsesPivotPoint = true,
662 ParentOrigin = NUI.ParentOrigin.TopCenter,
663 PivotPoint = NUI.PivotPoint.TopCenter,
665 bottomOverShootingShadowView = new View
667 BackgroundImage = FrameworkInformation.ResourcePath + "nui_component_default_scroll_over_shooting_bottom.png",
670 PositionUsesPivotPoint = true,
671 ParentOrigin = NUI.ParentOrigin.BottomCenter,
672 PivotPoint = NUI.PivotPoint.BottomCenter,
674 //Show horizontal shadow on the left (or right) of the scrollable when panning down (or up).
675 leftOverShootingShadowView = new View
677 BackgroundImage = FrameworkInformation.ResourcePath + "nui_component_default_scroll_over_shooting_left.png",
680 PositionUsesPivotPoint = true,
681 ParentOrigin = NUI.ParentOrigin.CenterLeft,
682 PivotPoint = NUI.PivotPoint.CenterLeft,
684 rightOverShootingShadowView = new View
686 BackgroundImage = FrameworkInformation.ResourcePath + "nui_component_default_scroll_over_shooting_right.png",
689 PositionUsesPivotPoint = true,
690 ParentOrigin = NUI.ParentOrigin.CenterRight,
691 PivotPoint = NUI.PivotPoint.CenterRight,
694 AccessibilityManager.Instance.SetAccessibilityAttribute(this, AccessibilityManager.AccessibilityAttribute.Trait, "ScrollableBase");
696 SetKeyboardNavigationSupport(true);
699 private bool OnInterruptTouchingChildTouched(object source, View.TouchEventArgs args)
701 if (args.Touch.GetState(0) == PointStateType.Down)
703 if (scrolling && !SnapToPage)
711 private void OnPropertyChanged(object source, PropertyNotification.NotifyEventArgs args)
717 /// Called after a child has been added to the owning view.
719 /// <param name="view">The child which has been added.</param>
720 /// <since_tizen> 8 </since_tizen>
721 public override void Add(View view)
723 ContentContainer.Add(view);
727 /// Called after a child has been removed from the owning view.
729 /// <param name="view">The child which has been removed.</param>
730 /// <since_tizen> 8 </since_tizen>
731 public override void Remove(View view)
733 if (SnapToPage && CurrentPage == Children.IndexOf(view) && CurrentPage == Children.Count - 1 && Children.Count > 1)
735 // Target View is current page and also last child.
736 // CurrentPage should be changed to previous page.
737 ScrollToIndex(CurrentPage - 1);
740 ContentContainer.Remove(view);
743 private void OnScrollingChildRelayout(object source, EventArgs args)
745 // Size is changed. Calculate maxScrollDistance.
746 bool isSizeChanged = previousContainerSize.Width != ContentContainer.Size.Width || previousContainerSize.Height != ContentContainer.Size.Height ||
747 previousSize.Width != Size.Width || previousSize.Height != Size.Height;
751 maxScrollDistance = CalculateMaximumScrollDistance();
752 if (!ReviseContainerPositionIfNeed())
758 previousContainerSize = ContentContainer.Size;
762 private bool ReviseContainerPositionIfNeed()
764 bool isHorizontal = ScrollingDirection == Direction.Horizontal;
765 float currentPosition = isHorizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y;
767 if (Math.Abs(currentPosition) > maxScrollDistance)
770 var targetPosition = BoundScrollPosition(-maxScrollDistance);
771 if (isHorizontal) ContentContainer.PositionX = targetPosition;
772 else ContentContainer.PositionY = targetPosition;
780 /// The composition of a Scrollbar can vary depending on how you use ScrollableBase.
781 /// Set the composition that will go into the ScrollableBase according to your ScrollableBase.
783 /// <since_tizen> 8 </since_tizen>
784 [EditorBrowsable(EditorBrowsableState.Never)]
785 protected virtual void SetScrollbar()
789 bool isHorizontal = ScrollingDirection == Direction.Horizontal;
790 float contentLength = isHorizontal ? ContentContainer.Size.Width : ContentContainer.Size.Height;
791 float viewportLength = isHorizontal ? Size.Width : Size.Height;
792 float currentPosition = isHorizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y;
793 Scrollbar.Initialize(contentLength, viewportLength, -currentPosition, isHorizontal);
797 /// Update scrollbar position and size.
798 [EditorBrowsable(EditorBrowsableState.Never)]
799 protected virtual void UpdateScrollbar()
803 bool isHorizontal = ScrollingDirection == Direction.Horizontal;
804 float contentLength = isHorizontal ? ContentContainer.Size.Width : ContentContainer.Size.Height;
805 float viewportLength = isHorizontal ? Size.Width : Size.Height;
806 float currentPosition = isHorizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y;
807 Scrollbar.Update(contentLength, viewportLength, -currentPosition);
812 /// Scrolls to the item at the specified index.
814 /// <param name="index">Index of item.</param>
815 /// <since_tizen> 8 </since_tizen>
816 public void ScrollToIndex(int index)
818 if (ContentContainer.ChildCount - 1 < index || index < 0)
828 float targetPosition = Math.Min(ScrollingDirection == Direction.Vertical ? Children[index].Position.Y : Children[index].Position.X, maxScrollDistance);
829 AnimateChildTo(ScrollDuration, -targetPosition);
832 private void OnScrollDragStarted()
834 ScrollEventArgs eventArgs = new ScrollEventArgs(ContentContainer.CurrentPosition);
835 ScrollDragStarted?.Invoke(this, eventArgs);
838 private void OnScrollDragEnded()
840 ScrollEventArgs eventArgs = new ScrollEventArgs(ContentContainer.CurrentPosition);
841 ScrollDragEnded?.Invoke(this, eventArgs);
844 private void OnScrollAnimationStarted()
846 ScrollEventArgs eventArgs = new ScrollEventArgs(ContentContainer.CurrentPosition);
847 ScrollAnimationStarted?.Invoke(this, eventArgs);
850 private void OnScrollAnimationEnded()
853 this.InterceptTouchEvent -= OnInterruptTouchingChildTouched;
855 ScrollEventArgs eventArgs = new ScrollEventArgs(ContentContainer.CurrentPosition);
856 ScrollAnimationEnded?.Invoke(this, eventArgs);
859 private void OnScroll()
861 ScrollEventArgs eventArgs = new ScrollEventArgs(ContentContainer.CurrentPosition);
862 Scrolling?.Invoke(this, eventArgs);
864 bool isHorizontal = ScrollingDirection == Direction.Horizontal;
865 float contentLength = isHorizontal ? ContentContainer.Size.Width : ContentContainer.Size.Height;
866 float currentPosition = isHorizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y;
868 scrollBar?.Update(contentLength, Math.Abs(currentPosition));
869 CheckPreReachedTargetPosition();
872 private void CheckPreReachedTargetPosition()
874 // Check whether we reached pre-reached target position
876 ContentContainer.CurrentPosition.Y <= finalTargetPosition + NoticeAnimationEndBeforePosition &&
877 ContentContainer.CurrentPosition.Y >= finalTargetPosition - NoticeAnimationEndBeforePosition)
880 readyToNotice = false;
881 OnPreReachedTargetPosition(finalTargetPosition);
886 /// This helps developer who wants to know before scroll is reaching target position.
888 /// <param name="targetPosition">Index of item.</param>
889 /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
890 [EditorBrowsable(EditorBrowsableState.Never)]
891 protected virtual void OnPreReachedTargetPosition(float targetPosition)
896 private void StopScroll()
898 if (scrollAnimation != null)
900 if (scrollAnimation.State == Animation.States.Playing)
902 Debug.WriteLineIf(LayoutDebugScrollableBase, "StopScroll Animation Playing");
903 scrollAnimation.Stop(Animation.EndActions.Cancel);
904 OnScrollAnimationEnded();
906 scrollAnimation.Clear();
910 private void AnimateChildTo(int duration, float axisPosition)
912 Debug.WriteLineIf(LayoutDebugScrollableBase, "AnimationTo Animation Duration:" + duration + " Destination:" + axisPosition);
913 finalTargetPosition = axisPosition;
915 StopScroll(); // Will replace previous animation so will stop existing one.
917 if (scrollAnimation == null)
919 scrollAnimation = new Animation();
920 scrollAnimation.Finished += ScrollAnimationFinished;
923 scrollAnimation.Duration = duration;
924 scrollAnimation.DefaultAlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSquare);
925 scrollAnimation.AnimateTo(ContentContainer, (ScrollingDirection == Direction.Horizontal) ? "PositionX" : "PositionY", axisPosition, ScrollAlphaFunction);
927 OnScrollAnimationStarted();
928 scrollAnimation.Play();
932 /// Scroll to specific position with or without animation.
934 /// <param name="position">Destination.</param>
935 /// <param name="animate">Scroll with or without animation</param>
936 /// <since_tizen> 8 </since_tizen>
937 public void ScrollTo(float position, bool animate)
940 float currentPositionX = ContentContainer.CurrentPosition.X != 0 ? ContentContainer.CurrentPosition.X : ContentContainer.Position.X;
941 float currentPositionY = ContentContainer.CurrentPosition.Y != 0 ? ContentContainer.CurrentPosition.Y : ContentContainer.Position.Y;
942 float delta = ScrollingDirection == Direction.Horizontal ? currentPositionX : currentPositionY;
943 // The argument position is the new pan position. So the new position of ScrollableBase becomes (-position).
944 // To move ScrollableBase's position to (-position), it moves by (-position - currentPosition).
945 delta = -position - delta;
947 ScrollBy(delta, animate);
950 private float BoundScrollPosition(float targetPosition)
952 if (ScrollAvailableArea != null)
954 float minScrollPosition = ScrollAvailableArea.X;
955 float maxScrollPosition = ScrollAvailableArea.Y;
957 targetPosition = Math.Min(-minScrollPosition, targetPosition);
958 targetPosition = Math.Max(-maxScrollPosition, targetPosition);
962 targetPosition = Math.Min(0, targetPosition);
963 targetPosition = Math.Max(-maxScrollDistance, targetPosition);
966 return targetPosition;
969 private void ScrollBy(float displacement, bool animate)
971 if (GetChildCount() == 0 || maxScrollDistance < 0)
976 float childCurrentPosition = (ScrollingDirection == Direction.Horizontal) ? ContentContainer.PositionX : ContentContainer.PositionY;
978 Debug.WriteLineIf(LayoutDebugScrollableBase, "ScrollBy childCurrentPosition:" + childCurrentPosition +
979 " displacement:" + displacement,
980 " maxScrollDistance:" + maxScrollDistance);
982 childTargetPosition = childCurrentPosition + displacement; // child current position + gesture displacement
984 Debug.WriteLineIf(LayoutDebugScrollableBase, "ScrollBy currentAxisPosition:" + childCurrentPosition + "childTargetPosition:" + childTargetPosition);
988 // Calculate scroll animation duration
989 float scrollDistance = Math.Abs(displacement);
990 readyToNotice = true;
992 AnimateChildTo(ScrollDuration, BoundScrollPosition(AdjustTargetPositionOfScrollAnimation(BoundScrollPosition(childTargetPosition))));
997 finalTargetPosition = BoundScrollPosition(childTargetPosition);
999 // Set position of scrolling child without an animation
1000 if (ScrollingDirection == Direction.Horizontal)
1002 ContentContainer.PositionX = finalTargetPosition;
1006 ContentContainer.PositionY = finalTargetPosition;
1012 /// you can override it to clean-up your own resources.
1014 /// <param name="type">DisposeTypes</param>
1015 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1016 [EditorBrowsable(EditorBrowsableState.Never)]
1017 protected override void Dispose(DisposeTypes type)
1024 if (type == DisposeTypes.Explicit)
1026 StopOverShootingShadowAnimation();
1029 if (mPanGestureDetector != null)
1031 mPanGestureDetector.Detected -= OnPanGestureDetected;
1032 mPanGestureDetector.Dispose();
1033 mPanGestureDetector = null;
1036 propertyNotification.Dispose();
1041 private float CalculateMaximumScrollDistance()
1043 float scrollingChildLength = 0;
1044 float scrollerLength = 0;
1045 if (ScrollingDirection == Direction.Horizontal)
1047 Debug.WriteLineIf(LayoutDebugScrollableBase, "Horizontal");
1049 scrollingChildLength = ContentContainer.Size.Width;
1050 scrollerLength = Size.Width;
1054 Debug.WriteLineIf(LayoutDebugScrollableBase, "Vertical");
1055 scrollingChildLength = ContentContainer.Size.Height;
1056 scrollerLength = Size.Height;
1059 Debug.WriteLineIf(LayoutDebugScrollableBase, "ScrollBy maxScrollDistance:" + (scrollingChildLength - scrollerLength) +
1060 " parent length:" + scrollerLength +
1061 " scrolling child length:" + scrollingChildLength);
1063 return Math.Max(scrollingChildLength - scrollerLength, 0);
1066 private void PageSnap(float velocity)
1070 Debug.WriteLineIf(LayoutDebugScrollableBase, "PageSnap with pan candidate totalDisplacement:" + totalDisplacementForPan +
1071 " currentPage[" + CurrentPage + "]");
1073 //Increment current page if total displacement enough to warrant a page change.
1074 if (Math.Abs(totalDisplacementForPan) > (mPageWidth * ratioOfScreenWidthToCompleteScroll))
1076 if (totalDisplacementForPan < 0)
1078 CurrentPage = Math.Min(Math.Max(Children.Count - 1, 0), ++CurrentPage);
1082 CurrentPage = Math.Max(0, --CurrentPage);
1085 else if (Math.Abs(velocity) > PageFlickThreshold)
1089 CurrentPage = Math.Min(Math.Max(Children.Count - 1, 0), ++CurrentPage);
1093 CurrentPage = Math.Max(0, --CurrentPage);
1097 // Animate to new page or reposition to current page
1098 if (ScrollingDirection == Direction.Horizontal)
1099 destination = -(Children[CurrentPage].Position.X + Children[CurrentPage].CurrentSize.Width / 2 - CurrentSize.Width / 2); // set to middle of current page
1101 destination = -(Children[CurrentPage].Position.Y + Children[CurrentPage].CurrentSize.Height / 2 - CurrentSize.Height / 2);
1103 AnimateChildTo(ScrollDuration, destination);
1107 /// Enable/Disable overshooting effect. default is disabled.
1109 [EditorBrowsable(EditorBrowsableState.Never)]
1110 public bool EnableOverShootingEffect { get; set; } = false;
1112 private void AttachOverShootingShadowView()
1114 if (!EnableOverShootingEffect)
1117 // stop animation if necessary.
1118 StopOverShootingShadowAnimation();
1120 if (ScrollingDirection == Direction.Horizontal)
1122 base.Add(leftOverShootingShadowView);
1123 base.Add(rightOverShootingShadowView);
1125 leftOverShootingShadowView.Size = new Size(0.0f, SizeHeight);
1126 leftOverShootingShadowView.Opacity = 1.0f;
1127 leftOverShootingShadowView.RaiseToTop();
1129 rightOverShootingShadowView.Size = new Size(0.0f, SizeHeight);
1130 rightOverShootingShadowView.Opacity = 1.0f;
1131 rightOverShootingShadowView.RaiseToTop();
1135 base.Add(topOverShootingShadowView);
1136 base.Add(bottomOverShootingShadowView);
1138 topOverShootingShadowView.Size = new Size(SizeWidth, 0.0f);
1139 topOverShootingShadowView.Opacity = 1.0f;
1140 topOverShootingShadowView.RaiseToTop();
1142 bottomOverShootingShadowView.Size = new Size(SizeWidth, 0.0f);
1143 bottomOverShootingShadowView.Opacity = 1.0f;
1144 bottomOverShootingShadowView.RaiseToTop();
1147 // at the beginning, height or width of overshooting shadow is 0, so it is invisible.
1148 isOverShootingShadowShown = false;
1151 private void DragOverShootingShadow(float totalPanDisplacement, float panDisplacement)
1153 if (!EnableOverShootingEffect)
1156 if (totalPanDisplacement > 0) // downwards
1158 // check if reaching at the top / left.
1159 if ((int)finalTargetPosition != 0)
1161 isOverShootingShadowShown = false;
1165 // save start displacement, and re-calculate displacement.
1166 if (!isOverShootingShadowShown)
1168 startShowShadowDisplacement = totalPanDisplacement;
1170 isOverShootingShadowShown = true;
1172 float newDisplacement = (int)totalPanDisplacement < (int)startShowShadowDisplacement ? 0 : totalPanDisplacement - startShowShadowDisplacement;
1174 if (ScrollingDirection == Direction.Horizontal)
1176 // scale limit of height is 60%.
1177 float heightScale = newDisplacement / overShootingShadowScaleHeightLimit;
1178 leftOverShootingShadowView.SizeHeight = heightScale > 0.6f ? SizeHeight * 0.4f : SizeHeight * (1.0f - heightScale);
1180 // scale limit of width is 300%.
1181 leftOverShootingShadowView.SizeWidth = newDisplacement > overShootingShadowScaleHeightLimit ? overShootingShadowScaleHeightLimit : newDisplacement;
1184 ScrollOutOfBoundEventArgs.Direction scrollDirection = panDisplacement > 0 ?
1185 ScrollOutOfBoundEventArgs.Direction.Right : ScrollOutOfBoundEventArgs.Direction.Left;
1186 OnScrollOutOfBound(scrollDirection, totalPanDisplacement);
1190 // scale limit of width is 60%.
1191 float widthScale = newDisplacement / overShootingShadowScaleHeightLimit;
1192 topOverShootingShadowView.SizeWidth = widthScale > 0.6f ? SizeWidth * 0.4f : SizeWidth * (1.0f - widthScale);
1194 // scale limit of height is 300%.
1195 topOverShootingShadowView.SizeHeight = newDisplacement > overShootingShadowScaleHeightLimit ? overShootingShadowScaleHeightLimit : newDisplacement;
1198 ScrollOutOfBoundEventArgs.Direction scrollDirection = panDisplacement > 0 ?
1199 ScrollOutOfBoundEventArgs.Direction.Down : ScrollOutOfBoundEventArgs.Direction.Up;
1200 OnScrollOutOfBound(scrollDirection, totalPanDisplacement);
1203 else if (totalPanDisplacement < 0) // upwards
1205 // check if reaching at the bottom.
1206 if (-(int)finalTargetPosition != (int)maxScrollDistance)
1208 isOverShootingShadowShown = false;
1212 // save start displacement, and re-calculate displacement.
1213 if (!isOverShootingShadowShown)
1215 startShowShadowDisplacement = totalPanDisplacement;
1217 isOverShootingShadowShown = true;
1219 float newDisplacement = (int)startShowShadowDisplacement < (int)totalPanDisplacement ? 0 : startShowShadowDisplacement - totalPanDisplacement;
1221 if (ScrollingDirection == Direction.Horizontal)
1223 // scale limit of height is 60%.
1224 float heightScale = newDisplacement / overShootingShadowScaleHeightLimit;
1225 rightOverShootingShadowView.SizeHeight = heightScale > 0.6f ? SizeHeight * 0.4f : SizeHeight * (1.0f - heightScale);
1227 // scale limit of width is 300%.
1228 rightOverShootingShadowView.SizeWidth = newDisplacement > overShootingShadowScaleHeightLimit ? overShootingShadowScaleHeightLimit : newDisplacement;
1231 ScrollOutOfBoundEventArgs.Direction scrollDirection = panDisplacement > 0 ?
1232 ScrollOutOfBoundEventArgs.Direction.Right : ScrollOutOfBoundEventArgs.Direction.Left;
1233 OnScrollOutOfBound(scrollDirection, totalPanDisplacement);
1237 // scale limit of width is 60%.
1238 float widthScale = newDisplacement / overShootingShadowScaleHeightLimit;
1239 bottomOverShootingShadowView.SizeWidth = widthScale > 0.6f ? SizeWidth * 0.4f : SizeWidth * (1.0f - widthScale);
1241 // scale limit of height is 300%.
1242 bottomOverShootingShadowView.SizeHeight = newDisplacement > overShootingShadowScaleHeightLimit ? overShootingShadowScaleHeightLimit : newDisplacement;
1245 ScrollOutOfBoundEventArgs.Direction scrollDirection = panDisplacement > 0 ?
1246 ScrollOutOfBoundEventArgs.Direction.Down : ScrollOutOfBoundEventArgs.Direction.Up;
1247 OnScrollOutOfBound(scrollDirection, totalPanDisplacement);
1252 // if total displacement is 0, shadow would become invisible.
1253 isOverShootingShadowShown = false;
1257 private void PlayOverShootingShadowAnimation()
1259 if (!EnableOverShootingEffect)
1262 // stop animation if necessary.
1263 StopOverShootingShadowAnimation();
1265 if (overShootingShadowAnimation == null)
1267 overShootingShadowAnimation = new Animation(overShootingShadowAnimationDuration);
1268 overShootingShadowAnimation.Finished += OnOverShootingShadowAnimationFinished;
1271 if (ScrollingDirection == Direction.Horizontal)
1273 View targetView = totalDisplacementForPan < 0 ? rightOverShootingShadowView : leftOverShootingShadowView;
1274 overShootingShadowAnimation.AnimateTo(targetView, "SizeHeight", SizeHeight);
1275 overShootingShadowAnimation.AnimateTo(targetView, "SizeWidth", 0.0f);
1276 overShootingShadowAnimation.AnimateTo(targetView, "Opacity", 0.0f);
1280 View targetView = totalDisplacementForPan < 0 ? bottomOverShootingShadowView : topOverShootingShadowView;
1281 overShootingShadowAnimation.AnimateTo(targetView, "SizeWidth", SizeWidth);
1282 overShootingShadowAnimation.AnimateTo(targetView, "SizeHeight", 0.0f);
1283 overShootingShadowAnimation.AnimateTo(targetView, "Opacity", 0.0f);
1285 overShootingShadowAnimation.Play();
1288 private void StopOverShootingShadowAnimation()
1290 if (overShootingShadowAnimation == null || overShootingShadowAnimation.State != Animation.States.Playing)
1293 overShootingShadowAnimation.Stop(Animation.EndActions.Cancel);
1294 OnOverShootingShadowAnimationFinished(null, null);
1295 overShootingShadowAnimation.Clear();
1298 private void OnOverShootingShadowAnimationFinished(object sender, EventArgs e)
1300 if (ScrollingDirection == Direction.Horizontal)
1302 base.Remove(leftOverShootingShadowView);
1303 base.Remove(rightOverShootingShadowView);
1305 leftOverShootingShadowView.Size = new Size(0.0f, SizeHeight);
1306 rightOverShootingShadowView.Size = new Size(0.0f, SizeHeight);
1310 base.Remove(topOverShootingShadowView);
1311 base.Remove(bottomOverShootingShadowView);
1313 topOverShootingShadowView.Size = new Size(SizeWidth, 0.0f);
1314 bottomOverShootingShadowView.Size = new Size(SizeWidth, 0.0f);
1317 // after animation finished, height/width & opacity of vertical shadow both are 0, so it is invisible.
1318 isOverShootingShadowShown = false;
1321 private void OnScrollOutOfBound(ScrollOutOfBoundEventArgs.Direction direction, float displacement)
1323 ScrollOutOfBoundEventArgs args = new ScrollOutOfBoundEventArgs(direction, displacement);
1324 ScrollOutOfBound?.Invoke(this, args);
1327 private void OnPanGestureDetected(object source, PanGestureDetector.DetectedEventArgs e)
1329 OnPanGesture(e.PanGesture);
1330 if(!((SnapToPage && scrollAnimation != null && scrollAnimation.State == Animation.States.Playing) || e.PanGesture.State == Gesture.StateType.Started))
1332 e.Handled = !((int)finalTargetPosition == 0 || -(int)finalTargetPosition == (int)maxScrollDistance);
1336 private void OnPanGesture(PanGesture panGesture)
1338 if (SnapToPage && scrollAnimation != null && scrollAnimation.State == Animation.States.Playing)
1343 if (panGesture.State == Gesture.StateType.Started)
1345 readyToNotice = false;
1346 //Interrupt touching when panning is started
1347 this.InterceptTouchEvent += OnInterruptTouchingChildTouched;
1348 AttachOverShootingShadowView();
1349 Debug.WriteLineIf(LayoutDebugScrollableBase, "Gesture Start");
1350 if (scrolling && !SnapToPage)
1354 totalDisplacementForPan = 0.0f;
1355 OnScrollDragStarted();
1357 else if (panGesture.State == Gesture.StateType.Continuing)
1359 if (ScrollingDirection == Direction.Horizontal)
1361 // if vertical shadow is shown, does not scroll.
1362 if (!isOverShootingShadowShown)
1364 ScrollBy(panGesture.Displacement.X, false);
1366 totalDisplacementForPan += panGesture.Displacement.X;
1367 DragOverShootingShadow(totalDisplacementForPan, panGesture.Displacement.X);
1371 // if vertical shadow is shown, does not scroll.
1372 if (!isOverShootingShadowShown)
1374 ScrollBy(panGesture.Displacement.Y, false);
1376 totalDisplacementForPan += panGesture.Displacement.Y;
1377 DragOverShootingShadow(totalDisplacementForPan, panGesture.Displacement.Y);
1379 Debug.WriteLineIf(LayoutDebugScrollableBase, "OnPanGestureDetected Continue totalDisplacementForPan:" + totalDisplacementForPan);
1382 else if (panGesture.State == Gesture.StateType.Finished || panGesture.State == Gesture.StateType.Cancelled)
1384 PlayOverShootingShadowAnimation();
1385 OnScrollDragEnded();
1386 StopScroll(); // Will replace previous animation so will stop existing one.
1388 if (scrollAnimation == null)
1390 scrollAnimation = new Animation();
1391 scrollAnimation.Finished += ScrollAnimationFinished;
1394 float panVelocity = (ScrollingDirection == Direction.Horizontal) ? panGesture.Velocity.X : panGesture.Velocity.Y;
1398 PageSnap(panVelocity);
1402 if (panVelocity == 0)
1404 float currentScrollPosition = (ScrollingDirection == Direction.Horizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y);
1405 scrollAnimation.DefaultAlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear);
1406 scrollAnimation.Duration = 0;
1407 scrollAnimation.AnimateTo(ContentContainer, (ScrollingDirection == Direction.Horizontal) ? "PositionX" : "PositionY", currentScrollPosition);
1408 scrollAnimation.Play();
1412 Decelerating(panVelocity, scrollAnimation);
1416 totalDisplacementForPan = 0;
1418 readyToNotice = true;
1419 OnScrollAnimationStarted();
1423 internal void BaseRemove(View view)
1428 internal override bool OnAccessibilityPan(PanGesture gestures)
1430 if (SnapToPage && scrollAnimation != null && scrollAnimation.State == Animation.States.Playing)
1435 OnPanGesture(gestures);
1439 private float CustomScrollAlphaFunction(float progress)
1441 if (panAnimationDelta == 0)
1447 // Parameter "progress" is normalized value. We need to multiply target duration to calculate distance.
1448 // Can get real distance using equation of deceleration (check Decelerating function)
1449 // After get real distance, normalize it
1450 float realDuration = progress * panAnimationDuration;
1451 float realDistance = velocityOfLastPan * ((float)Math.Pow(decelerationRate, realDuration) - 1) / logValueOfDeceleration;
1452 float result = Math.Min(realDistance / Math.Abs(panAnimationDelta), 1.0f);
1458 /// you can override it to custom your decelerating
1460 /// <param name="velocity">Velocity of current pan.</param>
1461 /// <param name="animation">Scroll animation.</param>
1462 [EditorBrowsable(EditorBrowsableState.Never)]
1463 protected virtual void Decelerating(float velocity, Animation animation)
1465 // Decelerating using deceleration equation ===========
1467 // V : velocity (pixel per millisecond)
1468 // V0 : initial velocity
1469 // d : deceleration rate,
1471 // X : final position after decelerating
1472 // log : natural logarithm
1474 // V(t) = V0 * d pow t;
1475 // X(t) = V0 * (d pow t - 1) / log d; <-- Integrate the velocity function
1476 // X(∞) = V0 * d / (1 - d); <-- Result using infinite T can be final position because T is tending to infinity.
1478 // Because of final T is tending to infinity, we should use threshold value to finish.
1479 // Final T = log(-threshold * log d / |V0| ) / log d;
1481 velocityOfLastPan = Math.Abs(velocity);
1483 float currentScrollPosition = -(ScrollingDirection == Direction.Horizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y);
1484 panAnimationDelta = (velocityOfLastPan * decelerationRate) / (1 - decelerationRate);
1485 panAnimationDelta = velocity > 0 ? -panAnimationDelta : panAnimationDelta;
1487 float destination = -(panAnimationDelta + currentScrollPosition);
1488 float adjustDestination = AdjustTargetPositionOfScrollAnimation(destination);
1489 float maxPosition = ScrollAvailableArea != null ? ScrollAvailableArea.Y : maxScrollDistance;
1490 float minPosition = ScrollAvailableArea != null ? ScrollAvailableArea.X : 0;
1492 if (destination < -maxPosition || destination > minPosition)
1494 panAnimationDelta = velocity > 0 ? (currentScrollPosition - minPosition) : (maxPosition - currentScrollPosition);
1495 destination = velocity > 0 ? minPosition : -maxPosition;
1497 if (panAnimationDelta == 0)
1499 panAnimationDuration = 0.0f;
1503 panAnimationDuration = (float)Math.Log((panAnimationDelta * logValueOfDeceleration / velocityOfLastPan + 1), decelerationRate);
1506 Debug.WriteLineIf(LayoutDebugScrollableBase, "\n" +
1507 "OverRange======================= \n" +
1508 "[decelerationRate] " + decelerationRate + "\n" +
1509 "[logValueOfDeceleration] " + logValueOfDeceleration + "\n" +
1510 "[Velocity] " + velocityOfLastPan + "\n" +
1511 "[CurrentPosition] " + currentScrollPosition + "\n" +
1512 "[CandidateDelta] " + panAnimationDelta + "\n" +
1513 "[Destination] " + destination + "\n" +
1514 "[Duration] " + panAnimationDuration + "\n" +
1515 "================================ \n"
1520 panAnimationDuration = (float)Math.Log(-DecelerationThreshold * logValueOfDeceleration / velocityOfLastPan) / logValueOfDeceleration;
1522 if (adjustDestination != destination)
1524 destination = adjustDestination;
1525 panAnimationDelta = destination + currentScrollPosition;
1526 velocityOfLastPan = Math.Abs(panAnimationDelta * logValueOfDeceleration / ((float)Math.Pow(decelerationRate, panAnimationDuration) - 1));
1527 panAnimationDuration = (float)Math.Log(-DecelerationThreshold * logValueOfDeceleration / velocityOfLastPan) / logValueOfDeceleration;
1530 Debug.WriteLineIf(LayoutDebugScrollableBase, "\n" +
1531 "================================ \n" +
1532 "[decelerationRate] " + decelerationRate + "\n" +
1533 "[logValueOfDeceleration] " + logValueOfDeceleration + "\n" +
1534 "[Velocity] " + velocityOfLastPan + "\n" +
1535 "[CurrentPosition] " + currentScrollPosition + "\n" +
1536 "[CandidateDelta] " + panAnimationDelta + "\n" +
1537 "[Destination] " + destination + "\n" +
1538 "[Duration] " + panAnimationDuration + "\n" +
1539 "================================ \n"
1543 finalTargetPosition = destination;
1545 customScrollAlphaFunction = new UserAlphaFunctionDelegate(CustomScrollAlphaFunction);
1546 animation.DefaultAlphaFunction = new AlphaFunction(customScrollAlphaFunction);
1547 GC.KeepAlive(customScrollAlphaFunction);
1548 animation.Duration = (int)panAnimationDuration;
1549 animation.AnimateTo(ContentContainer, (ScrollingDirection == Direction.Horizontal) ? "PositionX" : "PositionY", destination);
1553 private void ScrollAnimationFinished(object sender, EventArgs e)
1555 OnScrollAnimationEnded();
1559 /// Adjust scrolling position by own scrolling rules.
1560 /// Override this function when developer wants to change destination of flicking.(e.g. always snap to center of item)
1562 /// This may be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API
1563 [EditorBrowsable(EditorBrowsableState.Never)]
1564 protected virtual float AdjustTargetPositionOfScrollAnimation(float position)
1570 /// Scroll position given to ScrollTo.
1571 /// This is the position in the opposite direction to the position of ContentContainer.
1573 /// <since_tizen> 8 </since_tizen>
1574 public Position ScrollPosition
1578 return new Position(-ContentContainer.Position);
1583 /// Current scroll position in the middle of ScrollTo animation.
1584 /// This is the position in the opposite direction to the current position of ContentContainer.
1586 /// <since_tizen> 8 </since_tizen>
1587 public Position ScrollCurrentPosition
1591 return new Position(-ContentContainer.CurrentPosition);
1596 /// Remove all children in ContentContainer.
1598 /// <param name="dispose">If true, removed child is disposed.</param>
1599 [EditorBrowsable(EditorBrowsableState.Never)]
1600 public void RemoveAllChildren(bool dispose = false)
1602 RecursiveRemoveChildren(ContentContainer, dispose);
1605 private void RecursiveRemoveChildren(View parent, bool dispose)
1611 int maxChild = (int)parent.GetChildCount();
1612 for (int i = maxChild - 1; i >= 0; --i)
1614 View child = parent.GetChildAt((uint)i);
1619 RecursiveRemoveChildren(child, dispose);
1620 parent.Remove(child);
1630 [EditorBrowsable(EditorBrowsableState.Never)]
1631 public override View GetNextFocusableView(View currentFocusedView, View.FocusDirection direction, bool loopEnabled)
1633 View nextFocusedView = null;
1635 int currentIndex = ContentContainer.Children.IndexOf(currentFocusedView);
1639 case View.FocusDirection.Left:
1640 case View.FocusDirection.Up:
1642 if (currentIndex > 0)
1644 nextFocusedView = ContentContainer.Children[--currentIndex];
1648 case View.FocusDirection.Right:
1649 case View.FocusDirection.Down:
1651 if (currentIndex < ContentContainer.Children.Count - 1)
1653 nextFocusedView = ContentContainer.Children[++currentIndex];
1659 if (nextFocusedView != null)
1661 // Check next focused view is inside of visible area.
1662 // If it is not, move scroll position to make it visible.
1663 Position scrollPosition = ContentContainer.CurrentPosition;
1664 float targetPosition = -(ScrollingDirection == Direction.Horizontal ? scrollPosition.X : scrollPosition.Y);
1666 float left = nextFocusedView.Position.X;
1667 float right = nextFocusedView.Position.X + nextFocusedView.Size.Width;
1668 float top = nextFocusedView.Position.Y;
1669 float bottom = nextFocusedView.Position.Y + nextFocusedView.Size.Height;
1671 float visibleRectangleLeft = -scrollPosition.X;
1672 float visibleRectangleRight = -scrollPosition.X + Size.Width;
1673 float visibleRectangleTop = -scrollPosition.Y;
1674 float visibleRectangleBottom = -scrollPosition.Y + Size.Height;
1676 if (ScrollingDirection == Direction.Horizontal)
1678 if (left < visibleRectangleLeft)
1680 targetPosition = left;
1682 else if (right > visibleRectangleRight)
1684 targetPosition = right - Size.Width;
1689 if (top < visibleRectangleTop)
1691 targetPosition = top;
1693 else if (bottom > visibleRectangleBottom)
1695 targetPosition = bottom - Size.Height;
1698 ScrollTo(targetPosition, true);
1701 return nextFocusedView;