import { AnyFunction, StylesOf } from '@codeleap/types' import Animated, { useAnimatedStyle } from 'react-native-reanimated' import { Touchable } from '../Touchable' import { View } from '../View' import { DotComposition } from './styles' export type PagerDot = { onPress: AnyFunction isActive: boolean index: number styles: StylesOf } function Dot({ onPress, isActive, index, styles }: PagerDot) { /** `isActive` is a plain boolean captured by the worklet closure — this is safe because the Dot remounts when `currentPage` changes (keyed list), so the closure is never stale. If Dot were memoized across page changes this would need a SharedValue instead. */ const animation = useAnimatedStyle(() => { const scale = isActive ? 1 : 0.6 return { transform: [{ scale }], ...(isActive ? styles['dot:active'] : styles.dot), } }) return ( ) } export type PagerDots = { styles: StylesOf currentPage: number setCurrentPage: (page: number) => void pages: Array } export function PagerDots({ styles, currentPage, setCurrentPage, pages }: PagerDots) { return ( {pages?.map((_, i) => ( setCurrentPage(i)} isActive={i === currentPage} styles={styles} /> ))} ) }