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({ style }) {
const { webview } = useCurrentTrain();
const mapRef = useRef();
const { navigate } = useNavigation();
const [stationPin, setStationPin] = useState([]);
const {
selectedLine,
setSelectedLine,
injectJavaScript,
setInjectJavaScript,
mapsStationData: stationData,
} = 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;
if (index == 0 && stationPin.length > 0) {
setInjectJavaScript(
`MoveDisplayStation('${d}_${D.MyStation}_${D.Station_JP}');`
);
}
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: 100, left: 50, right: 50 } } // Add margin values here
);
}, [stationPin]);
return (
{stationPin.map(({ D, d, latlng, indexBase, index }) => (
))}
SheetManager.show("TrainMenuLineSelector")}
>
▲ ここを押して路線をフィルタリングできます ▲
{selectedLine
? lineListPair[stationIDPair[selectedLine]]
: "JR四国 対象全駅"}
路線記号からフィルタリング
{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");
webview.current?.injectJavaScript(injectJavaScript);
}}
top={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 (
);
};