From 3358ce9b7a6f1b488f91f09fce5e72a8d0d3a228 Mon Sep 17 00:00:00 2001 From: yufulao <3493942038@qq.com> Date: Mon, 31 Mar 2025 18:48:09 +0800 Subject: [PATCH] Fixed the bug where ScrollTo() error jumps to the last cell when the first cell of ScrollTo is incorrectly transferred to the last element in non-loop, unrestricted, and elastic mode. --- .../Sources/Runtime/Scroller/Scroller.cs | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Assets/FancyScrollView/Sources/Runtime/Scroller/Scroller.cs b/Assets/FancyScrollView/Sources/Runtime/Scroller/Scroller.cs index 85fbff1..8db3fc0 100644 --- a/Assets/FancyScrollView/Sources/Runtime/Scroller/Scroller.cs +++ b/Assets/FancyScrollView/Sources/Runtime/Scroller/Scroller.cs @@ -597,6 +597,24 @@ float CalculateMovementAmount(float sourcePosition, float destPosition) return amount; } - float CircularPosition(float p, int size) => size < 1 ? 0 : p < 0 ? size - 1 + (p + 1) % size : p % size; + float CircularPosition(float p, int size) + { + if (size < 1) + { + return 0f; + } + + if (p >= 0) + { + return p % size; + } + + if (movementType == MovementType.Unrestricted) + { + return size - 1 + (p + 1) % size; + } + + return 0f; + } } }