import React from 'react'; import { Alert, TouchableOpacity, Text, Dimensions, StyleSheet } from 'react-native'; import { SwiperFlatList } from 'react-native-swiper-flatlist'; const { width, height } = Dimensions.get('window'); export default () => { const scrollRef = React.useRef(null); const goToLastIndex = () => { scrollRef.current?.goToLastIndex(); }; const goToFirstIndex = () => { scrollRef.current?.goToFirstIndex(); }; const goToSecondIndex = () => { scrollRef.current?.scrollToIndex({ index: 1 }); }; const getCurrentIndex = () => { const currentIndex = scrollRef.current?.getCurrentIndex(); Alert.alert(`the current index is ${currentIndex}`); }; const getPrevIndex = () => { const prevIndex = scrollRef.current?.getPrevIndex(); Alert.alert(`the previous index is ${prevIndex}`); }; const [currentIndex, setCurrentIndex] = React.useState(0); const [currentPrevIndex, setPrevIndex] = React.useState(0); return ( <> index: {currentIndex} - prevIndex: {currentPrevIndex} { console.log('example', { index, prevIndex }); setPrevIndex(prevIndex); setCurrentIndex(index); }} // TODO: rename it to children eg: "container_swiper_children" e2eID="container_swiper" > 0 - Go to last index 1 - Press to get the previous index 2 - Press to get the current index 3 - Go to the second index 4 - Go to first index ); }; const styles = StyleSheet.create({ child: { height: height * 0.5, width, justifyContent: 'center', }, text: { fontSize: width * 0.1, textAlign: 'center', }, indexText: { fontSize: 11, backgroundColor: 'trasparent', textAlign: 'center', fontWeight: 'bold', }, });