diff --git a/components/Menu/StationPagination.tsx b/components/Menu/StationPagination.tsx new file mode 100644 index 0000000..d73eff1 --- /dev/null +++ b/components/Menu/StationPagination.tsx @@ -0,0 +1,166 @@ +import React, { FC, useState } from "react"; +import { View, Text, TouchableOpacity } from "react-native"; +import { Pagination } from "react-native-snap-carousel"; +import { useInterval } from "../../lib/useInterval"; + +import lineColorList from "../../assets/originData/lineColorList"; + +type StationProps = { + DispNum: string; + JrHpUrl: string; + MyStation: string; + StationMap: string; + StationNumber: string | null; + StationTimeTable: string; + Station_EN: string; + Station_JP: string; + jslodApi: string; + lat: number; + lng: number; +}; +type StationPaginationProps = { + entries: StationProps[][]; + activeSlide: number; + carouselRef: any; + setSelectedCurrentStation: React.Dispatch>; + dotButton: boolean; +}; + +export const Paginations: FC = (props) => { + const { + entries, + activeSlide, + carouselRef, + setSelectedCurrentStation, + dotButton, + } = props; + return ( + + ) + } + dotElement={ + dotButton && ( + + ) + } + /> + ); +}; +type StationNumberMakerProps = { + currentStations: StationProps[][]; + setSelectedCurrentStation: React.Dispatch>; + active?: boolean; + index?: number; +}; +export const StationNumberMaker: FC = (props) => { + const { currentStations, active, index, setSelectedCurrentStation } = props; + return ( + setSelectedCurrentStation(index)} + /> + ); +}; +type StationNumberProps = { + currentStation: StationProps[]; + active: boolean; + onPress: () => void; +}; +export const StationNumber: FC = (props) => { + const { currentStation, active, onPress } = props; + const [animation, setAnimation] = useState(0); + const data = currentStation.filter((d) => (d.StationNumber ? true : false)); + useInterval(() => { + if (!data) return; + setAnimation(animation + 1 < data.length ? animation + 1 : 0); + }, 2000); + + const lineID = data[animation].StationNumber.slice(0, 1); + const lineName = data[animation].StationNumber.slice(1); + const size = active ? 24 : 18; + const margin = active ? 3 : 6; + const border = active ? 2 : 1; + return ( + <> + {active && ( + + + + )} + + + + {lineID + "\n" + lineName} + + + + + ); +}; diff --git a/menu.js b/menu.js index eefde48..12e8695 100644 --- a/menu.js +++ b/menu.js @@ -1,5 +1,5 @@ import React, { useRef, useState, useEffect } from "react"; -import Carousel from "react-native-snap-carousel"; +import Carousel, { Pagination } from "react-native-snap-carousel"; import { Platform, View, @@ -7,6 +7,7 @@ import { Linking, Text, TouchableOpacity, + LayoutAnimation, } from "react-native"; import Constants from "expo-constants"; import * as Location from "expo-location"; @@ -31,6 +32,9 @@ import { SheetManager } from "react-native-actions-sheet"; import { useTrainDelayData } from "./stateBox/useTrainDelayData"; import { useNavigation } from "@react-navigation/native"; import { useStationList } from "./stateBox/useStationList"; +import { Paginations } from "./components/Menu/StationPagination"; +import lineColorList from "./assets/originData/lineColorList"; +import { AS } from "./storageControl"; export default function Menu({ getCurrentTrain }) { const { navigate } = useNavigation(); @@ -110,6 +114,7 @@ export default function Menu({ getCurrentTrain }) { setSelectedCurrentStation(0); return; } + console.log(allStationData) if (allStationData[selectedCurrentStation] == undefined) { const count = selectedCurrentStation - 1; setSelectedCurrentStation(count); @@ -156,6 +161,24 @@ export default function Menu({ getCurrentTrain }) { SheetManager.show("StationDetailView", { payload }); }; + const [dotButton, setDotButton] = useState(false); + + useEffect(() => { + AS.getItem("CarouselSettings/activeDotSettings").then((data) => { + setDotButton(data === "true"); + }); + }, []); + const oLPSign = () => { + LayoutAnimation.configureNext({ + duration: 600, + update: { type: "spring", springDamping: 0.5 }, + }); + AS.setItem( + "CarouselSettings/activeDotSettings", + !dotButton ? "true": "false" + ); + setDotButton(!dotButton); + } return ( {originalStationList.length != 0 && allStationData.length != 0 && ( - { - return ( - - - - ); - }} - /> + <> + { + return ( + + + + ); + }} + /> + + )} {allStationData.length != 0 && originalStationList.length != 0 &&