From d9adaecfb7bb8f8e2dc2008f085a7665db6e4ccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Durmus=CC=A7=20Ali=20C=CC=A7o=CC=88llu=CC=88?= Date: Tue, 13 Nov 2018 02:32:14 +0100 Subject: [PATCH] Issue #239 fixed. https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/issues/239/swipe-threshold-value-seems-to-be-on --- Scripts/Layout/HorizontalScrollSnap.cs | 53 ++++++++++++++++++-------- Scripts/Layout/VerticalScrollSnap.cs | 52 +++++++++++++++++-------- 2 files changed, 75 insertions(+), 30 deletions(-) diff --git a/Scripts/Layout/HorizontalScrollSnap.cs b/Scripts/Layout/HorizontalScrollSnap.cs index 8ab2d17..54b4a02 100644 --- a/Scripts/Layout/HorizontalScrollSnap.cs +++ b/Scripts/Layout/HorizontalScrollSnap.cs @@ -239,31 +239,54 @@ namespace UnityEngine.UI.Extensions if (_scroll_rect.horizontal) { var distance = Vector3.Distance(_startPosition, _screensContainer.localPosition); - if ((UseFastSwipe && distance < panelDimensions.width && distance >= FastSwipeThreshold) || UseHardSwipe) - { + + if(UseHardSwipe){ _scroll_rect.velocity = Vector3.zero; - if (_startPosition.x - _screensContainer.localPosition.x > 0) + + if (distance > FastSwipeThreshold) { - if (_startPosition.x - _screensContainer.localPosition.x > _childSize / 3) - { - ScrollToClosestElement(); - } - else + if (_startPosition.x - _screensContainer.localPosition.x > 0) { NextScreen(); } - } - else - { - if (_startPosition.x - _screensContainer.localPosition.x > -_childSize / 3) - { - ScrollToClosestElement(); - } else { PreviousScreen(); } } + else + { + ScrollToClosestElement(); + } + } + else + { + if (UseFastSwipe && distance < panelDimensions.width && distance >= FastSwipeThreshold ) + { + _scroll_rect.velocity = Vector3.zero; + if (_startPosition.x - _screensContainer.localPosition.x > 0) + { + if (_startPosition.x - _screensContainer.localPosition.x > _childSize / 3) + { + ScrollToClosestElement(); + } + else + { + NextScreen(); + } + } + else + { + if (_startPosition.x - _screensContainer.localPosition.x > -_childSize / 3) + { + ScrollToClosestElement(); + } + else + { + PreviousScreen(); + } + } + } } } } diff --git a/Scripts/Layout/VerticalScrollSnap.cs b/Scripts/Layout/VerticalScrollSnap.cs index 71519a7..7599eca 100644 --- a/Scripts/Layout/VerticalScrollSnap.cs +++ b/Scripts/Layout/VerticalScrollSnap.cs @@ -239,31 +239,53 @@ namespace UnityEngine.UI.Extensions if (_scroll_rect.vertical) { var distance = Vector3.Distance(_startPosition, _screensContainer.localPosition); - if ((UseFastSwipe && distance < panelDimensions.height + FastSwipeThreshold && distance >=1f) || UseHardSwipe) - { + if(UseHardSwipe){ _scroll_rect.velocity = Vector3.zero; - if (_startPosition.y - _screensContainer.localPosition.y > 0) + + if (distance > FastSwipeThreshold) { - if (_startPosition.y - _screensContainer.localPosition.y > _childSize / 3) - { - ScrollToClosestElement(); - } - else + if (_startPosition.y - _screensContainer.localPosition.y > 0) { NextScreen(); } - } - else - { - if (_startPosition.y - _screensContainer.localPosition.y > -_childSize / 3) - { - ScrollToClosestElement(); - } else { PreviousScreen(); } } + else + { + ScrollToClosestElement(); + } + } + else + { + if (UseFastSwipe && distance < panelDimensions.height + FastSwipeThreshold && distance >=1f) + { + _scroll_rect.velocity = Vector3.zero; + if (_startPosition.y - _screensContainer.localPosition.y > 0) + { + if (_startPosition.y - _screensContainer.localPosition.y > _childSize / 3) + { + ScrollToClosestElement(); + } + else + { + NextScreen(); + } + } + else + { + if (_startPosition.y - _screensContainer.localPosition.y > -_childSize / 3) + { + ScrollToClosestElement(); + } + else + { + PreviousScreen(); + } + } + } } } }