列車の現在地が追従するように変更

This commit is contained in:
harukin-expo-dev-env
2025-09-09 14:28:34 +00:00
parent 30c05bdee6
commit c7487d38db
2 changed files with 87 additions and 13 deletions

View File

@@ -16,7 +16,7 @@ type props = {
trainID: string; trainID: string;
}; };
export const FixedTrain:FC<props> = ({ trainID }) => { export const FixedTrain: FC<props> = ({ trainID }) => {
const { const {
fixedPosition, fixedPosition,
setFixedPosition, setFixedPosition,
@@ -178,12 +178,18 @@ export const FixedTrain:FC<props> = ({ trainID }) => {
}, [train]); }, [train]);
const [nextStationData, setNextStationData] = useState<StationProps[]>([]); const [nextStationData, setNextStationData] = useState<StationProps[]>([]);
const [untilStationData, setUntilStationData] = useState<StationProps[]>([]);
useEffect(() => { useEffect(() => {
const points = findReversalPoints(currentPosition, stopStationIDList); const points = findReversalPoints(currentPosition, stopStationIDList);
if (!points) return; if (!points) return;
if (points.length == 0) return; if (points.length == 0) return;
let searchCount = points.findIndex((d) => d == true); let searchCountBase = points.findIndex((d) => d == true);
for (searchCount; searchCount < points.length; searchCount++) { for (
let searchCount = searchCountBase;
searchCount < points.length;
searchCount++
) {
console.log(trainDataWidhThrough[searchCount]);
const nextPos = trainDataWidhThrough[searchCount]; const nextPos = trainDataWidhThrough[searchCount];
if (nextPos) { if (nextPos) {
const [station, se, time] = nextPos.split(","); const [station, se, time] = nextPos.split(",");
@@ -194,6 +200,15 @@ export const FixedTrain:FC<props> = ({ trainID }) => {
} }
} }
} }
let trainList = [];
for (
let searchCount = searchCountBase - 1;
searchCount < points.length;
searchCount++
) {
trainList.push(trainDataWidhThrough[searchCount]);
}
setUntilStationData(trainList);
}, [currentPosition, trainDataWidhThrough]); }, [currentPosition, trainDataWidhThrough]);
const [ToData, setToData] = useState(""); const [ToData, setToData] = useState("");
useEffect(() => { useEffect(() => {
@@ -350,7 +365,7 @@ export const FixedTrain:FC<props> = ({ trainID }) => {
marginHorizontal: 5, marginHorizontal: 5,
}} }}
> >
{nextStationData[0]?.Station_JP == train?.Pos ? "ただいま" : "次は"}
</Text> </Text>
<StationNumberMaker <StationNumberMaker
currentStation={nextStationData} currentStation={nextStationData}
@@ -383,12 +398,16 @@ export const FixedTrain:FC<props> = ({ trainID }) => {
></View> ></View>
</View> </View>
</View> </View>
<CurrentPositionBox train={train} lineColor={lineColor} /> <CurrentPositionBox
train={train}
lineColor={lineColor}
trainDataWithThrough={untilStationData}
/>
</TouchableOpacity> </TouchableOpacity>
); );
}; };
const CurrentPositionBox = ({ train, lineColor }) => { const CurrentPositionBox = ({ train, lineColor, trainDataWithThrough }) => {
let firstText = ""; let firstText = "";
let secondText = ""; let secondText = "";
let marginText = ""; let marginText = "";
@@ -439,12 +458,68 @@ const CurrentPositionBox = ({ train, lineColor }) => {
}} }}
></View> ></View>
</View> </View>
<Text style={{ color: "black", fontSize: 10, alignSelf: "flex-end" }}> <View style={{ flex: 1, flexDirection: "row", overflow: "hidden" }}>
{trainDataWithThrough.length > 0 &&
</Text> trainDataWithThrough.map((d, index, array) => {
<Text style={{ color: "black", fontSize: 30, alignSelf: "center" }}> if (!d) return null;
{marginText == "" ? firstText + marginText + secondText : firstText} if (d == "") return null;
</Text> const [station, se, time] = d.split(",");
return (
<>
{(index == 0 && secondText == "") || <View
style={{
flexDirection: "column",
backgroundColor: "#6e6e6eff",
borderRadius: 10,
marginHorizontal: 2,
padding: 2,
justifyContent: "center",
alignItems: "center",
overflow: "hidden",
}}
>
{station.split("").map((i, index) => {
return (
<Text
key={index}
style={{
fontSize: 6,
color: "white",
margin: 0,
padding: 0,
fontWeight: "bold",
}}
>
{i}
</Text>
);
})}
<View style={{ flex: 1 }} />
<Text style={{ fontSize: 8, color: "white" }}>
{se.includes("通") ? "" : "●"}
</Text>
</View>}
{(index == 0 && secondText != "") && (
<View
style={{
flexDirection: "column",
backgroundColor: "#6e6e6e0e",
borderRadius: 10,
marginHorizontal: 2,
padding: 2,
justifyContent: "center",
alignItems: "center",
overflow: "hidden",
}}
>
<View style={{ flex: 1 }} />
<Text style={{ fontSize: 8, color: "black" }}></Text>
</View>
)}
</>
);
})}
</View>
</View> </View>
); );
}; };

View File

@@ -147,7 +147,6 @@ export const CurrentTrainProvider = ({ children }) => {
const setInjectData = ({ type, value, fixed }) => { const setInjectData = ({ type, value, fixed }) => {
if (type === "station") { if (type === "station") {
const script = getInjectJavascriptAddress(value); const script = getInjectJavascriptAddress(value);
console.log(value);
inject(script); inject(script);
} else if (type === "train") { } else if (type === "train") {
const currentTrain = getCurrentStationData(value); const currentTrain = getCurrentStationData(value);