diff --git a/Scripts/Layout/HorizontalScrollSnap.cs b/Scripts/Layout/HorizontalScrollSnap.cs index 58b3578..b8361c3 100644 --- a/Scripts/Layout/HorizontalScrollSnap.cs +++ b/Scripts/Layout/HorizontalScrollSnap.cs @@ -43,19 +43,22 @@ namespace UnityEngine.UI.Extensions } CurrentPage = GetPageforPosition(_screensContainer.localPosition); - + //If the container is moving check if it needs to settle on a page - if (!_pointerDown && (_scroll_rect.velocity.x > 0.01 || _scroll_rect.velocity.x < 0.01)) + if (!_pointerDown) { - // if the pointer is released and is moving slower than the threshold, then just land on a page - if (IsRectMovingFasterThanThreshold(0)) + if (_scroll_rect.velocity.x > 0.01 || _scroll_rect.velocity.x < 0.01) { - ScrollToClosestElement(); + //if the pointer is released and is moving slower than the threshold, then just land on a page + if (IsRectMovingSlowerThanThreshold(0)) + { + ScrollToClosestElement(); + } } } } - private bool IsRectMovingFasterThanThreshold(float startingSpeed) + private bool IsRectMovingSlowerThanThreshold(float startingSpeed) { return (_scroll_rect.velocity.x > startingSpeed && _scroll_rect.velocity.x < SwipeVelocityThreshold) || (_scroll_rect.velocity.x < startingSpeed && _scroll_rect.velocity.x > -SwipeVelocityThreshold); @@ -195,6 +198,8 @@ namespace UnityEngine.UI.Extensions /// public void OnEndDrag(PointerEventData eventData) { + _pointerDown = false; + if (_scroll_rect.horizontal) { if (UseFastSwipe) diff --git a/Scripts/Layout/ScrollSnapBase.cs b/Scripts/Layout/ScrollSnapBase.cs index 67fabf2..34c81ce 100644 --- a/Scripts/Layout/ScrollSnapBase.cs +++ b/Scripts/Layout/ScrollSnapBase.cs @@ -4,7 +4,7 @@ using UnityEngine.EventSystems; namespace UnityEngine.UI.Extensions { - public class ScrollSnapBase : MonoBehaviour, IBeginDragHandler, IDragHandler, IPointerDownHandler, IPointerUpHandler + public class ScrollSnapBase : MonoBehaviour, IBeginDragHandler, IDragHandler { internal RectTransform _screensContainer; internal bool _isVertical; @@ -404,6 +404,7 @@ namespace UnityEngine.UI.Extensions /// public void OnBeginDrag(PointerEventData eventData) { + _pointerDown = true; _settled = false; StartScreenChange(); _startPosition = _screensContainer.localPosition; @@ -418,15 +419,6 @@ namespace UnityEngine.UI.Extensions _lerp = false; } - public void OnPointerDown(PointerEventData eventData) - { - _pointerDown = true; - } - - public void OnPointerUp(PointerEventData eventData) - { - _pointerDown = false; - } #endregion } } \ No newline at end of file diff --git a/Scripts/Layout/VerticalScrollSnap.cs b/Scripts/Layout/VerticalScrollSnap.cs index 0d92abb..b563b46 100644 --- a/Scripts/Layout/VerticalScrollSnap.cs +++ b/Scripts/Layout/VerticalScrollSnap.cs @@ -45,16 +45,23 @@ namespace UnityEngine.UI.Extensions CurrentPage = GetPageforPosition(_screensContainer.localPosition); //If the container is moving check if it needs to settle on a page - if (!_pointerDown && (_scroll_rect.velocity.y > 0.01 || _scroll_rect.velocity.y < -0.01)) + if (!_pointerDown) { - // if the pointer is released and is moving slower than the threshold, then just land on a page - if ((_scroll_rect.velocity.y > 0 && _scroll_rect.velocity.y < SwipeVelocityThreshold) || - (_scroll_rect.velocity.y < 0 && _scroll_rect.velocity.y > -SwipeVelocityThreshold)) - { - ScrollToClosestElement(); + if (_scroll_rect.velocity.y > 0.01 || _scroll_rect.velocity.y < -0.01) + { + // if the pointer is released and is moving slower than the threshold, then just land on a page + if (IsRectMovingSlowerThanThreshold(0)) + { + ScrollToClosestElement(); + } } } + } + private bool IsRectMovingSlowerThanThreshold(float startingSpeed) + { + return (_scroll_rect.velocity.y > startingSpeed && _scroll_rect.velocity.y < SwipeVelocityThreshold) || + (_scroll_rect.velocity.y < startingSpeed && _scroll_rect.velocity.y > -SwipeVelocityThreshold); } public void DistributePages() @@ -191,6 +198,8 @@ namespace UnityEngine.UI.Extensions /// public void OnEndDrag(PointerEventData eventData) { + _pointerDown = false; + if (_scroll_rect.vertical) { if (UseFastSwipe)