import React, { useRef, useState, useEffect } from "react"; import { View, Text, TouchableOpacity, Linking, Platform } from "react-native"; import MapView, { Marker } from "react-native-maps"; import Constants from "expo-constants"; import { MaterialCommunityIcons, Ionicons } from "@expo/vector-icons"; import { useCurrentTrain } from "../stateBox/useCurrentTrain"; import { useNavigation } from "@react-navigation/native"; import lineColorList from "../assets/originData/lineColorList"; import { stationIDPair } from "../lib/getStationList2"; import { lineListPair } from "../lib/getStationList"; import { SheetManager } from "react-native-actions-sheet"; import { useTrainMenu } from "../stateBox/useTrainMenu"; export default function TrainMenu({ stationData, style }) { const { webview } = useCurrentTrain(); const mapRef = useRef(); const { navigate } = useNavigation(); const [stationPin, setStationPin] = useState([]); const { selectedLine, setSelectedLine } = useTrainMenu(); useEffect(() => { const stationPinData = []; Object.keys(stationData).map((d, indexBase) => stationData[d].map((D, index) => { if (!D.StationMap) return null; if (selectedLine && selectedLine != d) return; const latlng = D.StationMap.replace( "https://www.google.co.jp/maps/place/", "" ).split(","); if (latlng.length == 0) return null; stationPinData.push({ D, d, latlng, indexBase: 0, index }); }) ); setStationPin(stationPinData); }, [stationData, selectedLine]); useEffect(() => { mapRef.current.fitToCoordinates( stationPin.map(({ latlng }) => ({ latitude: parseFloat(latlng[0]), longitude: parseFloat(latlng[1]), })), { edgePadding: { top: 100, bottom: 50, left: 50, right: 50 } } // Add margin values here ); }, [stationPin]); return ( {stationPin.map(({ D, d, latlng, indexBase, index }) => ( ))} SheetManager.show("TrainMenuLineSelector")} > {selectedLine ? lineListPair[stationIDPair[selectedLine]] : "ここを押して路線をフィルタリングできます  ▲"} 路線記号からフィルタリング {Object.keys(stationData).map((d) => ( setSelectedLine(selectedLine == d ? undefined : d)} > {stationIDPair[d]} ))} {navigate && ( navigate("howto", { info: "https://train.jr-shikoku.co.jp/usage.htm", }) } > 使い方 navigate("favoriteList")} > お気に入り Linking.openURL( "https://nexcloud.haruk.in/apps/forms/ZRHjWFF7znr5Xjr2" ) } > フィードバック )} navigate("Apps")} top={Platform.OS == "ios" ? Constants.statusBarHeight : 0} mapSwitch={"flex"} /> ); } const UsefulBox = (props) => { const { icon, backgroundColor, flex, onPressButton, children } = props; return ( {children} ); }; const MapPin = ({ index, indexBase, latlng, D, d, navigate, webview }) => { return ( { webview.current?.injectJavaScript( `MoveDisplayStation('${d}_${D.MyStation}_${D.Station_JP}'); document.getElementById("disp").insertAdjacentHTML("afterbegin", "
");` ); if (navigate) navigate("Apps"); }} > ); }; const MapsButton = ({ onPress, top, mapSwitch }) => { const styles = { touch: { position: "absolute", top, left: 10, width: 50, height: 50, backgroundColor: "#0099CC", borderColor: "white", borderStyle: "solid", borderWidth: 1, borderRadius: 50, alignContent: "center", alignSelf: "center", alignItems: "center", display: mapSwitch, }, text: { textAlign: "center", width: "auto", height: "auto", textAlignVertical: "center", fontWeight: "bold", color: "white", }, }; return ( ); };