import React, {useState} from 'react'; import {Image, StyleSheet, TouchableOpacity, View} from 'react-native'; import Carousel from 'react-native-reanimated-carousel'; const CAROUSEL_ASPECT_RATIO = 350 / 80; // 轮播图宽高比 const INDEX_BACKGROUND_CURRENT = '#FFFFFF'; const INDEX_BACKGROUND = 'rgba(255, 255, 255, 0.6)'; type Props = { width: number; // 轮播图宽度 data: {imgUrl: string}[]; // 数据的数组 onPress?: (index: number) => void; // 点击事件 }; /** * @description: 首页轮播图 */ export default function HomeCarousel(props: Props) { const [currentIndex, setCurrentIndex] = useState(0); return ( { setCurrentIndex(index); }} renderItem={({index}) => { return ( { props.onPress && props.onPress(index); }}> ); }} /> {props.data.map((_item, index) => { return ( ); })} ); } const styles = StyleSheet.create({ carousel: { borderRadius: 10, backgroundColor: '#FFFFFF', }, indexView: { position: 'absolute', bottom: 0, left: 0, right: 0, height: 7.5, }, indexContent: { flex: 1, flexDirection: 'row', justifyContent: 'center', }, indexItem: { flexShrink: 1, width: 7.5, height: 2.5, marginHorizontal: 1.5, borderRadius: 2, }, });