diff --git a/Runtime/Scripts/Layout/HorizontalScrollSnap.cs b/Runtime/Scripts/Layout/HorizontalScrollSnap.cs index f533370..1baacfd 100644 --- a/Runtime/Scripts/Layout/HorizontalScrollSnap.cs +++ b/Runtime/Scripts/Layout/HorizontalScrollSnap.cs @@ -12,6 +12,8 @@ namespace UnityEngine.UI.Extensions [AddComponentMenu("Layout/Extensions/Horizontal Scroll Snap")] public class HorizontalScrollSnap : ScrollSnapBase { + private bool updated = true; + void Start() { _isVertical = false; @@ -23,6 +25,8 @@ namespace UnityEngine.UI.Extensions void Update() { + updated = false; + if (!_lerp && _scroll_rect.velocity == Vector2.zero) { if (!_settled && !_pointerDown) @@ -243,6 +247,14 @@ namespace UnityEngine.UI.Extensions /// public override void OnEndDrag(PointerEventData eventData) { + if (updated) + { + return; + } + + // to prevent double dragging, only act on EndDrag once per frame + updated = true; + _pointerDown = false; if (_scroll_rect.horizontal) diff --git a/Runtime/Scripts/Layout/VerticalScrollSnap.cs b/Runtime/Scripts/Layout/VerticalScrollSnap.cs index a8228d8..e0c5bb0 100644 --- a/Runtime/Scripts/Layout/VerticalScrollSnap.cs +++ b/Runtime/Scripts/Layout/VerticalScrollSnap.cs @@ -12,6 +12,8 @@ namespace UnityEngine.UI.Extensions [AddComponentMenu("Layout/Extensions/Vertical Scroll Snap")] public class VerticalScrollSnap : ScrollSnapBase { + private bool updated = true; + void Start() { _isVertical = true; @@ -23,6 +25,8 @@ namespace UnityEngine.UI.Extensions void Update() { + updated = false; + if (!_lerp && _scroll_rect.velocity == Vector2.zero) { if (!_settled && !_pointerDown) @@ -236,6 +240,14 @@ namespace UnityEngine.UI.Extensions /// public override void OnEndDrag(PointerEventData eventData) { + if (updated) + { + return; + } + + // to prevent double dragging, only act on EndDrag once per frame + updated = true; + _pointerDown = false; if (_scroll_rect.vertical)