import React, { useRef, useState, useEffect } from "react"; import { FlatList, Image, Modal, StyleSheet, Text, TouchableOpacity, View, } from "react-native"; import { StoryType } from "./src"; const { CubeNavigationHorizontal } = require("react-native-3dcube-navigation"); import StoryContainer from "./src/StoryContainer"; type Props = { data: StoryType[]; containerAvatarStyle?: StyleSheet.Styles; avatarStyle?: StyleSheet.Styles; titleStyle?: StyleSheet.Styles; textReadMore?: string; }; const Stories = (props: Props) => { const [isModelOpen, setModel] = useState(false); const [currentUserIndex, setCurrentUserIndex] = useState(0); const [currentScrollValue, setCurrentScrollValue] = useState(0); const modalScroll = useRef(null); const onStorySelect = (index) => { setCurrentUserIndex(index); setModel(true); }; const onStoryClose = () => { setModel(false); }; const onStoryNext = (isScroll: boolean) => { const newIndex = currentUserIndex + 1; if (props.data.length - 1 > currentUserIndex) { setCurrentUserIndex(newIndex); if (!isScroll) { //erro aqui try { modalScroll.current.scrollTo(newIndex, true); } catch (e) { // console.warn("error=>", e); } } } else { setModel(false); } }; const onStoryPrevious = (isScroll: boolean) => { const newIndex = currentUserIndex - 1; if (currentUserIndex > 0) { setCurrentUserIndex(newIndex); if (!isScroll) { modalScroll.current.scrollTo(newIndex, true); } } }; const onScrollChange = (scrollValue) => { if (currentScrollValue > scrollValue) { onStoryNext(true); // console.log("next"); setCurrentScrollValue(scrollValue); } if (currentScrollValue < scrollValue) { onStoryPrevious(false); // console.log("previous"); setCurrentScrollValue(scrollValue); } }; const imageurl = 'https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_1280.png' return ( item.title} renderItem={({ item, index }) => ( onStorySelect(index)}> {item.title} )} /> { if (currentUserIndex > 0) { modalScroll.current.scrollTo(currentUserIndex, false); } }} onRequestClose={onStoryClose} > onScrollChange(g)} ref={modalScroll} style={styles.container} > {props.data.map((item, index) => ( ))} ); }; const styles = new StyleSheet.create({ boxStory: { }, ItemSeparator: { height: 1, }, container: { flex: 1, paddingBottom: 2, }, circle: { width: 50, height: 50, borderRadius: 100, borderWidth: 3, borderColor: "#FFF", }, superCircle: { borderWidth: 3, borderColor: "blue", borderRadius: 60, }, modal: { flex: 1, }, title: { fontSize: 8, textAlign: "center", }, }); export default Stories;