貨物の追加とフォント指定の動的化
This commit is contained in:
parent
a33ffb013e
commit
0c002c443d
@ -37,18 +37,79 @@ export const HeaderText: FC<Props> = ({
|
|||||||
from,
|
from,
|
||||||
fontLoaded,
|
fontLoaded,
|
||||||
}) => {
|
}) => {
|
||||||
const [typeName, trainName] = useMemo(() => {
|
const { limited, trainNum } = data;
|
||||||
if (!data.limited) return "";
|
|
||||||
const limitedArray = data.limited.split(":");
|
|
||||||
const type = getType(limitedArray[0]);
|
|
||||||
|
|
||||||
|
// 貨物の判定
|
||||||
|
const freightDetect = (num:string)=>{
|
||||||
|
switch(num){
|
||||||
|
case "71":
|
||||||
|
return "貨物 東京(タ)→高松(タ)";
|
||||||
|
case "73":
|
||||||
|
case "75":
|
||||||
|
return "貨物 大阪(タ)→高松(タ)";
|
||||||
|
case "3079":
|
||||||
|
return "貨物 高松(タ)→伊予三島";
|
||||||
|
case "3071":
|
||||||
|
case "3077":
|
||||||
|
return "貨物 高松(タ)→新居浜";
|
||||||
|
case "3073":
|
||||||
|
return "貨物 高松(タ)→松山貨物";
|
||||||
|
case "70":
|
||||||
|
return "貨物 高松(タ)→東京(タ)";
|
||||||
|
case "74":
|
||||||
|
case "76":
|
||||||
|
return "貨物 高松(タ)→大阪(タ)";
|
||||||
|
case "3078":
|
||||||
|
return "貨物 伊予三島→高松(タ)";
|
||||||
|
case "3070":
|
||||||
|
return "貨物 新居浜→高松(タ)";
|
||||||
|
case "3076":
|
||||||
|
return "貨物 新居浜→高松(タ)";
|
||||||
|
case "3072":
|
||||||
|
return "貨物 松山貨物→高松(タ)";
|
||||||
|
case "9070":
|
||||||
|
return "貨物 臨時";
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 列車名、種別、フォントの取得
|
||||||
|
const [typeName, trainName, fontAvailable] = useMemo(() => {
|
||||||
|
if (!limited) return "";
|
||||||
|
const limitedArray = limited.split(":");
|
||||||
|
const [type, fontAvailable] = (() => {
|
||||||
|
const d = getType(limitedArray[0]);
|
||||||
|
switch (true) {
|
||||||
|
case !!d:
|
||||||
|
return [d, true];
|
||||||
|
case !!trainNum.includes("T"):
|
||||||
|
return ["単機回送", false];
|
||||||
|
case !!trainNum.includes("R"):
|
||||||
|
case !!trainNum.includes("E"):
|
||||||
|
case !!trainNum.includes("L"):
|
||||||
|
case !!trainNum.includes("A"):
|
||||||
|
case !!trainNum.includes("B"):
|
||||||
|
return ["回送", false];
|
||||||
|
case !!trainNum.includes("H"):
|
||||||
|
return ["試運転", false];
|
||||||
|
case !!trainNum.match("D"):
|
||||||
|
case !!trainNum.match("M"):
|
||||||
|
return ["普通", true];
|
||||||
|
case !!freightDetect(trainNum):
|
||||||
|
return [freightDetect(trainNum), false];
|
||||||
|
default:
|
||||||
|
return ["", false];
|
||||||
|
}
|
||||||
|
})();
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case !!limitedArray[1]:
|
case !!limitedArray[1]:
|
||||||
// 特急の場合は、列車名を取得
|
// 特急の場合は、列車名を取得
|
||||||
return [type, migrateTrainName(limitedArray[1])];
|
return [type, migrateTrainName(limitedArray[1]), fontAvailable];
|
||||||
case trainData.length == 0:
|
case trainData.length == 0:
|
||||||
// 特急以外の場合は、列車番号を取得
|
// 特急以外の場合は、列車番号を取得
|
||||||
return [type, ""];
|
|
||||||
|
return [type, "", fontAvailable];
|
||||||
default:
|
default:
|
||||||
// 行先がある場合は、行先を取得
|
// 行先がある場合は、行先を取得
|
||||||
return [
|
return [
|
||||||
@ -56,87 +117,47 @@ export const HeaderText: FC<Props> = ({
|
|||||||
migrateTrainName(
|
migrateTrainName(
|
||||||
trainData[trainData.length - 1].split(",")[0] + "行き"
|
trainData[trainData.length - 1].split(",")[0] + "行き"
|
||||||
),
|
),
|
||||||
|
fontAvailable,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}, [data.limited, trainData]);
|
}, [limited, trainData]);
|
||||||
|
|
||||||
|
// 1人運転の判定
|
||||||
|
const isOneMan = useMemo(() => {
|
||||||
|
const OneManRegex = new RegExp(/^4[1-9]\d\d[DM]$/);
|
||||||
|
const OneManRegex2 = new RegExp(/^5[1-7]\d\d[DM]$/);
|
||||||
|
return !!(
|
||||||
|
OneManRegex.test(trainNum) ||
|
||||||
|
OneManRegex2.test(trainNum) ||
|
||||||
|
trainNum === "3621D"
|
||||||
|
);
|
||||||
|
}, [trainNum]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={{ padding: 10, flexDirection: "row", alignItems: "center" }}>
|
<View style={{ padding: 10, flexDirection: "row", alignItems: "center" }}>
|
||||||
<TrainIconStatus {...{ data, navigate, from }} />
|
<TrainIconStatus {...{ data, navigate, from }} />
|
||||||
<View
|
<View
|
||||||
style={{ borderRadius: 5, flexDirection: "row", alignItems: "center" }}
|
style={{ borderRadius: 5, flexDirection: "row", alignItems: "center" }}
|
||||||
>
|
>
|
||||||
{fontLoaded ? (
|
|
||||||
<>
|
|
||||||
<Text
|
|
||||||
style={{
|
|
||||||
fontSize: 20,
|
|
||||||
color: "white",
|
|
||||||
fontFamily: !!typeName ? "JR-Nishi" : undefined,
|
|
||||||
marginRight: 5,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{(() => {
|
|
||||||
if (!!typeName) return typeName;
|
|
||||||
switch (true) {
|
|
||||||
case !!data.trainNum.includes("T"):
|
|
||||||
return "単機回送";
|
|
||||||
case !!data.trainNum.includes("R"):
|
|
||||||
case !!data.trainNum.includes("E"):
|
|
||||||
case !!data.trainNum.includes("L"):
|
|
||||||
case !!data.trainNum.includes("A"):
|
|
||||||
case !!data.trainNum.includes("B"):
|
|
||||||
return "回送";
|
|
||||||
case !!data.trainNum.includes("H"):
|
|
||||||
return "試運転";
|
|
||||||
case !!data.trainNum.match("D"):
|
|
||||||
case !!data.trainNum.match("M"):
|
|
||||||
return "普通";
|
|
||||||
default:
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
})()}
|
|
||||||
</Text>
|
|
||||||
{!!(
|
|
||||||
new RegExp(/^4[1-9]\d\d[DM]$/).test(data.trainNum) ||
|
|
||||||
new RegExp(/^5[1-7]\d\d[DM]$/).test(data.trainNum) ||
|
|
||||||
data.trainNum === "3621D"
|
|
||||||
) && <OneManText />}
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<Text
|
|
||||||
style={{
|
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: "bold",
|
|
||||||
color: "white",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{typeName}
|
|
||||||
</Text>
|
|
||||||
)}
|
|
||||||
<Text
|
<Text
|
||||||
style={{
|
style={{
|
||||||
fontSize: 18,
|
fontSize: 20,
|
||||||
fontWeight: "bold",
|
|
||||||
textShadowColor: "white",
|
|
||||||
textShadowOffset: { width: 0, height: 0 },
|
|
||||||
textShadowRadius: 0,
|
|
||||||
color: "white",
|
color: "white",
|
||||||
|
fontFamily: fontAvailable ? "JR-Nishi" : undefined,
|
||||||
|
fontWeight: !fontAvailable ?"bold":undefined,
|
||||||
|
marginRight: 5,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{trainName}
|
{typeName}
|
||||||
</Text>
|
</Text>
|
||||||
|
{isOneMan && <OneManText />}
|
||||||
|
<Text style={textConfig}>{trainName}</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<View style={{ flex: 1 }} />
|
<View style={{ flex: 1 }} />
|
||||||
<Text
|
<Text style={textConfig}>
|
||||||
style={{
|
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: "bold",
|
|
||||||
color: "white",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{showHeadStation.map((d) => `${headStation[d].id} + `)}
|
{showHeadStation.map((d) => `${headStation[d].id} + `)}
|
||||||
{data.trainNum}
|
{trainNum}
|
||||||
{showTailStation.map((d) => ` + ${tailStation[d].id}`)}
|
{showTailStation.map((d) => ` + ${tailStation[d].id}`)}
|
||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user