From 17d59d8b94321620e9fe54127b02786912737828 Mon Sep 17 00:00:00 2001 From: Kakabay <2kakabayashyrberdyew@gmail.com> Date: Tue, 24 Dec 2024 17:58:33 +0500 Subject: [PATCH] counter reversed --- .../lottery/RollingCounter/RollingCounter.tsx | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/components/lottery/RollingCounter/RollingCounter.tsx b/components/lottery/RollingCounter/RollingCounter.tsx index e775e5c..9d5ee9c 100644 --- a/components/lottery/RollingCounter/RollingCounter.tsx +++ b/components/lottery/RollingCounter/RollingCounter.tsx @@ -9,14 +9,26 @@ interface RollingCounterProps { // Move constants outside component const ROLLS = 2; const DIGIT_HEIGHT = 104; -const INITIAL_OFFSET = 38; +const EXTRA_NUMBERS_BEFORE = 2; const EXTRA_NUMBERS_AFTER = 5; +const CONTAINER_HEIGHT = 180; +const INITIAL_OFFSET = (CONTAINER_HEIGHT - DIGIT_HEIGHT) / 2 - DIGIT_HEIGHT * 2; // Memoize number generation function const getNumbers = (targetValue: number) => { const numbers = []; - // Add complete rolls + // Add extra numbers before + for (let n = 10 - EXTRA_NUMBERS_BEFORE; n < 10; n++) { + numbers.push(n); + } + + // Start with zeros + for (let n = 0; n <= targetValue; n++) { + numbers.push(n); + } + + // Add complete rolls after the initial sequence for (let i = 0; i < ROLLS; i++) { for (let n = 0; n < 10; n++) { numbers.push(n); @@ -42,12 +54,14 @@ const RollingDigit = ({ onAnimationComplete, isStopped, showHyphen, + totalDigits, }: { targetValue: number; index: number; onAnimationComplete: () => void; isStopped: boolean; showHyphen: boolean; + totalDigits: number; }) => { const numbers = useMemo(() => getNumbers(targetValue), [targetValue]); @@ -57,11 +71,11 @@ const RollingDigit = ({ = ({ numberString }) => { onAnimationComplete={() => handleAnimationComplete(index)} isStopped={isStopped[index]} showHyphen={(index + 1) % 2 === 0 && index !== numbers.length - 1} + totalDigits={numbers.length} /> ))}