暫定的に動作するように変更

This commit is contained in:
harukin-expo-dev-env
2025-09-01 11:55:40 +00:00
parent eda1d10c0c
commit ac11117fd6
3 changed files with 60 additions and 41 deletions

View File

@@ -25,7 +25,7 @@ export const TrainDataView = ({
const { width, height } = useWindowDimensions();
const { isLandscape } = useDeviceOrientationChange();
const { inject } = useCurrentTrain();
const { setInjectData } = useCurrentTrain();
const { allCustomTrainData } = useAllTrainDiagram();
const [mapsStationData, setMapsStationData] = useState(undefined);
@@ -150,27 +150,18 @@ export const TrainDataView = ({
<TouchableOpacity
style={{ flex: 1, flexDirection: "row" }}
//disabled={!onLine}
onLongPress={openEditWindow}
//onLongPress={openEditWindow}
onLongPress={()=>{
if (!onLine) return;
setInjectData({ type:"train", value:currentTrainData?.num, fixed:true});
navigate("positions", { screen: "Apps" });
SheetManager.hide("EachTrainInfo");
}}
onPress={() => {
if (!onLine) return;
const test = [];
Object.keys(mapsStationData).forEach((d) => {
mapsStationData[d].forEach((x) => {
if (x.StationNumber == currentPosition[0])
test.push({ line: d, station: x });
});
if (currentPosition[0] == "M12") {
test.push({
line: "seto",
station: { Station_JP: "児島", MyStation: "0" },
});
}
});
if (!test.length) return;
setInjectData({ type: "station", value: currentPosition[0], fixed: false });
navigate("positions", { screen: "Apps" });
inject(
`MoveDisplayStation('${test[0].line}_${test[0].station.MyStation}_${test[0].station.Station_JP}');document.getElementById("disp").insertAdjacentHTML("afterbegin", "<div />");`
);
SheetManager.hide("EachTrainInfo");
}}
>

View File

@@ -4,6 +4,7 @@ import {
Platform,
useWindowDimensions,
LayoutAnimation,
Text,
} from "react-native";
import Constants from "expo-constants";
import * as Updates from "expo-updates";
@@ -30,7 +31,7 @@ var Status = StatusbarDetect(); */
const top = Platform.OS == "ios" ? Constants.statusBarHeight : 0;
export default function Apps() {
const { webview } = useCurrentTrain();
const { webview, fixedPosition, setFixedPosition } = useCurrentTrain();
const { height, width } = useWindowDimensions();
const { navigate } = useNavigation();
const { isLandscape } = useDeviceOrientationChange();
@@ -125,6 +126,16 @@ export default function Apps() {
}}
/>
)}
{fixedPosition.type && (
<Text
onPress={() => {
setFixedPosition({ type: null, value: null });
}}
>
{fixedPosition.type}: {fixedPosition.value}
</Text>
)}
{mapSwitch == "true" ? (
<ReloadButton
onPress={() => Updates.reloadAsync()}

View File

@@ -47,15 +47,25 @@ export const CurrentTrainProvider = ({ children }) => {
() => {
if (!webview.current) return;
if (fixedPosition.type == "station") {
alert("stationに移動");
const script = getInjectJavascriptAddress(fixedPosition.value);
inject(script);
}
else if(fixedPosition.type == "train"){
} else if (fixedPosition.type == "train") {
const currentTrain = getCurrentStationData(fixedPosition.value);
const values = getPosition(currentTrain);
if (!values) return;
if (values[0] == "M12" || values[1] == "M12") {
const script = getInjectJavascriptAddress("M12");
inject(script);
return;
}
const script = getInjectJavascriptAddress(
values[values.length == 2 ? currentTrain.Direction : 0]
);
inject(script);
}
},
60000,
5000, //60000,
false
);
useEffect(() => {
@@ -66,7 +76,6 @@ export const CurrentTrainProvider = ({ children }) => {
}
}, [fixedPosition]);
const getPosition = (currentTrainData) => {
console.log(currentTrainData);
//currentTrainData.Pos = "鴨川~端岡"; //test
if (!currentTrainData) return;
if (!currentTrainData?.Pos) return;
@@ -127,22 +136,6 @@ export const CurrentTrainProvider = ({ children }) => {
return [getStationID(currentTrainData?.Pos, stationList)];
}
};
const setInjectData = ({ type, value, fixed }) => {
if (type === "station") {
const script = getInjectJavascriptAddress(value);
console.log(value);
inject(script);
if (fixed) {
setFixedPosition({ type, value: value });
}
} else if (type === "station") {
const script = getInjectJavascriptAddress(value);
inject(script);
if (fixed) {
setFixedPosition(script);
}
}
};
const getCurrentStationData = (e) => {
//e:trainNumber
if (!currentTrain.length) return;
@@ -151,6 +144,28 @@ export const CurrentTrainProvider = ({ children }) => {
stationList
);
};
const setInjectData = ({ type, value, fixed }) => {
if (type === "station") {
const script = getInjectJavascriptAddress(value);
console.log(value);
inject(script);
} else if (type === "train") {
const currentTrain = getCurrentStationData(value);
const values = getPosition(currentTrain);
if (!values) return;
let script;
if (values[0] == "M12" || values[1] == "M12") {
script = getInjectJavascriptAddress("M12");
} else {
const valuesIndex = values.length == 2 ? currentTrain.Direction : 0;
script = getInjectJavascriptAddress(values[valuesIndex]);
}
inject(script);
}
if (fixed) {
setFixedPosition({ type, value });
}
};
const getCurrentTrain = () => {
fetch("https://n8n.haruk.in/webhook/c501550c-7d1b-4e50-927b-4429fe18931a")
.then((response) => response.json())
@@ -215,6 +230,8 @@ export const CurrentTrainProvider = ({ children }) => {
setInjectData,
getCurrentStationData,
getPosition,
fixedPosition,
setFixedPosition,
}}
>
{children}