fix: Исправлена анимация смены года
This commit is contained in:
@@ -10,7 +10,7 @@ import { HISTORICAL_PERIODS } from '@/entities/TimePeriod'
|
|||||||
import ChevronSvg from '@/shared/assets/chevron--left.svg'
|
import ChevronSvg from '@/shared/assets/chevron--left.svg'
|
||||||
import { Button } from '@/shared/ui/Button'
|
import { Button } from '@/shared/ui/Button'
|
||||||
|
|
||||||
import { ACTIVE_POSITION_ANGLE } from './constants'
|
import { ACTIVE_POSITION_ANGLE, GSAP_ANIMATION_CONFIG } from './constants'
|
||||||
import styles from './TimeFrameSlider.module.scss'
|
import styles from './TimeFrameSlider.module.scss'
|
||||||
import { CircleTimeline } from '../CircleTimeline/CircleTimeline'
|
import { CircleTimeline } from '../CircleTimeline/CircleTimeline'
|
||||||
import { EventsCarousel } from '../EventsCarousel/EventsCarousel'
|
import { EventsCarousel } from '../EventsCarousel/EventsCarousel'
|
||||||
@@ -35,16 +35,20 @@ export const TimeFrameSlider = memo(() => {
|
|||||||
const endYearRef = useRef<HTMLSpanElement>(null)
|
const endYearRef = useRef<HTMLSpanElement>(null)
|
||||||
const containerRef = useRef<HTMLDivElement>(null)
|
const containerRef = useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
// Мемоизированные константы
|
|
||||||
const totalPeriods = useMemo(() => HISTORICAL_PERIODS.length, [])
|
|
||||||
const anglePerPoint = useMemo(() => 360 / totalPeriods, [totalPeriods])
|
|
||||||
|
|
||||||
// Текущий период
|
// Текущий период
|
||||||
const currentPeriod = useMemo(
|
const currentPeriod = useMemo(
|
||||||
() => HISTORICAL_PERIODS[activePeriod],
|
() => HISTORICAL_PERIODS[activePeriod],
|
||||||
[activePeriod]
|
[activePeriod]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Мемоизированные константы
|
||||||
|
const totalPeriods = useMemo(() => HISTORICAL_PERIODS.length, [])
|
||||||
|
const anglePerPoint = useMemo(() => 360 / totalPeriods, [totalPeriods])
|
||||||
|
|
||||||
|
// Рефы для предыдущих значений периода
|
||||||
|
const prevYearFromRef = useRef(currentPeriod.yearFrom)
|
||||||
|
const prevYearToRef = useRef(currentPeriod.yearTo)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Расчет поворота при изменении активного периода
|
* Расчет поворота при изменении активного периода
|
||||||
* Использует кратчайший путь для анимации
|
* Использует кратчайший путь для анимации
|
||||||
@@ -68,22 +72,33 @@ export const TimeFrameSlider = memo(() => {
|
|||||||
|
|
||||||
const ctx = gsap.context(() => {
|
const ctx = gsap.context(() => {
|
||||||
if (startYearRef.current) {
|
if (startYearRef.current) {
|
||||||
gsap.to(startYearRef.current, {
|
gsap.fromTo(
|
||||||
innerText: currentPeriod.yearFrom,
|
startYearRef.current,
|
||||||
snap: { innerText: 1 },
|
{
|
||||||
duration: 1,
|
innerText: prevYearFromRef.current,
|
||||||
ease: 'power2.inOut',
|
},
|
||||||
})
|
{
|
||||||
|
innerText: currentPeriod.yearFrom,
|
||||||
|
...GSAP_ANIMATION_CONFIG,
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endYearRef.current) {
|
if (endYearRef.current) {
|
||||||
gsap.to(endYearRef.current, {
|
gsap.fromTo(
|
||||||
innerText: currentPeriod.yearTo,
|
endYearRef.current,
|
||||||
snap: { innerText: 1 },
|
{
|
||||||
duration: 1,
|
innerText: prevYearToRef.current,
|
||||||
ease: 'power2.inOut',
|
},
|
||||||
})
|
{
|
||||||
|
innerText: currentPeriod.yearTo,
|
||||||
|
...GSAP_ANIMATION_CONFIG,
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prevYearFromRef.current = currentPeriod.yearFrom
|
||||||
|
prevYearToRef.current = currentPeriod.yearTo
|
||||||
}, containerRef)
|
}, containerRef)
|
||||||
|
|
||||||
return () => ctx.revert()
|
return () => ctx.revert()
|
||||||
@@ -112,6 +127,7 @@ export const TimeFrameSlider = memo(() => {
|
|||||||
<div className={styles.content}>
|
<div className={styles.content}>
|
||||||
<div className={styles.centerDate}>
|
<div className={styles.centerDate}>
|
||||||
<span ref={startYearRef}>{currentPeriod.yearFrom}</span>
|
<span ref={startYearRef}>{currentPeriod.yearFrom}</span>
|
||||||
|
{'\u00A0'}
|
||||||
<span ref={endYearRef}>{currentPeriod.yearTo}</span>
|
<span ref={endYearRef}>{currentPeriod.yearTo}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -137,7 +153,7 @@ export const TimeFrameSlider = memo(() => {
|
|||||||
onClick={handlePrev}
|
onClick={handlePrev}
|
||||||
aria-label='Предыдущий период'
|
aria-label='Предыдущий период'
|
||||||
>
|
>
|
||||||
<ChevronSvg width={6.25} height={12.5} stroke='#42567A' />
|
<ChevronSvg width={9} height={14} stroke='#42567A' />
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant='round'
|
variant='round'
|
||||||
@@ -147,8 +163,8 @@ export const TimeFrameSlider = memo(() => {
|
|||||||
aria-label='Следующий период'
|
aria-label='Следующий период'
|
||||||
>
|
>
|
||||||
<ChevronSvg
|
<ChevronSvg
|
||||||
width={6.25}
|
width={9}
|
||||||
height={12.5}
|
height={14}
|
||||||
stroke='#42567A'
|
stroke='#42567A'
|
||||||
className={styles.rotated}
|
className={styles.rotated}
|
||||||
/>
|
/>
|
||||||
@@ -157,7 +173,9 @@ export const TimeFrameSlider = memo(() => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<EventsCarousel events={currentPeriod.events} visible />
|
<div className={styles.eventCarousel}>
|
||||||
|
<EventsCarousel events={currentPeriod.events} visible />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user