import * as React from 'react'; import { View } from 'react-native'; import Carousel from 'rn-animated-carousel'; import Animated, { Extrapolate, interpolate, useAnimatedStyle, useSharedValue, } from 'react-native-reanimated'; import SButton from '../components/SButton'; import { SBItem } from '../components/SBItem'; import { ElementsText, window } from '../constants'; const PAGE_WIDTH = window.width; const colors = [ '#26292E', '#899F9C', '#B3C680', '#5C6265', '#F5D399', '#F1F1F1', ]; function Index() { const [isVertical, setIsVertical] = React.useState(false); const [autoPlay, setAutoPlay] = React.useState(false); const [pagingEnabled, setPagingEnabled] = React.useState(true); const [snapEnabled, setSnapEnabled] = React.useState(true); const progressValue = useSharedValue(0); const baseOptions = isVertical ? ({ vertical: true, width: PAGE_WIDTH, height: PAGE_WIDTH * 0.6, } as const) : ({ vertical: false, width: PAGE_WIDTH, height: PAGE_WIDTH * 0.6, } as const); return ( (progressValue.value = absoluteProgress) } mode="parallax" modeConfig={{ parallaxScrollingScale: 0.9, parallaxScrollingOffset: 50, }} data={colors} renderItem={({ index }) => } /> {!!progressValue && ( {colors.map((backgroundColor, index) => { return ( ); })} )} setAutoPlay(!autoPlay)} >{`${ElementsText.AUTOPLAY}:${autoPlay}`} { setIsVertical(!isVertical); }} > {isVertical ? 'Set horizontal' : 'Set Vertical'} { setPagingEnabled(!pagingEnabled); }} > {`pagingEnabled:${pagingEnabled}`} { setSnapEnabled(!snapEnabled); }} > {`snapEnabled:${snapEnabled}`} ); } const PaginationItem: React.FC<{ index: number; backgroundColor: string; length: number; animValue: Animated.SharedValue; isRotate?: boolean; }> = (props) => { const { animValue, index, length, backgroundColor, isRotate } = props; const width = 10; const animStyle = useAnimatedStyle(() => { let inputRange = [index - 1, index, index + 1]; let outputRange = [-width, 0, width]; if (index === 0 && animValue?.value > length - 1) { inputRange = [length - 1, length, length + 1]; outputRange = [-width, 0, width]; } return { transform: [ { translateX: interpolate( animValue?.value, inputRange, outputRange, Extrapolate.CLAMP ), }, ], }; }, [animValue, index, length]); return ( ); }; export default Index;