import Sign from "@/components/駅名表/Sign"; import React, { useEffect, useRef, useState } from "react"; import { AS } from "@/storageControl"; import { useWindowDimensions, View, LayoutAnimation, TouchableOpacity, Text, ScrollView, } from "react-native"; import Carousel, { ICarouselInstance } from "react-native-reanimated-carousel"; import { SheetManager } from "react-native-actions-sheet"; import { StationNumber } from "../StationPagination"; import { SimpleDot } from "../SimpleDot"; export const CarouselBox = ({ originalStationList, listUpStation, nearPositionStation, setListIndex, listIndex, navigate, stationListMode, isSearchMode }) => { const carouselRef = useRef(null); const { height, width } = useWindowDimensions(); const [dotButton, setDotButton] = useState(false); const carouselBadgeScrollViewRef = useRef(null); useEffect(() => { if (!carouselBadgeScrollViewRef.current) return; const dotSize = dotButton ? 28 : 24; const scrollToIndex = dotSize * listIndex - width / 2 + dotSize - 5; carouselBadgeScrollViewRef.current.scrollTo({ x: scrollToIndex, animated: true, }); }, [listIndex, dotButton, width, carouselBadgeScrollViewRef]); const oPSign = () => { const payload = { currentStation: listUpStation[listIndex], navigate, goTo: "menu", //@ts-ignore useShow: () => SheetManager.show("StationDetailView", { payload }), onExit: () => SheetManager.hide("StationDetailView"), }; //@ts-ignore SheetManager.show("StationDetailView", { payload }); }; const oLPSign = () => { LayoutAnimation.configureNext({ duration: 600, update: { type: "spring", springDamping: 0.5 }, }); AS.setItem( "CarouselSettings/activeDotSettings", !dotButton ? "true" : "false" ); setDotButton(!dotButton); }; useEffect(() => { AS.getItem("CarouselSettings/activeDotSettings").then((data) => { setDotButton(data === "true"); }); }, []); const RenderItem = ({ item, index }) => { return ( {item[0].StationNumber != "null" ? ( ) : ( {!!isSearchMode ? "路線検索モードです。入力欄に駅名やナンバリングを入力したり、上に並んでいる路線を選んでみましょう!" :stationListMode == "position" ? "現在地の近くに駅がありません。" : "お気に入りリストがありません。お気に入りの駅を追加しよう!"} )} ); }; return ( 0 ? listUpStation : [[{ StationNumber: "null" }]] } height={(((width / 100) * 80) / 20) * 9 + 10} pagingEnabled={true} snapEnabled={true} loop={false} width={width} style={{ width: width, alignContent: "center" }} mode="parallax" modeConfig={{ parallaxScrollingScale: 1, parallaxScrollingOffset: 100, parallaxAdjacentItemScale: 0.8, }} scrollAnimationDuration={600} onSnapToItem={setListIndex} renderItem={RenderItem} overscrollEnabled={false} defaultIndex={listIndex >= listUpStation.length ? 0 : listIndex} /> { // ScrollViewのrefを保存 if (scrollViewRef) { carouselBadgeScrollViewRef.current = scrollViewRef; } }} > {originalStationList && listUpStation.map((d, index) => { const active = index == listIndex; const numberKey = d[0].StationNumber + index; return dotButton ? ( setListIndex(index)} currentStation={d} active={active} key={numberKey} /> ) : ( setListIndex(index)} active={active} key={numberKey} /> ); })} ); };