import * as React from 'react'; import { Pressable } from 'react-native'; import Animated, { Extrapolate, interpolate, interpolateColor, useAnimatedStyle, useSharedValue, withTiming, } from 'react-native-reanimated'; import Carousel, { ICarouselInstance } from 'rn-animated-carousel'; import { Colors, View } from 'react-native-ui-lib'; import SButton from '../components/SButton'; import { ElementsText, window } from '../constants'; import { useToggleButton } from '../hooks/useToggleButton'; const PAGE_WIDTH = 60; const PAGE_HEIGHT = 40; const DATA = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']; function Index() { const r = React.useRef(null); const AutoPLay = useToggleButton({ defaultValue: false, buttonTitle: ElementsText.AUTOPLAY, }); const [loop, setLoop] = React.useState(false); return ( { return ( r.current?.scrollTo({ count: animationValue.value, animated: true, }) } /> ); }} autoPlay={AutoPLay.status} /> {AutoPLay.button} setLoop(!loop)}>{`Loop: ${loop}`} r.current?.prev()}>{'Prev'} r.current?.next()}>{'Next'} ); } export default Index; interface Props { animationValue: Animated.SharedValue; label: string; onPress?: () => void; } const Item: React.FC = (props) => { const { animationValue, label, onPress } = props; const translateY = useSharedValue(0); const containerStyle = useAnimatedStyle(() => { const opacity = interpolate( animationValue.value, [-1, 0, 1], [0.5, 1, 0.5], Extrapolate.CLAMP ); return { opacity, }; }, [animationValue]); const labelStyle = useAnimatedStyle(() => { const scale = interpolate( animationValue.value, [-1, 0, 1], [1, 1.25, 1], Extrapolate.CLAMP ); const color = interpolateColor( animationValue.value, [-1, 0, 1], [Colors.grey30, Colors.blue30, Colors.grey30] ); return { transform: [{ scale }, { translateY: translateY.value }], color, }; }, [animationValue, translateY]); const onPressIn = React.useCallback(() => { translateY.value = withTiming(-8, { duration: 250 }); }, [translateY]); const onPressOut = React.useCallback(() => { translateY.value = withTiming(0, { duration: 250 }); }, [translateY]); return ( {label} ); };