Merge commit 'c0cdad36837f27dee7c22930834272052d53d090'

This commit is contained in:
harukin-expo-dev-env 2024-03-09 15:48:41 +00:00
commit 34dc62aee6
47 changed files with 3961 additions and 2180 deletions

90
App.js
View File

@ -1,35 +1,24 @@
import React, { useEffect } from "react";
import { NavigationContainer } from "@react-navigation/native";
import { createStackNavigator } from "@react-navigation/stack";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import { Platform, UIManager } from "react-native";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { UpdateAsync } from "./UpdateAsync.js";
import { AS } from "./storageControl";
import TNDView from "./ndView";
import { LogBox } from "react-native";
import useInterval from "./lib/useInterval";
import { HeaderConfig } from "./lib/HeaderConfig";
import { initIcon } from "./lib/initIcon";
import {
useFavoriteStation,
FavoriteStationProvider,
} from "./stateBox/useFavoriteStation";
import { FavoriteStationProvider } from "./stateBox/useFavoriteStation";
import { Top } from "./Top.js";
import { MenuPage } from "./MenuPage.js";
import {
useCurrentTrain,
CurrentTrainProvider,
} from "./stateBox/useCurrentTrain.js";
import { CurrentTrainProvider } from "./stateBox/useCurrentTrain.js";
import { useAreaInfo, AreaInfoProvider } from "./stateBox/useAreaInfo.js";
import {
useBusAndTrainData,
BusAndTrainDataProvider,
} from "./stateBox/useBusAndTrainData.js";
import { BusAndTrainDataProvider } from "./stateBox/useBusAndTrainData.js";
import { AllTrainDiagramProvider } from "./stateBox/useAllTrainDiagram.js";
import { SheetProvider } from "react-native-actions-sheet";
import "./components/ActionSheetComponents/sheets.js";
import { TrainDelayDataProvider } from "./stateBox/useTrainDelayData.js";
import { SafeAreaProvider } from "react-native-safe-area-context";
import { DeviceOrientationChangeProvider } from "./stateBox/useDeviceOrientationChange.js";
LogBox.ignoreLogs([
"ViewPropTypes will be removed",
"ColorPropType will be removed",
@ -44,54 +33,31 @@ if (Platform.OS === "android") {
export default function App() {
useEffect(() => UpdateAsync(), []);
return (
<SafeAreaProvider>
<FavoriteStationProvider>
<TrainDelayDataProvider>
<CurrentTrainProvider>
<AreaInfoProvider>
<AllTrainDiagramProvider>
<BusAndTrainDataProvider>
<SheetProvider>
<AppContainer />
</SheetProvider>
</BusAndTrainDataProvider>
</AllTrainDiagramProvider>
</AreaInfoProvider>
</CurrentTrainProvider>
</TrainDelayDataProvider>
</FavoriteStationProvider>
</SafeAreaProvider>
<DeviceOrientationChangeProvider>
<SafeAreaProvider>
<GestureHandlerRootView style={{ flex: 1 }}>
<FavoriteStationProvider>
<TrainDelayDataProvider>
<CurrentTrainProvider>
<AreaInfoProvider>
<AllTrainDiagramProvider>
<BusAndTrainDataProvider>
<SheetProvider>
<AppContainer />
</SheetProvider>
</BusAndTrainDataProvider>
</AllTrainDiagramProvider>
</AreaInfoProvider>
</CurrentTrainProvider>
</TrainDelayDataProvider>
</FavoriteStationProvider>
</GestureHandlerRootView>
</SafeAreaProvider>
</DeviceOrientationChangeProvider>
);
}
export function AppContainer() {
const { setBusAndTrainData } = useBusAndTrainData();
useEffect(() => {
AS.getItem("busAndTrain")
.then((d) => {
const returnData = JSON.parse(d);
setBusAndTrainData(returnData);
})
.catch(() => {
fetch(
"https://script.google.com/macros/s/AKfycbw0UW6ZeCDgUYFRP0zxpc_Oqfy-91dBdbWv-cM8n3narKp14IyCd2wy5HW7taXcW7E/exec"
)
.then((d) => d.json())
.then((d) => {
setBusAndTrainData(d);
AS.setItem("busAndTrain", JSON.stringify(d));
});
});
}, []);
const { areaInfo, setAreaInfo } = useAreaInfo();
const getAreaData = () =>
fetch(
"https://script.google.com/macros/s/AKfycbz80LcaEUrhnlEsLkJy0LG2IRO3DBVQhfNmN1d_0f_HvtsujNQpxM90SrV9yKWH_JG1Ww/exec"
)
.then((d) => d.text())
.then((d) => setAreaInfo(d));
useEffect(getAreaData, []);
useInterval(getAreaData, 60000); //60秒毎に全在線列車取得
return (
<NavigationContainer name="Root" style={{ flex: 1 }}>
@ -115,7 +81,7 @@ export function AppContainer() {
tabBarLabel: "リンク",
headerTransparent: true,
gestureEnabled: true,
tabBarIcon: initIcon("ios-radio", "Ionicons"),
tabBarIcon: initIcon("radio", "Ionicons"),
}}
>
{(props) => <MenuPage {...props} />}
@ -126,7 +92,7 @@ export function AppContainer() {
tabBarLabel: "運行情報",
headerTransparent: true,
gestureEnabled: true,
tabBarIcon: initIcon("md-train", "Ionicons"),
tabBarIcon: initIcon("train", "Ionicons"),
tabBarBadge: areaInfo ? "!" : undefined,
}}
>

202
Apps.js
View File

@ -1,8 +1,17 @@
import React, { useEffect, useRef, useState } from "react";
import { View, Platform, Text, TouchableOpacity } from "react-native";
import React, { useEffect, useState } from "react";
import {
View,
Platform,
Text,
TouchableOpacity,
useWindowDimensions,
LayoutAnimation,
} from "react-native";
import { WebView } from "react-native-webview";
import Constants from "expo-constants";
import { Ionicons } from "@expo/vector-icons";
import * as Updates from "expo-updates";
import { AS } from "./storageControl";
import { news } from "./config/newsUpdate";
import { getStationList, lineList } from "./lib/getStationList";
@ -10,16 +19,22 @@ import { injectJavascriptData } from "./lib/webViewInjectjavascript";
import { checkDuplicateTrainData } from "./lib/checkDuplicateTrainData";
import { useFavoriteStation } from "./stateBox/useFavoriteStation";
import { useCurrentTrain } from "./stateBox/useCurrentTrain";
import { useDeviceOrientationChange } from "./stateBox/useDeviceOrientationChange";
import { SheetManager } from "react-native-actions-sheet";
import TrainMenu from "./components/trainMenu";
import { EachTrainInfoCore } from "./components/ActionSheetComponents/EachTrainInfoCore";
/*
import StatusbarDetect from './StatusbarDetect';
var Status = StatusbarDetect(); */
export default function Apps({ navigation, webview, stationData }) {
const { currentTrain } = useCurrentTrain();
const { height, width } = useWindowDimensions();
const { navigate } = navigation;
var urlcache = "";
const { favoriteStation } = useFavoriteStation();
const { isLandscape, setIsLandscape } = useDeviceOrientationChange();
const handleLayout = () => {};
//画面表示関連
const [iconSetting, setIconSetting] = useState(undefined);
@ -49,6 +64,10 @@ export default function Apps({ navigation, webview, stationData }) {
stationMenu,
trainMenu
);
const ASCore = ({ k, s, d }) =>
AS.getItem(k)
.then((d) => (d ? s(d) : AS.setItem(k, d).then(Updates.reloadAsync)))
.catch(() => AS.setItem(k, d).then(Updates.reloadAsync));
useEffect(() => {
//ニュース表示
@ -61,67 +80,26 @@ export default function Apps({ navigation, webview, stationData }) {
useEffect(() => {
//列車アイコンスイッチ
AS.getItem("iconSwitch")
.then((d) => {
if (d) {
setIconSetting(d);
} else {
AS.setItem("iconSwitch", "true").then(Updates.reloadAsync);
}
})
.catch(() => AS.setItem("iconSwitch", "true").then(Updates.reloadAsync));
}, []);
useEffect(() => {
ASCore({ k: "iconSwitch", s: setIconSetting, d: "true" });
//地図スイッチ
AS.getItem("mapSwitch")
.then((d) => {
if (d) {
setMapSwitch(d);
} else {
AS.setItem("mapSwitch", "false").then(Updates.reloadAsync);
}
})
.catch(() => AS.setItem("mapSwitch", "false").then(Updates.reloadAsync));
}, []);
useEffect(() => {
ASCore({ k: "mapSwitch", s: setMapSwitch, d: "false" });
//駅メニュースイッチ
AS.getItem("stationSwitch")
.then((d) => {
if (d) {
setStationMenu(d);
} else {
AS.setItem("stationSwitch", "true").then(Updates.reloadAsync);
}
})
.catch(() =>
AS.setItem("stationSwitch", "true").then(Updates.reloadAsync)
);
}, []);
useEffect(() => {
ASCore({ k: "stationSwitch", s: setStationMenu, d: "true" });
//列車メニュースイッチ
AS.getItem("trainSwitch")
.then((d) => {
if (d) {
setTrainMenu(d);
} else {
AS.setItem("trainSwitch", "true").then(Updates.reloadAsync);
}
})
.catch(() => AS.setItem("trainSwitch", "true").then(Updates.reloadAsync));
ASCore({ k: "trainSwitch", s: setTrainMenu, d: "true" });
}, []);
const onMessage = (event) => {
if (event.nativeEvent.data.includes("train.html")) {
navigate("trainbase", { info: event.nativeEvent.data, from: "Train" });
const { data } = event.nativeEvent;
if (data.includes("train.html")) {
navigate("trainbase", { info: data, from: "Train" });
return;
}
if (!originalStationList) {
alert("駅名標データを取得中...");
return;
}
const dataSet = JSON.parse(event.nativeEvent.data);
const dataSet = JSON.parse(data);
switch (dataSet.type) {
case "LoadError": {
setLoadError(true);
@ -130,12 +108,10 @@ export default function Apps({ navigation, webview, stationData }) {
case "PopUpMenu":
{
const selectedStationPDFAddress = dataSet.pdf;
const findStationEachLine = (selectLine) => {
let NearStation = selectLine.filter(
const findStationEachLine = (selectLine) =>
selectLine.filter(
(d) => d.StationTimeTable == selectedStationPDFAddress
);
return NearStation;
};
let returnDataBase = lineList
.map((d) => findStationEachLine(originalStationList[d]))
.filter((d) => d.length > 0)
@ -154,19 +130,16 @@ export default function Apps({ navigation, webview, stationData }) {
SheetManager.show("StationDetailView", {
payload,
}),
onExit: () => {
SheetManager.hide("StationDetailView");
},
onExit: () => SheetManager.hide("StationDetailView"),
};
SheetManager.show("StationDetailView", {
payload,
});
SheetManager.show("StationDetailView", { payload });
}
}
return;
case "ShowTrainTimeInfo": {
const { trainNum, limited } = dataSet;
//alert(trainNum, limited);
LayoutAnimation.easeInEaseOut();
setTrainInfo({
trainNum,
limited,
@ -174,6 +147,7 @@ export default function Apps({ navigation, webview, stationData }) {
currentTrain.filter((a) => a.num == trainNum)
),
}); //遅延情報は未実装
if (isLandscape) return;
const payload = {
data: {
trainNum,
@ -271,8 +245,22 @@ export default function Apps({ navigation, webview, stationData }) {
style={{
height: "100%",
paddingTop: Platform.OS == "ios" ? Constants.statusBarHeight : 0,
flexDirection: isLandscape ? "row" : "column",
}}
onLayout={handleLayout}
>
{!trainInfo.trainNum && isLandscape ? (
<TrainMenu
webview={webview}
stationData={stationData}
navigation={{ navigate: null }}
style={{
width: (width / 100) * 40,
height: "100%",
flexDirection: "column-reverse",
}}
/>
) : null}
{/* {Status} */}
<WebView
useWebKit
@ -310,14 +298,50 @@ export default function Apps({ navigation, webview, stationData }) {
}
}}
/>
<MapsButton
onPress={() => navigate("trainMenu", { webview })}
top={Platform.OS == "ios" ? Constants.statusBarHeight : 0}
mapSwitch={mapSwitch == "true" ? "flex" : "none"}
/>
{isLandscape && trainInfo.trainNum && (
<View
style={{
width: (width / 100) * 40,
height: height,
flexDirection: "column",
}}
>
<EachTrainInfoCore
{...{
data: trainInfo.trainNum ? trainInfo : undefined,
navigate,
originalStationList,
openStationACFromEachTrainInfo,
from: "Train",
setTrainInfo,
}}
/>
</View>
)}
{isLandscape || (
<MapsButton
onPress={() => navigate("trainMenu", { webview })}
top={Platform.OS == "ios" ? Constants.statusBarHeight : 0}
mapSwitch={mapSwitch == "true" ? "flex" : "none"}
/>
)}
{isLandscape && trainInfo.trainNum && (
<LandscapeBackButton
onPress={() => {
LayoutAnimation.easeInEaseOut();
setTrainInfo({
trainNum: undefined,
limited: undefined,
trainData: undefined,
});
}}
top={Platform.OS == "ios" ? Constants.statusBarHeight : 0}
/>
)}
<ReloadButton
onPress={() => webview.current.reload()}
top={Platform.OS == "ios" ? Constants.statusBarHeight : 0}
right={isLandscape && trainInfo.trainNum ? (width / 100) * 40 : 0}
LoadError={LoadError}
/>
</View>
@ -360,12 +384,54 @@ const MapsButton = ({ onPress, top, mapSwitch }) => {
);
};
const ReloadButton = ({ onPress, top, mapSwitch, LoadError = false }) => {
const LandscapeBackButton = ({ onPress, top }) => {
const styles = {
touch: {
position: "absolute",
top,
right: 10,
left: 10,
width: 50,
height: 50,
backgroundColor: "#0099CC",
borderColor: "white",
borderStyle: "solid",
borderWidth: 1,
borderRadius: 50,
alignContent: "center",
alignSelf: "center",
alignItems: "center",
display: "flex",
},
text: {
textAlign: "center",
width: "auto",
height: "auto",
textAlignVertical: "center",
fontWeight: "bold",
color: "white",
},
};
return (
<TouchableOpacity onPress={onPress} style={styles.touch}>
<View style={{ flex: 1 }} />
<Ionicons name="arrow-back" color="white" size={30} />
<View style={{ flex: 1 }} />
</TouchableOpacity>
);
};
const ReloadButton = ({
onPress,
top,
mapSwitch,
LoadError = false,
right,
}) => {
const styles = {
touch: {
position: "absolute",
top,
right: 10 + right,
width: 50,
height: 50,
backgroundColor: LoadError ? "red" : "#0099CC",

View File

@ -3,12 +3,35 @@
"name": "JR四国運行状況",
"slug": "jrshikoku",
"privacy": "public",
"platforms": [
"ios",
"android"
"platforms": ["ios", "android"],
"plugins": [
[
"react-native-android-widget",
{
"widgets": [
{
"name": "JR_shikoku_train_info",
"label": "JR四国列車遅延速報EX",
"minWidth": "70dp",
"minHeight": "50dp",
"description": "JR四国列車遅延速報EXのウィジェットです。30分ごとに自動更新します。タッチすると強制更新します。",
"previewImage": "./assets/icon.png",
"updatePeriodMillis": 1800000,
"resizeMode": "horizontal|vertical"
}
]
}
],
"expo-font",
[
"expo-screen-orientation",
{
"initialOrientation": "DEFAULT"
}
]
],
"version": "4.6",
"orientation": "portrait",
"version": "5.0",
"orientation": "default",
"icon": "./assets/icon.png",
"splash": {
"image": "./assets/splash.png",
@ -19,23 +42,29 @@
"fallbackToCacheTimeout": 0,
"url": "https://u.expo.dev/398abf60-57a7-11e9-970c-8f04356d08bf"
},
"assetBundlePatterns": [
"**/*"
],
"assetBundlePatterns": ["**/*"],
"ios": {
"buildNumber": "31",
"buildNumber": "33",
"supportsTablet": true,
"bundleIdentifier": "jrshikokuinfo.xprocess.hrkn",
"config": {
"googleMapsApiKey": "AIzaSyAVGDTjBkR_0wkQiNkoo5WDLhqXCjrjk8Y"
},
"infoPlist": {
"NFCReaderUsageDescription": "To read FeliCa card",
"com.apple.developer.nfc.readersession.felica.systemcodes": [
"0003",
"FE00"
]
},
"entitlements": {
"com.apple.developer.nfc.readersession.formats": ["TAG"]
}
},
"android": {
"package": "jrshikokuinfo.xprocess.hrkn",
"versionCode": 20,
"permissions": [
"ACCESS_FINE_LOCATION"
],
"versionCode": 22,
"permissions": ["ACCESS_FINE_LOCATION", "NFC"],
"googleServicesFile": "./google-services.json",
"config": {
"googleMaps": {

View File

@ -1,802 +1,23 @@
import React, { useEffect, useState, useRef } from "react";
import {
View,
LayoutAnimation,
ScrollView,
Linking,
Text,
TouchableOpacity,
TouchableWithoutFeedback,
TouchableHighlight,
Platform,
} from "react-native";
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons";
import ActionSheet, {
SheetManager,
useScrollHandlers,
} from "react-native-actions-sheet";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { AS } from "../../storageControl";
import LottieView from "lottie-react-native";
import trainList from "../../assets/originData/trainList";
import { lineList } from "../../lib/getStationList";
import {
heightPercentageToDP,
widthPercentageToDP,
} from "react-native-responsive-screen";
import lineColorList from "../../assets/originData/lineColorList";
import { useCurrentTrain } from "../../stateBox/useCurrentTrain";
import { checkDuplicateTrainData } from "../../lib/checkDuplicateTrainData";
import React, { useRef } from "react";
import { Platform } from "react-native";
import ActionSheet from "react-native-actions-sheet";
import { EachTrainInfoCore } from "./EachTrainInfoCore";
export const EachTrainInfo = (props) => {
if (!props.payload) return <></>;
const {
data,
navigate,
originalStationList,
openStationACFromEachTrainInfo = () => {},
from,
} = props.payload;
const [trainData, setTrainData] = useState([]);
const [isTop, setIsTop] = useState(true);
const [currentPosition, setCurrentPosition] = useState([]);
const [trainPositionSwitch, setTrainPositionSwitch] = useState("false");
const { currentTrain } = useCurrentTrain();
const [currentTrainData, setCurrentTrainData] = useState([]);
useEffect(() => {
setCurrentTrainData(
checkDuplicateTrainData(
currentTrain.filter((d) => d.num == data.trainNum)
)
);
}, [currentTrain]);
useEffect(() => {
//列車現在地アイコン表示スイッチ
AS.getItem("trainPositionSwitch")
.then((d) => {
if (d) {
setTrainPositionSwitch(d);
} else {
}
})
.catch((d) => AS.setItem("trainPositionSwitch", "false"));
}, []);
const insets = useSafeAreaInsets();
const getStationData = (stationName) => {
const Stations = stationList.map((a) =>
a.filter((d) => d.StationName == stationName)
);
const Station =
Stations &&
Stations.reduce((newArray, e) => {
return newArray.concat(e);
}, []);
if (!Station[0]) return [];
return Station.map((d) => d.StationNumber)[0];
};
useEffect(() => {
//currentTrainData.Pos = "鴨川~端岡"; //test
if (!currentTrainData?.Pos) return;
if (currentTrainData?.Pos.match("")) {
const pos = currentTrainData?.Pos.replace("(下り)", "")
.replace("(上り)", "")
.split("");
setCurrentPosition([getStationData(pos[0]), getStationData(pos[1])]);
} else {
setCurrentPosition([getStationData(currentTrainData?.Pos)]);
}
}, [currentTrainData]);
const stationList =
originalStationList &&
lineList.map((d) =>
originalStationList[d].map((a) => ({
StationNumber: a.StationNumber,
StationName: a.Station_JP,
}))
);
const stopStationIDList = trainData.map((i, index) => {
const [station, se, time] = i.split(",");
const Stations = stationList.map((a) =>
a.filter((d) => d.StationName == station)
);
const StationNumbers =
Stations &&
Stations.reduce((newArray, e) => {
return newArray.concat(e);
}, [])
.filter((d) => d.StationNumber)
.map((d) => d.StationNumber);
return StationNumbers[0];
});
function findReversalPoints(array) {
try {
// arrayは現在位置の駅ID(駅在宅の場合は1つの配列、駅間の場合は2つの配列)
// stopStationIDListは停車駅の駅IDの配列
if (!stopStationIDList.length) return [];
// arrayが二次元配列だったら早期リターン
if (!array instanceof Array) return [];
if (!array.length) return [];
if (array[0] instanceof Array) return [];
const arrayNumber = array.map((d) => ({
line: d
.split("")
.filter((s) => "A" < s && s < "Z")
.join(""),
ID: d
.split("")
.filter((s) => "0" <= s && s <= "9")
.join(""),
}));
const stopStationIDListNumber = stopStationIDList.map((d) => {
if (!d) return { line: [], ID: [] };
return {
line: d
.split("")
.filter((s) => "A" < s && s < "Z")
.join(""),
ID: d
.split("")
.filter((s) => "0" <= s && s <= "9")
.join(""),
};
});
// 完全一致
if (array.length == 1) {
const index = stopStationIDList.indexOf(array[0]);
if (index != -1) return [index];
// 通過駅の場合
for (let i = 0; i < stopStationIDListNumber.length - 1; i++) {
if (stopStationIDListNumber[i].ID < arrayNumber[0].ID) {
if (stopStationIDListNumber[i + 1].ID > arrayNumber[0].ID) {
return [i + 1];
}
}
if (stopStationIDListNumber[i].ID > arrayNumber[0].ID) {
if (stopStationIDListNumber[i + 1].ID < arrayNumber[0].ID) {
return [i + 1];
}
}
}
}
// 駅間の場合
if (array.length == 2) {
const index1 = stopStationIDList.indexOf(array[0]);
const index2 = stopStationIDList.indexOf(array[1]);
if (index1 != -1 && index2 != -1) {
// 駅間で通過駅も無い場合
if (index1 < index2) {
if (index1 + 1 == index2) {
return [index2];
} else {
const returnArray = [];
for (let i = index1 + 1; i <= index2; i++) {
returnArray.push(i);
}
return returnArray;
}
}
if (index1 > index2) {
if (index2 + 1 == index1) return [index1];
else {
const returnArray = [];
for (let i = index2 + 1; i <= index1; i++) {
returnArray.push(i);
}
return returnArray;
}
}
} else {
const getNearStationID = (stationID) => {
for (let i = 0; i <= stopStationIDListNumber.length; i++) {
if (stopStationIDListNumber[i].ID < stationID) {
if (stopStationIDListNumber[i + 1].ID > stationID) {
return i + 1;
}
}
if (stopStationIDListNumber[i].ID > stationID) {
if (stopStationIDListNumber[i + 1].ID < stationID) {
return i + 1;
}
}
}
};
let newIndex1 = index1;
let newIndex2 = index2;
if (index1 == -1) {
newIndex1 = getNearStationID(arrayNumber[0].ID);
}
if (index2 == -1) {
newIndex2 = getNearStationID(arrayNumber[1].ID);
}
if (newIndex1 && newIndex2) {
return [newIndex1, newIndex2];
}
// 通過駅の場合
}
return [];
}
} catch (e) {
console.log(e);
}
}
// 使用例
const points =
trainPositionSwitch == "true" ? findReversalPoints(currentPosition) : [];
useEffect(() => {
setIsTop(true);
if (!data.trainNum) return;
const TD = trainList[data.trainNum];
if (!TD) {
setTrainData([]);
return;
}
setTrainData(TD.split("#").filter((d) => d != ""));
}, [data]);
const getType = (string) => {
switch (string) {
case "express":
return "特急";
case "rapid":
return "快速";
default:
return "";
}
};
const migrateTrainName = (string) => {
return string
.replace("マリン", "マリンライナー")
.replace("ライナーライナー", "ライナー");
};
const actionSheetRef = useRef(null);
const scrollHandlers = useScrollHandlers("scrollview-1", actionSheetRef);
return (
<ActionSheet
gestureEnabled={isTop}
gestureEnabled={true}
//gestureEnabled={!actionSheetHorizonalScroll}
CustomHeaderComponent={<></>}
ref={actionSheetRef}
drawUnderStatusBar={false}
isModal={Platform.OS == "ios"}
containerStyle={
Platform.OS == "android"
? {
paddingBottom: insets.bottom,
}
: {}
}
useBottomSafeAreaPadding={Platform.OS == "android"}
//useBottomSafeAreaPadding={Platform.OS == "android"}
>
<View
style={{
backgroundColor: "#0099CC",
borderTopRadius: 5,
borderColor: "dark",
borderWidth: 1,
}}
>
<View style={{ height: 26, width: "100%" }}>
<View
style={{
height: 6,
width: 45,
borderRadius: 100,
backgroundColor: "#f0f0f0",
marginVertical: 10,
alignSelf: "center",
}}
/>
</View>
<View
style={{ padding: 10, flexDirection: "row", alignItems: "center" }}
>
<Text style={{ fontSize: 20, fontWeight: "bold", color: "white" }}>
{data.limited
? getType(data.limited.split(":")[0]) +
migrateTrainName(
data.limited.split(":")[1] ||
(trainData.length > 0
? trainData[trainData.length - 1].split(",")[0] + "行き"
: " ")
)
: ""}
</Text>
<View style={{ flex: 1 }} />
<Text style={{ fontSize: 20, fontWeight: "bold", color: "white" }}>
{data.trainNum}
</Text>
{data.limited != undefined &&
getType(data.limited.split(":")[0]) &&
!data.limited.split(":")[1].match("サンポート") && (
<Ionicons
name="subway"
color="white"
size={30}
style={{ margin: 5 }}
onPress={() => {
LayoutAnimation.easeInEaseOut(); //setLoadingDelayData(true);
navigate("trainbase", {
info: "train.html?tn=" + data.trainNum,
from,
});
SheetManager.hide("EachTrainInfo");
}}
/>
)}
</View>
{from == "AllTrainDiagramView" || (
<ScrollView
style={{
flexDirection: "row",
//width: widthPercentageToDP("200%"),
minHeight: 200,
height: heightPercentageToDP("20%"),
}}
horizontal
pagingEnabled
>
<View
style={{
flexDirection: "row",
minHeight: 200,
height: heightPercentageToDP("20%"),
width: widthPercentageToDP("100%"),
}}
>
<View
style={{
flex: 1,
backgroundColor: "white",
borderRadius: 10,
padding: 10,
margin: 10,
}}
>
<Text style={{ fontSize: 15, color: "#0099CC" }}>
現在地 {currentPosition.toString()}
</Text>
<View style={{ flex: 1 }} />
{currentTrainData?.Pos && currentTrainData?.Pos.match("") ? (
<>
<Text
style={{
fontSize: 28,
color: "#0099CC",
textAlign: "right",
}}
>
{
currentTrainData?.Pos.replace("(下り)", "")
.replace("(上り)", "")
.split("")[0]
}
</Text>
<Text style={{ color: "#0099CC", textAlign: "right" }}>
</Text>
<Text
style={{
fontSize: 28,
color: "#0099CC",
textAlign: "right",
}}
>
{
currentTrainData?.Pos.replace("(下り)", "")
.replace("(上り)", "")
.split("")[1]
}
</Text>
</>
) : (
<Text
style={{
fontSize: 28,
color: "#0099CC",
textAlign: "right",
}}
>
{currentTrainData?.Pos}
</Text>
)}
</View>
<View style={{ flex: 1, flexDirection: "column" }}>
<View
style={{
flex: 1,
backgroundColor: "white",
borderRadius: 10,
padding: 10,
margin: 10,
}}
>
<Text style={{ fontSize: 15, color: "#0099CC" }}>
{isNaN(currentTrainData?.delay) ? "状態" : "遅延時分"}
</Text>
<View style={{ flex: 1 }} />
<Text
style={{
fontSize: 32,
color: "#0099CC",
textAlign: "right",
}}
>
{currentTrainData?.delay}
{isNaN(currentTrainData?.delay) ? "" : "分"}
</Text>
</View>
<View
style={{
flex: 1,
backgroundColor: "white",
borderRadius: 10,
padding: 10,
margin: 10,
}}
>
<Text style={{ fontSize: 15, color: "#0099CC" }}>列番</Text>
<Text
style={{
fontSize: 32,
color: "#0099CC",
textAlign: "right",
}}
>
{currentTrainData?.num}
</Text>
</View>
</View>
</View>
{/* <View
style={{
flexDirection: "column",
height: heightPercentageToDP("20%"),
flex: 1,
width: widthPercentageToDP("100%"),
}}
>
<View style={{ flex: 1, flexDirection: "row" }}>
<View
style={{
flex: 1,
backgroundColor: "white",
borderRadius: 10,
padding: 10,
margin: 10,
}}
>
<Text style={{ fontSize: 15, color: "#0099CC" }}>行先</Text>
<View style={{ flex: 1 }} />
<Text
style={{
fontSize: 20,
color: "#0099CC",
textAlign: "right",
}}
>
岡山
</Text>
</View>
<View
style={{
flex: 3,
backgroundColor: "white",
borderRadius: 10,
padding: 10,
margin: 10,
}}
>
<Text style={{ fontSize: 15, color: "#0099CC" }}>車両案内</Text>
<View style={{ flex: 1 }} />
<Text
style={{
fontSize: 20,
color: "#0099CC",
textAlign: "right",
}}
>
宇多津でうずしお号と連結
</Text>
</View>
</View>
<View style={{ flex: 1, flexDirection: "row" }}>
<View
style={{
flex: 1,
backgroundColor: "white",
borderRadius: 10,
padding: 10,
margin: 10,
}}
>
<Text style={{ fontSize: 15, color: "#0099CC" }}>
編成(使用車両2700)
</Text>
<View style={{ flex: 1 }} />
<Text
style={{
fontSize: 20,
color: "#0099CC",
textAlign: "left",
}}
>
{"[<自][自>][アン自|指>][アン指|G>]"}
</Text>
</View>
</View>
</View> */}
</ScrollView>
)}
<View
style={{
alignItems: "center",
backgroundColor: "white",
flexDirection: "row",
}}
>
<View
style={{
padding: 8,
flexDirection: "row",
borderBottomWidth: 1,
borderBottomColor: "#f0f0f0",
flex: 1,
}}
>
<Text style={{ fontSize: 20 }}>停車駅</Text>
<View style={{ flex: 1 }} />
<View style={{ flexDirection: "row" }}>
{!isNaN(currentTrainData?.delay) &&
currentTrainData?.delay != 0 && (
<Text
style={{
fontSize: 15,
color: "black",
position: "absolute",
right: 110,
textAlign: "right",
textDecorationLine: "line-through",
}}
>
(定刻)
</Text>
)}
<Text
style={{
fontSize: 20,
color: isNaN(currentTrainData?.delay)
? "black"
: currentTrainData?.delay == 0
? "black"
: "red",
width: 60,
}}
>
見込
</Text>
<Text style={{ fontSize: 20, width: 50 }}></Text>
</View>
</View>
</View>
<ScrollView
{...scrollHandlers}
style={{
maxHeight: heightPercentageToDP(
from == "AllTrainDiagramView" ? "70%" : "50%"
),
}}
onScroll={(e) => {
if (!Platform.OS !== "android") return;
setIsTop(e.nativeEvent.contentOffset.y < 0);
}}
>
<View style={{ backgroundColor: "white", alignItems: "center" }}>
{/* <LottieView
autoPlay
loop
style={{ width: 150, height: 150, backgroundColor: "#fff" }}
source={require("../../assets/51690-loading-diamonds.json")}
/>
<Text>ほげほげふがふが</Text> */}
{trainData.map((i, index) => {
const [station, se, time] = i.split(",");
if(se == "提"){
return (
<TouchableWithoutFeedback
onPress={() => Linking.openURL(time)}
key={station}
>
<View style={{ flexDirection: "row" }}>
<View
style={{
padding: 8,
flexDirection: "row",
borderBottomWidth: 1,
borderBottomColor: "#f0f0f0",
flex: 1,
}}
>
<Text style={{ fontSize: 20 }}>{station}</Text>
<View style={{ flex: 1 }} />
<Text style={{ fontSize: 18 }}>
提供元<MaterialCommunityIcons name={"open-in-new"} color="black" size={20} />
</Text>
</View>
</View>
</TouchableWithoutFeedback>
);
}
const Stations = stationList.map((a) =>
a.filter((d) => d.StationName == station)
);
const StationNumbers =
Stations &&
Stations.reduce((newArray, e) => {
return newArray.concat(e);
}, [])
.filter((d) => d.StationNumber)
.map((d) => d.StationNumber);
const colorIDs =
StationNumbers != null
? StationNumbers.map((d) => {
return d.split("").filter((s) => "A" < s && s < "Z");
}).reduce((newArray, e) => {
return newArray.concat(e);
}, [])
: [];
const EachIDs =
StationNumbers != null
? StationNumbers.map((d) => {
return d
.split("")
.filter((s) => "0" <= s && s <= "9")
.join("");
})
: [];
const date = new Date();
if (time) {
date.setHours(time.split(":")[0], time.split(":")[1]);
}
if (!isNaN(currentTrainData?.delay)) {
date.setMinutes(date.getMinutes() + currentTrainData?.delay);
}
const timeString = date.toTimeString().split(" ")[0].split(":");
return (
<TouchableWithoutFeedback
onPress={() => openStationACFromEachTrainInfo(station)}
key={station}
>
<View style={{ flexDirection: "row" }}>
<View
style={{
width: 35,
position: "relative",
marginHorizontal: 15,
flexDirection: "row",
height: "101%",
}}
>
{colorIDs.map((color, index) => (
<View
style={{
backgroundColor: lineColorList[color],
flex: 1,
}}
key={color}
>
<View style={{ flex: 1 }} />
<Text
style={{
color: "white",
textAlign: "center",
fontSize: 10,
fontWeight: "bold",
}}
>
{colorIDs[index]}
</Text>
<Text
style={{
color: "white",
textAlign: "center",
fontSize: 10,
fontWeight: "bold",
}}
>
{EachIDs[index]}
</Text>
<View style={{ flex: 1 }} />
</View>
))}
</View>
<View
style={{
padding: 8,
flexDirection: "row",
borderBottomWidth: 1,
borderBottomColor: "#f0f0f0",
flex: 1,
}}
>
<Text style={{ fontSize: 20 }}>{station}</Text>
<View style={{ flex: 1 }} />
{points && points.findIndex((d) => d == index) >= 0 ? (
<Text
style={{
fontSize: 20,
marginRight: 70,
}}
>
🚊
</Text>
) : null}
{!isNaN(currentTrainData?.delay) &&
currentTrainData?.delay != 0 && (
<Text
style={{
fontSize: 15,
color: "black",
width: 60,
position: "absolute",
right: 120,
textAlign: "right",
textDecorationLine: "line-through",
}}
>
{time}
</Text>
)}
<Text
style={{
fontSize: 20,
color: isNaN(currentTrainData?.delay)
? "black"
: currentTrainData?.delay == 0
? "black"
: "red",
width: 60,
}}
>
{timeString[0]}:{timeString[1]}
</Text>
<Text style={{ fontSize: 18, width: 50 }}>
{se?.replace("発", "出発").replace("着", "到着")}
</Text>
</View>
</View>
</TouchableWithoutFeedback>
);
})}
<View style={{ flexDirection: "row" }}>
<View
style={{
padding: 8,
flexDirection: "row",
borderBottomWidth: 1,
borderBottomColor: "#f0f0f0",
flex: 1,
}}
>
<Text style={{ fontSize: 20 }}> </Text>
<View style={{ flex: 1 }} />
</View>
</View>
</View>
</ScrollView>
</View>
<EachTrainInfoCore {...{ actionSheetRef, ...props.payload }} />
</ActionSheet>
);
};

View File

@ -0,0 +1,36 @@
import React from "react";
import { View, Text, TouchableWithoutFeedback } from "react-native";
import { MaterialCommunityIcons } from "@expo/vector-icons";
import { Linking } from "react-native";
export const DataFromButton = ({ i }) => {
const [station, se, time] = i.split(",");
return (
<TouchableWithoutFeedback
onPress={() => Linking.openURL(time)}
key={station}
>
<View style={{ flexDirection: "row" }}>
<View
style={{
padding: 8,
flexDirection: "row",
borderBottomWidth: 1,
borderBottomColor: "#f0f0f0",
flex: 1,
}}
>
<Text style={{ fontSize: 20 }}>{station}</Text>
<View style={{ flex: 1 }} />
<Text style={{ fontSize: 18 }}>
提供元
<MaterialCommunityIcons
name={"open-in-new"}
color="black"
size={20}
/>
</Text>
</View>
</View>
</TouchableWithoutFeedback>
);
};

View File

@ -0,0 +1,140 @@
import React from "react";
import { View, Text, TouchableWithoutFeedback } from "react-native";
import dayjs from "dayjs";
import lineColorList from "../../../assets/originData/lineColorList";
export const EachStopList = ({
i,
index,
stationList,
points,
currentTrainData,
openStationACFromEachTrainInfo,
}) => {
const [station, se, time] = i.split(","); // 阿波池田,発,6:21
const Stations = stationList
.map((a) => a.filter((d) => d.StationName == station))
.reduce((newArray, e) => newArray.concat(e), []);
/*Array [
Object {
"StationName": "佐古",
"StationNumber": "T01",
},
Object {
"StationName": "佐古",
"StationNumber": "B01",
},
] */
const StationNumbers =
Stations &&
Stations.filter((d) => d.StationNumber).map((d) => d.StationNumber);
// Array [ "T01", "B01",]
const lineIDs = [];
const EachIDs = [];
StationNumbers.forEach((d) => {
const textArray = d.split("");
lineIDs.push(textArray.filter((s) => "A" < s && s < "Z").join(""));
EachIDs.push(textArray.filter((s) => "0" <= s && s <= "9").join(""));
});
// Array [ "T", "B",]
// Array [ "01", "01",]
const dates = dayjs()
.set("hour", parseInt(time.split(":")[0]))
.set("minute", parseInt(time.split(":")[1]))
.add(isNaN(currentTrainData?.delay) ? 0 : currentTrainData.delay, "minute");
const timeString = dates.format("HH:mm").split(":");
return (
<TouchableWithoutFeedback
onPress={() =>
openStationACFromEachTrainInfo &&
openStationACFromEachTrainInfo(station)
}
key={station}
>
<View style={{ flexDirection: "row", backgroundColor: "white" }}>
<View
style={{
width: 35,
position: "relative",
marginHorizontal: 15,
flexDirection: "row",
height: "101%",
}}
>
{lineIDs.map((lineID, index) => (
<View
style={{
backgroundColor: lineColorList[lineID],
flex: 1,
}}
key={lineID}
>
<View style={{ flex: 1 }} />
<Text
style={{
color: "white",
textAlign: "center",
fontSize: 10,
fontWeight: "bold",
}}
>
{lineIDs[index]}
{"\n"}
{EachIDs[index]}
</Text>
<View style={{ flex: 1 }} />
</View>
))}
</View>
<View
style={{
padding: 8,
flexDirection: "row",
borderBottomWidth: 1,
borderBottomColor: "#f0f0f0",
flex: 1,
}}
>
<Text style={{ fontSize: 20 }}>{station}</Text>
<View style={{ flex: 1 }} />
{points && points.findIndex((d) => d == index) >= 0 ? (
<Text style={{ fontSize: 20, marginRight: 70 }}>🚊</Text>
) : null}
{!isNaN(currentTrainData?.delay) && currentTrainData?.delay != 0 && (
<Text
style={{
fontSize: 15,
color: "black",
width: 60,
position: "absolute",
right: 120,
textAlign: "right",
textDecorationLine: "line-through",
}}
>
{time}
</Text>
)}
<Text
style={{
fontSize: 20,
color: isNaN(currentTrainData?.delay)
? "black"
: currentTrainData?.delay == 0
? "black"
: "red",
width: 60,
}}
>
{timeString[0]}:{timeString[1]}
</Text>
<Text style={{ fontSize: 18, width: 50 }}>
{se?.replace("発", "出発").replace("着", "到着")}
</Text>
</View>
</View>
</TouchableWithoutFeedback>
);
};

View File

@ -0,0 +1,47 @@
import React from "react";
import { View, Text, ScrollView, useWindowDimensions } from "react-native";
export const LandscapeTrainInfo = (props) => {
const { leftContent, topStickyContent, children, scrollHandlers } = props;
const { height, width } = useWindowDimensions();
return (
<View
style={{
flexDirection: "row",
backgroundColor: "blue",
width: width,
height: (height / 100) * 70,
marginBottom: 50,
}}
>
<View
style={{
flexDirection: "column",
height: (height / 100) * 70,
width: width / 2,
}}
>
<Text>{width / 2}</Text>
{leftContent}
</View>
<ScrollView
{...scrollHandlers}
style={{
width: width / 2,
height: "auto",
}}
stickyHeaderIndices={[1]}
scrollEventThrottle={16}
onScroll={(d) => {
console.log(d.nativeEvent.contentOffset.y);
}}
>
<View style={{ height: 0 }} />
<View style={{ flexDirection: "column" }} index={1}>
{topStickyContent}
</View>
{children}
</ScrollView>
</View>
);
};

View File

@ -0,0 +1,33 @@
import React from "react";
import { ScrollView } from "react-native";
import { TrainDataView } from "./TrainDataView";
export const LongHeader = ({
currentTrainData,
currentPosition,
nearTrainIDList,
openTrainInfo,
}) => {
return (
<ScrollView
//onTouchStart={() => setActionSheetHorizonalScroll(true)}
//onScrollEndDrag={() => setActionSheetHorizonalScroll(false)}
//onScrollBeginDrag={() => console.log("onScrollBeginDrag")}
style={{
flexDirection: "row",
//width: widthPercentageToDP("200%"),
// minHeight: 200,
//height: heightPercentageToDP("20%"),
}}
horizontal
pagingEnabled
>
<TrainDataView
currentTrainData={currentTrainData}
currentPosition={currentPosition}
nearTrainIDList={nearTrainIDList}
openTrainInfo={openTrainInfo}
/>
</ScrollView>
);
};

View File

@ -0,0 +1,57 @@
import React from "react";
import { View, Text } from "react-native";
export const ScrollStickyContent = ({ currentTrainData }) => {
return (
<View
style={{
alignItems: "center",
backgroundColor: "white",
flexDirection: "row",
}}
>
<View
style={{
padding: 8,
flexDirection: "row",
borderBottomWidth: 1,
borderBottomColor: "#f0f0f0",
flex: 1,
}}
>
<Text style={{ fontSize: 20 }}>停車駅</Text>
<View style={{ flex: 1 }} />
<View style={{ flexDirection: "row" }}>
{!isNaN(currentTrainData?.delay) && currentTrainData?.delay != 0 && (
<Text
style={{
fontSize: 15,
color: "black",
position: "absolute",
right: 110,
textAlign: "right",
textDecorationLine: "line-through",
}}
>
(定刻)
</Text>
)}
<Text
style={{
fontSize: 20,
color: isNaN(currentTrainData?.delay)
? "black"
: currentTrainData?.delay == 0
? "black"
: "red",
width: 60,
}}
>
見込
</Text>
<Text style={{ fontSize: 20, width: 50 }}></Text>
</View>
</View>
</View>
);
};

View File

@ -0,0 +1,35 @@
import React from "react";
import { ScrollView } from "react-native";
import { TrainDataView } from "./TrainDataView";
export const ShortHeader = ({
currentTrainData,
currentPosition,
nearTrainIDList,
openTrainInfo,
}) => {
return (
<ScrollView
//onTouchStart={() => setActionSheetHorizonalScroll(true)}
//onScrollEndDrag={() => setActionSheetHorizonalScroll(false)}
//onScrollBeginDrag={() => console.log("onScrollBeginDrag")}
style={{
flexDirection: "row",
flex: 1,
//width: widthPercentageToDP("200%"),
// minHeight: 200,
//height: heightPercentageToDP("20%"),
}}
horizontal
pagingEnabled
>
<TrainDataView
mode={2}
currentTrainData={currentTrainData}
currentPosition={currentPosition}
nearTrainIDList={nearTrainIDList}
openTrainInfo={openTrainInfo}
/>
</ScrollView>
);
};

View File

@ -0,0 +1,55 @@
import React from "react";
import { View, Text } from "react-native";
export const StateBox = ({ text, title, style, mode }) => (
<View style={{ ...(mode == 2 ? boxStyle2 : boxStyle), ...style }}>
<Text style={{ fontSize: 12, color: "#0099CC" }}>{title}</Text>
<View style={{ flex: 1 }} />
<View
style={{
color: "#0099CC",
textAlign: "right",
flexDirection: mode == 2 ? "row" : "column",
}}
>
{text?.match("") ? (
<>
<Text style={mode == 2 ? boxTextStyle2 : boxTextStyle}>
{text.split("")[0]}
</Text>
<Text style={{ color: "#0099CC", textAlign: "right" }}></Text>
<Text style={mode == 2 ? boxTextStyle2 : boxTextStyle}>
{text.split("")[1]}
</Text>
</>
) : (
<Text style={mode == 2 ? boxTextStyle2 : boxTextStyle}>{text}</Text>
)}
</View>
</View>
);
const boxStyle = {
flex: 1,
backgroundColor: "white",
borderRadius: 10,
padding: 10,
margin: 10,
};
const boxStyle2 = {
flex: 1,
backgroundColor: "white",
borderRadius: 10,
padding: 5,
margin: 5,
};
const boxTextStyle2 = {
fontSize: 18,
color: "#0099CC",
textAlign: "right",
};
const boxTextStyle = {
fontSize: 25,
color: "#0099CC",
textAlign: "right",
};

View File

@ -0,0 +1,79 @@
import React from "react";
import { View, TouchableOpacity, useWindowDimensions } from "react-native";
import { StateBox } from "./StateBox";
import { useDeviceOrientationChange } from "../../../stateBox/useDeviceOrientationChange";
export const TrainDataView = ({
currentTrainData,
currentPosition,
nearTrainIDList,
openTrainInfo,
mode = 0,
}) => {
const { width, height } = useWindowDimensions();
const { isLandscape } = useDeviceOrientationChange();
return (
<View
style={{
flexDirection: "row",
//minHeight: 200,
//height: heightPercentageToDP("20%"),
width: isLandscape ? (width / 100) * 40 : width,
flex: 1,
}}
>
<StateBox
mode={mode}
title={`現在地 ${currentPosition.toString()}`}
text={
currentTrainData?.Pos.match("")
? `${
currentTrainData?.Pos.replace("(下り)", "")
.replace("(上り)", "")
.split("")[0]
}${
currentTrainData?.Pos.replace("(下り)", "")
.replace("(上り)", "")
.split("")[1]
}`
: currentTrainData?.Pos
}
/>
<View style={{ flex: 1, flexDirection: mode == 2 ? "row" : "column" }}>
<View style={{ flex: 1, flexDirection: "row" }}>
<StateBox
mode={mode}
title={isNaN(currentTrainData?.delay) ? "状態" : "遅延時分"}
text={`${currentTrainData?.delay}${
isNaN(currentTrainData?.delay) ? "" : "分"
}`}
/>
</View>
<TouchableOpacity
style={{ flex: 1, flexDirection: "row" }}
disabled={nearTrainIDList.length == 0}
onPress={() => {
if (nearTrainIDList.length == 0) return;
openTrainInfo(nearTrainIDList[0]);
}}
>
{nearTrainIDList.length == 0 ? (
<StateBox mode={mode} title="列番" text={currentTrainData?.num} />
) : (
<StateBox
mode={mode}
title="増解結相手を表示▶️"
text={`${nearTrainIDList}`}
style={{
borderWidth: 1,
borderColor: "red",
borderStyle: "solid",
}}
/>
)}
</TouchableOpacity>
</View>
</View>
);
};

View File

@ -0,0 +1,451 @@
import React, { useEffect, useState } from "react";
import {
View,
LayoutAnimation,
Text,
TouchableOpacity,
StyleSheet,
useWindowDimensions,
BackHandler,
} from "react-native";
import { Ionicons } from "@expo/vector-icons";
import { SheetManager, useScrollHandlers } from "react-native-actions-sheet";
import { AS } from "../../storageControl";
import trainList from "../../assets/originData/trainList";
import { lineList } from "../../lib/getStationList";
import { useCurrentTrain } from "../../stateBox/useCurrentTrain";
import { checkDuplicateTrainData } from "../../lib/checkDuplicateTrainData";
import { getTrainType } from "../../lib/getTrainType";
import { customTrainDataDetector } from "../custom-train-data";
import { useBusAndTrainData } from "../../stateBox/useBusAndTrainData";
import { useDeviceOrientationChange } from "../../stateBox/useDeviceOrientationChange";
import { EachStopList } from "./EachTrainInfo/EachStopList";
import { DataFromButton } from "./EachTrainInfo/DataFromButton";
import { DynamicHeaderScrollView } from "../DynamicHeaderScrollView";
import { LongHeader } from "./EachTrainInfo/LongHeader";
import { ShortHeader } from "./EachTrainInfo/ShortHeader";
import { ScrollStickyContent } from "./EachTrainInfo/ScrollStickyContent";
import { getStationData } from "../../lib/eachTrainInfoCoreLib/getStationData";
import { findReversalPoints } from "../../lib/eachTrainInfoCoreLib/findReversalPoints";
import { migrateTrainName } from "../../lib/eachTrainInfoCoreLib/migrateTrainName";
import { getType } from "../../lib/eachTrainInfoCoreLib/getType";
import { searchSpecialTrain } from "../../lib/eachTrainInfoCoreLib/searchSpecialTrain";
import { openBackTrainInfo } from "../../lib/eachTrainInfoCoreLib/openBackTrainInfo";
export const EachTrainInfoCore = ({
actionSheetRef,
data,
navigate,
originalStationList,
openStationACFromEachTrainInfo,
from,
setTrainInfo,
}) => {
// const [actionSheetHorizonalScroll, setActionSheetHorizonalScroll] = useState(false);
const { currentTrain } = useCurrentTrain();
const [currentTrainData, setCurrentTrainData] = useState();
// const [actionSheetHorizonalScroll, setActionSheetHorizonalScroll] = useState(false);
useEffect(() => {
console.log(currentTrain.length);
if (!currentTrain.length) return;
setCurrentTrainData(
checkDuplicateTrainData(
currentTrain.filter((d) => d.num == data.trainNum)
)
);
}, [currentTrain, data.trainNum]);
useEffect(() => {
const backAction = () => {
SheetManager.hide("EachTrainInfo");
return true;
};
const backHandler = BackHandler.addEventListener(
"hardwareBackPress",
backAction
);
return () => backHandler.remove();
}, []);
//bconst insets = useSafeAreaInsets();
const [headStation, setHeadStation] = useState();
const [tailStation, setTailStation] = useState();
const [isConcatNear, setIsConcatNear] = useState(false);
const [showNearTrain, setShowNearTrain] = useState([]);
const [nearTrainIDList, setNearTrainIDList] = useState([]);
const { getInfluencedTrainData } = useBusAndTrainData();
const [trainPositionSwitch, setTrainPositionSwitch] = useState("false");
const [currentPosition, setCurrentPosition] = useState([]);
const [trainData, setTrainData] = useState([]);
const scrollHandlers = actionSheetRef
? useScrollHandlers("scrollview-1", actionSheetRef)
: null;
const stationList =
originalStationList &&
lineList.map((d) =>
originalStationList[d].map((a) => ({
StationNumber: a.StationNumber,
StationName: a.Station_JP,
}))
);
// 使用例
const stopStationIDList = trainData.map((i, index) => {
const [station, se, time] = i.split(",");
const Stations = stationList.map((a) =>
a.filter((d) => d.StationName == station)
);
const StationNumbers =
Stations &&
Stations.reduce((newArray, e) => {
return newArray.concat(e);
}, [])
.filter((d) => d.StationNumber)
.map((d) => d.StationNumber);
return StationNumbers[0];
});
const points =
trainPositionSwitch == "true"
? findReversalPoints(currentPosition, stopStationIDList)
: [];
const { height, width } = useWindowDimensions();
const { isLandscape } = useDeviceOrientationChange();
const [trueTrainID, setTrueTrainID] = useState();
useEffect(() => {
if (!data.trainNum) return;
const TD = trainList[data.trainNum];
setIsConcatNear(false);
setHeadStation();
setTailStation();
if (!TD) {
const specialTrainActualID = searchSpecialTrain(data.trainNum, trainList);
setTrueTrainID(specialTrainActualID || undefined);
setTrainData([]);
return;
}
setTrainData(TD.split("#").filter((d) => d != ""));
}, [data]);
//裏列車探索
useEffect(() => {
if (!data.trainNum) return;
const [returnArray, TDArray] = getInfluencedTrainData(data.trainNum);
setNearTrainIDList(returnArray);
setShowNearTrain(TDArray);
if (trainData.length == 0) return;
if (TDArray.length == 0) return;
let head;
let tail;
TDArray.forEach((d) => {
const [station, se, time] = d.split(",");
if (station == trainData[0].split(",")[0]) {
head = trainData[0].split(",")[0];
}
if (station == trainData[trainData.length - 1].split(",")[0]) {
tail = trainData[trainData.length - 1].split(",")[0];
}
});
if (head) setHeadStation(head);
else setHeadStation();
if (tail) setTailStation(tail);
else setTailStation();
}, [trainData, data]);
useEffect(() => {
//currentTrainData.Pos = "鴨川~端岡"; //test
if (!currentTrainData) return;
if (!currentTrainData?.Pos) return;
if (currentTrainData?.Pos.match("")) {
const pos = currentTrainData?.Pos.replace("(下り)", "")
.replace("(上り)", "")
.split("");
setCurrentPosition([
getStationData(pos[0], stationList),
getStationData(pos[1], stationList),
]);
} else {
setCurrentPosition([getStationData(currentTrainData?.Pos, stationList)]);
}
}, [currentTrainData]);
const replaceSpecialTrainDetail = (trainNum) => {
let TD = trainList[trainNum];
if (!TD) return;
setTrainData(TD.split("#").filter((d) => d != ""));
};
useEffect(() => {
//列車現在地アイコン表示スイッチ
AS.getItem("trainPositionSwitch")
.then((d) => {
if (d) setTrainPositionSwitch(d);
})
.catch((d) => AS.setItem("trainPositionSwitch", "false"));
}, []);
const openTrainInfo = (d) => {
const train = customTrainDataDetector(d);
let TrainNumber = "";
if (train.trainNumDistance != undefined) {
const timeInfo =
parseInt(d.replace("M", "").replace("D", "")) - train.trainNumDistance;
TrainNumber = timeInfo + "号";
}
const payload = {
data: {
trainNum: d,
limited: `${getTrainType(train.type).data}:${
train.trainName
}${TrainNumber}`,
},
navigate,
originalStationList,
from: "AllTrainDiagramView",
};
if (setTrainInfo) {
setTrainInfo(payload.data);
} else {
SheetManager.hide("EachTrainInfo").then(() => {
//0.1秒待機してから開く
setTimeout(() => {
SheetManager.show("EachTrainInfo", { payload });
}, 2);
});
}
};
return (
<View
style={{
backgroundColor: "#0099CC",
borderTopRadius: 5,
borderColor: "dark",
borderWidth: 1,
}}
>
{isLandscape || (
<View style={{ height: 26, width: "100%" }}>
<View
style={{
height: 6,
width: 45,
borderRadius: 100,
backgroundColor: "#f0f0f0",
marginVertical: 10,
alignSelf: "center",
}}
/>
</View>
)}
<View style={{ padding: 10, flexDirection: "row", alignItems: "center" }}>
<Text style={{ fontSize: 20, fontWeight: "bold", color: "white" }}>
{data.limited
? getType(data.limited.split(":")[0]) +
migrateTrainName(
data.limited.split(":")[1] ||
(trainData.length > 0
? trainData[trainData.length - 1].split(",")[0] + "行き"
: " ")
)
: ""}
</Text>
<View style={{ flex: 1 }} />
<Text style={{ fontSize: 20, fontWeight: "bold", color: "white" }}>
{data.trainNum}
{isConcatNear ? ` + ${nearTrainIDList}` : ""}
</Text>
{data.limited != undefined &&
getType(data.limited.split(":")[0]) &&
!data.limited.split(":")[1].match("サンポート") && (
<Ionicons
name="subway"
color="white"
size={30}
style={{ margin: 5 }}
onPress={() => {
LayoutAnimation.easeInEaseOut(); //setLoadingDelayData(true);
navigate("trainbase", {
info: "train.html?tn=" + data.trainNum,
from,
});
SheetManager.hide("EachTrainInfo");
}}
/>
)}
</View>
<DynamicHeaderScrollView
styles={styles}
scrollViewProps={scrollHandlers}
containerProps={{
style: {
maxHeight: isLandscape ? height - 94 : (height / 100) * 70,
},
}}
Max_Header_Height={from == "AllTrainDiagramView" ? 0 : 200}
Min_Header_Height={from == "AllTrainDiagramView" ? 0 : 80}
shortHeader={
from == "AllTrainDiagramView" ? (
<></>
) : (
<ShortHeader
currentTrainData={currentTrainData}
currentPosition={currentPosition}
nearTrainIDList={nearTrainIDList}
openTrainInfo={openTrainInfo}
/>
)
}
longHeader={
from == "AllTrainDiagramView" ? (
<></>
) : (
<LongHeader
currentTrainData={currentTrainData}
currentPosition={currentPosition}
nearTrainIDList={nearTrainIDList}
openTrainInfo={openTrainInfo}
/>
)
}
topStickyContent={
<ScrollStickyContent currentTrainData={currentTrainData} />
}
>
{headStation && !isConcatNear && (
<TouchableOpacity
onPress={() => {
const array = openBackTrainInfo(
headStation,
trainData,
showNearTrain
);
if (!array) return;
setTrainData(array);
setIsConcatNear(true);
}}
style={{
padding: 10,
flexDirection: "row",
borderColor: "blue",
borderWidth: 1,
margin: 10,
borderRadius: 5,
alignItems: "center",
}}
>
<Text style={{ fontSize: 18, fontWeight: "bold", color: "black" }}>
本当の始発駅を表示
</Text>
</TouchableOpacity>
)}
{/* <LottieView
autoPlay
loop
style={{ width: 150, height: 150, backgroundColor: "#fff" }}
source={require("../../assets/51690-loading-diamonds.json")}
/>
<Text>ほげほげふがふが</Text> */}
{trainData.length == 0 && trueTrainID && (
<TouchableOpacity
onPress={() => replaceSpecialTrainDetail(trueTrainID)}
style={{
padding: 10,
flexDirection: "row",
borderColor: "blue",
borderWidth: 1,
margin: 10,
borderRadius: 5,
alignItems: "center",
}}
>
<Text style={{ fontSize: 18, fontWeight: "bold", color: "black" }}>
本来の列車情報を表示
</Text>
</TouchableOpacity>
)}
{trainData.map((i, index) =>
i.split(",")[1] == "提" ? (
<DataFromButton i={i} />
) : (
<EachStopList
i={i}
index={index}
stationList={stationList}
points={points}
currentTrainData={currentTrainData}
openStationACFromEachTrainInfo={openStationACFromEachTrainInfo}
/>
)
)}
{tailStation && !isConcatNear && (
<TouchableOpacity
onPress={() => {
const array = openBackTrainInfo(
tailStation,
trainData,
showNearTrain
);
if (!array) return;
setTrainData(array);
setIsConcatNear(true);
}}
style={{
padding: 10,
flexDirection: "row",
borderColor: "blue",
borderWidth: 1,
margin: 10,
borderRadius: 5,
alignItems: "center",
}}
>
<Text style={{ fontSize: 18, fontWeight: "bold", color: "black" }}>
本当の終着駅を表示
</Text>
</TouchableOpacity>
)}
<View style={{ flexDirection: "row" }}>
<View
style={{
padding: 8,
flexDirection: "row",
borderBottomWidth: 1,
borderBottomColor: "#f0f0f0",
flex: 1,
}}
>
<Text style={{ fontSize: 20 }}> </Text>
<View style={{ flex: 1 }} />
</View>
</View>
</DynamicHeaderScrollView>
</View>
);
};
const styles = StyleSheet.create({
header: {
justifyContent: "center",
alignItems: "center",
left: 0,
right: 0,
//paddingTop: 10,
position: "absolute",
zIndex: 1,
backgroundColor: "f0f0f0",
},
headerText: {
color: "#fff",
fontSize: 25,
fontWeight: "bold",
textAlign: "center",
},
});

View File

@ -1,4 +1,4 @@
import React, { useRef } from "react";
import React, { useEffect, useRef } from "react";
import {
View,
LayoutAnimation,
@ -7,11 +7,17 @@ import {
Text,
TouchableOpacity,
Platform,
BackHandler,
} from "react-native";
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons";
import ActionSheet, { useScrollHandlers } from "react-native-actions-sheet";
import ActionSheet, {
SheetManager,
useScrollHandlers,
} from "react-native-actions-sheet";
import LottieView from "lottie-react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import ViewShot from "react-native-view-shot";
import * as Sharing from "expo-sharing";
import { useTrainDelayData } from "../../stateBox/useTrainDelayData";
export const JRSTraInfo = () => {
const { getTime, delayData, loadingDelayData, setLoadingDelayData } =
@ -19,6 +25,20 @@ export const JRSTraInfo = () => {
const actionSheetRef = useRef(null);
const scrollHandlers = useScrollHandlers("scrollview-1", actionSheetRef);
const insets = useSafeAreaInsets();
const viewShot = useRef(null);
const onCapture = async () => {
const url = await viewShot.current.capture();
const ok = await Sharing.isAvailableAsync();
if (ok) {
await Sharing.shareAsync(
"file://" + url,
(options = { mimeType: "image/jpeg", dialogTitle: "Share this image" })
);
}
};
return (
<ActionSheet
gestureEnabled
@ -34,6 +54,7 @@ export const JRSTraInfo = () => {
}
useBottomSafeAreaPadding={Platform.OS == "android"}
>
<Handler />
<View
style={{
backgroundColor: "#0099CC",
@ -42,87 +63,107 @@ export const JRSTraInfo = () => {
borderWidth: 1,
}}
>
<View style={{ height: 26, width: "100%" }}>
<ViewShot ref={viewShot} options={{ format: "jpg" }}>
<View
style={{
height: 6,
width: 45,
borderRadius: 100,
backgroundColor: "#f0f0f0",
marginVertical: 10,
alignSelf: "center",
}}
/>
</View>
<View
style={{ padding: 10, flexDirection: "row", alignItems: "center" }}
>
<Text style={{ fontSize: 30, fontWeight: "bold", color: "white" }}>
列車遅延速報EX
</Text>
<View style={{ flex: 1 }} />
{/* <TouchableOpacity style={{padding:10,backgroundColor:"white",alignContent:"center"}} onPress={() => {doFetch()}}>
<Text style={{fontSize:20,fontWeight:"bold",color:"#0099CC"}}>最新の情報へ更新</Text>
</TouchableOpacity> */}
<Text style={{ fontSize: 30, fontWeight: "bold", color: "white" }}>
{getTime
? getTime.toLocaleTimeString("ja-JP").split(":")[0] +
":" +
getTime.toLocaleTimeString("ja-JP").split(":")[1]
: NaN}{" "}
</Text>
<Ionicons
name="reload"
color="white"
size={30}
style={{ margin: 5 }}
onPress={() => {
LayoutAnimation.easeInEaseOut(), setLoadingDelayData(true);
}}
/>
</View>
<ScrollView {...scrollHandlers}>
style={{ height: 26, width: "100%", backgroundColor: "#0099CC" }}
>
<View
style={{
height: 6,
width: 45,
borderRadius: 100,
backgroundColor: "#f0f0f0",
marginVertical: 10,
alignSelf: "center",
}}
/>
</View>
<View
style={{
padding: 10,
backgroundColor: "white",
flexDirection: "row",
alignItems: "center",
backgroundColor: "#0099CC",
}}
>
{loadingDelayData ? (
<View style={{ alignItems: "center" }}>
<LottieView
autoPlay
loop
style={{ width: 150, height: 150, backgroundColor: "#fff" }}
source={require("../../assets/51690-loading-diamonds.json")}
/>
</View>
) : delayData ? (
delayData.map((d) => {
let data = d.split(" ");
return (
<View style={{ flexDirection: "row" }} key={data[1]}>
<Text style={{ flex: 15, fontSize: 20 }}>
{data[0].replace("\n", "")}
</Text>
<Text style={{ flex: 5, fontSize: 20 }}>{data[1]}</Text>
<Text style={{ flex: 6, fontSize: 20 }}>{data[3]}</Text>
</View>
);
})
) : (
<Text>現在5分以上の遅れはありません</Text>
)}
<Text style={{ fontSize: 30, fontWeight: "bold", color: "white" }}>
列車遅延速報EX
</Text>
<View style={{ flex: 1 }} />
{/* <TouchableOpacity style={{padding:10,backgroundColor:"white",alignContent:"center"}} onPress={() => {doFetch()}}>
<Text style={{fontSize:20,fontWeight:"bold",color:"#0099CC"}}>最新の情報へ更新</Text>
</TouchableOpacity> */}
<Text style={{ fontSize: 30, fontWeight: "bold", color: "white" }}>
{getTime
? getTime.toLocaleTimeString("ja-JP").split(":")[0] +
":" +
getTime.toLocaleTimeString("ja-JP").split(":")[1]
: NaN}{" "}
</Text>
<Ionicons
name="reload"
color="white"
size={30}
style={{ margin: 5 }}
onPress={() => {
LayoutAnimation.easeInEaseOut(), setLoadingDelayData(true);
}}
/>
</View>
<ScrollView {...scrollHandlers}>
<View
style={{
padding: 10,
backgroundColor: "white",
}}
>
{loadingDelayData ? (
<View style={{ alignItems: "center" }}>
<LottieView
autoPlay
loop
style={{ width: 150, height: 150, backgroundColor: "#fff" }}
source={require("../../assets/51690-loading-diamonds.json")}
/>
</View>
) : delayData ? (
delayData.map((d) => {
let data = d.split(" ");
return (
<View style={{ flexDirection: "row" }} key={data[1]}>
<Text style={{ flex: 15, fontSize: 18 }}>
{data[0].replace("\n", "")}
</Text>
<Text style={{ flex: 5, fontSize: 18 }}>{data[1]}</Text>
<Text style={{ flex: 6, fontSize: 18 }}>{data[3]}</Text>
</View>
);
})
) : (
<Text>現在5分以上の遅れはありません</Text>
)}
</View>
<View style={{ padding: 10 }}>
<Text style={{ fontSize: 20, fontWeight: "bold", color: "white" }}>
列車遅延情報EXについて
</Text>
<Text style={{ color: "white" }}>
列車遅延情報をJR四国公式列車運行情報より5分毎に取得しますTwitterにて投稿している内容と同一のものとなります
</Text>
</View>
<View style={{ padding: 10, backgroundColor: "#0099CC" }}>
<Text
style={{ fontSize: 20, fontWeight: "bold", color: "white" }}
>
列車遅延情報EXについて
</Text>
<Text style={{ color: "white" }}>
列車遅延情報をJR四国公式列車運行情報より5分毎に取得しますTwitterにて投稿している内容と同一のものとなります
</Text>
</View>
</ScrollView>
</ViewShot>
<View
style={{
padding: 10,
backgroundColor: "#0099CC",
flexDirection: "row",
justifyContent: "space-between",
}}
>
<TouchableOpacity
style={{
padding: 10,
@ -132,6 +173,8 @@ export const JRSTraInfo = () => {
margin: 10,
borderRadius: 5,
alignItems: "center",
backgroundColor: "#0099CC",
flex: 1,
}}
onPress={() =>
Linking.openURL("https://mstdn.y-zu.org/@JRSTraInfoEX")
@ -140,15 +183,45 @@ export const JRSTraInfo = () => {
<MaterialCommunityIcons name="mastodon" color="white" size={30} />
<View style={{ flex: 1 }} />
<Text style={{ fontSize: 25, fontWeight: "bold", color: "white" }}>
MastodonBOTはこちら
MastodonBOT
</Text>
<View style={{ flex: 1 }} />
<Text style={{ fontSize: 25, fontWeight: "bold", color: "white" }}>
</Text>
</TouchableOpacity>
</ScrollView>
<TouchableOpacity
style={{
padding: 10,
flexDirection: "row",
borderColor: "white",
borderWidth: 1,
margin: 10,
borderRadius: 5,
alignItems: "center",
backgroundColor: "#0099CC",
}}
onPress={onCapture}
>
<MaterialCommunityIcons
name="share-variant"
color="white"
size={30}
/>
</TouchableOpacity>
</View>
</View>
</ActionSheet>
);
};
const Handler = () => {
useEffect(() => {
const backAction = () => {
SheetManager.hide("JRSTraInfo");
return true;
};
const backHandler = BackHandler.addEventListener(
"hardwareBackPress",
backAction
);
return () => backHandler.remove();
}, []);
return <></>;
};

View File

@ -1,9 +1,16 @@
import React, { useState, useEffect } from "react";
import { View, Linking, Text, TouchableOpacity, Platform } from "react-native";
import {
View,
Linking,
Text,
TouchableOpacity,
BackHandler,
Platform,
} from "react-native";
import AutoHeightImage from "react-native-auto-height-image";
import { FontAwesome, Foundation, Ionicons } from "@expo/vector-icons";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import ActionSheet from "react-native-actions-sheet";
import ActionSheet, { SheetManager } from "react-native-actions-sheet";
import Sign from "../../components/駅名表/Sign";
import { TicketBox } from "../atom/TicketBox";
@ -25,6 +32,7 @@ export const StationDeteilView = (props) => {
} = props.payload;
const { busAndTrainData } = useBusAndTrainData();
const [trainBus, setTrainBus] = useState();
useEffect(() => {
if (!currentStation) return () => {};
const data = busAndTrainData.filter((d) => {
@ -60,6 +68,7 @@ export const StationDeteilView = (props) => {
}
useBottomSafeAreaPadding={Platform.OS == "android"}
>
<Handler />
<View
key={currentStation}
style={{
@ -417,6 +426,20 @@ const 駅構内図 = (props) => {
);
};
const Handler = () => {
useEffect(() => {
const backAction = () => {
SheetManager.hide("StationDetailView");
return true;
};
const backHandler = BackHandler.addEventListener(
"hardwareBackPress",
backAction
);
return () => backHandler.remove();
}, []);
return <></>;
};
const styleSheet = {
外枠: {
width: wp("80%"),

View File

@ -0,0 +1,25 @@
import * as React from "react";
import { StyleSheet, View } from "react-native";
import { WidgetPreview } from "react-native-android-widget";
import { HelloWidget } from "./HelloWidget";
export function HelloWidgetPreviewScreen() {
return (
<View style={styles.container}>
<WidgetPreview
renderWidget={() => <HelloWidget />}
width={200}
height={200}
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: "center",
justifyContent: "center",
},
});

View File

@ -0,0 +1,98 @@
import React from "react";
import {
FlexWidget,
TextWidget,
ListWidget,
} from "react-native-android-widget";
export function TraInfoEXWidget({ time, delayString }) {
return (
<FlexWidget
style={{
height: "match_parent",
width: "match_parent",
justifyContent: "center",
alignItems: "center",
backgroundColor: "#ffffff",
borderRadius: 16,
}}
clickAction="WIDGET_CLICK"
>
<FlexWidget
style={{
justifyContent: "center",
alignItems: "center",
backgroundColor: "#0099CC",
width: "match_parent",
flexDirection: "row",
padding: 10,
}}
>
<TextWidget
text={"列車遅延速報EX"}
style={{
fontSize: 30,
fontWeight: "bold",
fontFamily: "Inter",
color: "#fff",
}}
/>
<FlexWidget style={{ flex: 1 }} />
<TextWidget
text={time}
style={{
fontSize: 32,
fontFamily: "Inter",
color: "#fff",
}}
/>
</FlexWidget>
<ListWidget
style={{
flex: 1,
backgroundColor: "#fff",
width: "match_parent",
height: "match_parent",
padding: 10,
}}
>
{delayString ? (
delayString.map((d) => {
let data = d.split(" ");
return (
<FlexWidget
style={{
flexDirection: "row",
width: "match_parent",
backgroundColor: "#ffffff",
flex: 1,
}}
clickAction="WIDGET_CLICK"
key={data[1]}
>
<FlexText flex={3} text={data[0].replace("\n", "")} />
<FlexText flex={1} text={data[1]} />
<FlexText flex={1} text={data[3]} />
</FlexWidget>
);
})
) : (
<TextWidget
style={{
color: "#000000",
fontSize: 20,
}}
clickAction="WIDGET_CLICK"
text="現在、5分以上の遅れはありません。"
/>
)}
</ListWidget>
</FlexWidget>
);
}
const FlexText = ({ flex, text }) => (
<FlexWidget style={{ flex }}>
<TextWidget style={{ fontSize: 20, color: "#000000" }} text={text} />
</FlexWidget>
);

View File

@ -0,0 +1,46 @@
import React from "react";
import { TraInfoEXWidget } from "./TraInfoEXWidget";
import dayjs from "dayjs";
import { ToastAndroid } from "react-native";
const nameToWidget = {
// Hello will be the **name** with which we will reference our widget.
JR_shikoku_train_info: TraInfoEXWidget,
};
export async function widgetTaskHandler(props) {
const widgetInfo = props.widgetInfo;
const Widget = nameToWidget[widgetInfo.widgetName];
const time = dayjs().format("HH:mm");
ToastAndroid.show(
`Widget Action: ${props.widgetAction} ${time}`,
ToastAndroid.SHORT
);
const delayString = await fetch(
"https://script.google.com/macros/s/AKfycbyKxch7z7l8e07LXulRHqxjVoIiB13kcgvoToLE-rqlxLmLSKdlmqz0FI1F2EuA7Zfg/exec"
)
.then((response) => response.text())
.then((data) => {
if (data !== "") {
return data.split("^");
}
return null;
});
ToastAndroid.show(`${delayString}`, ToastAndroid.SHORT);
switch (props.widgetAction) {
case "WIDGET_ADDED":
case "WIDGET_UPDATE":
case "WIDGET_CLICK":
case "WIDGET_RESIZED":
// Not needed for now
props.renderWidget(<Widget time={time} delayString={delayString} />);
break;
case "WIDGET_DELETED":
// Not needed for now
break;
default:
break;
}
}

View File

@ -0,0 +1,106 @@
import { ScrollView, View, Animated, Platform } from "react-native";
import React, { useRef } from "react";
export const DynamicHeaderScrollView = (props) => {
const {
Max_Header_Height = 200,
Min_Header_Height = 80,
children,
scrollViewProps = {},
containerProps = {},
shortHeader = <></>,
longHeader = <></>,
topStickyContent,
styles,
} = props;
const scrollOffsetY = useRef(new Animated.Value(0)).current;
const Scroll_Distance = Max_Header_Height - Min_Header_Height;
const animatedHeaderHeight = scrollOffsetY.interpolate({
inputRange: [Scroll_Distance, Scroll_Distance + 30],
outputRange: [Max_Header_Height, 0],
extrapolate: "clamp",
});
const animatedHeaderHeight2 = scrollOffsetY.interpolate({
inputRange: [Scroll_Distance, Scroll_Distance + 30],
outputRange: [Max_Header_Height, Min_Header_Height],
extrapolate: "clamp",
});
const animatedHeaderVisible = scrollOffsetY.interpolate({
inputRange: [Scroll_Distance - 30, Scroll_Distance],
outputRange: [1, 0],
extrapolate: "clamp",
});
const animatedHeaderVisible2 = scrollOffsetY.interpolate({
inputRange: [Scroll_Distance - 30, Scroll_Distance + 30],
outputRange: [0, 1],
extrapolate: "clamp",
});
return (
<View {...containerProps}>
<View style={{ zIndex: 1 }}>
<Animated.View
style={[
styles.header,
{
height: animatedHeaderHeight2,
backgroundColor: "#0099CC",
margin: 0,
top: 0,
opacity: animatedHeaderVisible2,
},
]}
>
{shortHeader}
</Animated.View>
<Animated.View
style={[
styles.header,
{
height: animatedHeaderHeight,
backgroundColor: "#0099CC",
opacity: animatedHeaderVisible,
top: 0,
},
]}
>
{longHeader}
</Animated.View>
</View>
<ScrollView
{...scrollViewProps}
style={{
backgroundColor: "white",
zIndex: 0,
}}
stickyHeaderIndices={[1]}
scrollEventThrottle={16}
onScroll={Animated.event(
[{ nativeEvent: { contentOffset: { y: scrollOffsetY } } }],
{ useNativeDriver: false }
)}
>
<View
style={{
height: Scroll_Distance,
flexDirection: "column",
}}
/>
{topStickyContent && (
<View
style={{
paddingTop: Min_Header_Height,
flexDirection: "column",
}}
index={1}
>
{topStickyContent}
</View>
)}
{children}
</ScrollView>
</View>
);
};

View File

@ -1,5 +1,6 @@
import React, { useState, useEffect } from "react";
import React, { useState, useEffect, useLayoutEffect } from "react";
import { View, Text, TouchableOpacity, Linking } from "react-native";
import * as ExpoFelicaReader from "../modules/expo-felica-reader/src";
import * as Updates from "expo-updates";
import StatusbarDetect from "../StatusbarDetect";
import { AS } from "../storageControl";
@ -16,7 +17,7 @@ export default function Setting(props) {
const [usePDFView, setUsePDFView] = useState(false);
const [trainMenu, setTrainMenu] = useState(false);
const [trainPosition, setTrainPosition] = useState(false);
useEffect(() => {
useLayoutEffect(() => {
AS.getItem("iconSwitch").then(setIconSetting);
AS.getItem("mapSwitch").then(setMapSwitch);
AS.getItem("stationSwitch").then(setStationMenu);
@ -24,6 +25,22 @@ export default function Setting(props) {
AS.getItem("trainSwitch").then(setTrainMenu);
AS.getItem("trainPositionSwitch").then(setTrainPosition);
}, []);
const testNFC = async () => {
const resulit = await ExpoFelicaReader.scan();
alert(resulit);
};
const updateAndReload = () => {
Promise.all([
AS.setItem("iconSwitch", iconSetting.toString()),
AS.setItem("mapSwitch", mapSwitch.toString()),
AS.setItem("stationSwitch", stationMenu.toString()),
AS.setItem("usePDFView", usePDFView.toString()),
AS.setItem("trainSwitch", trainMenu.toString()),
AS.setItem("trainPositionSwitch", trainPosition.toString()),
]).then(() => {
Updates.reloadAsync();
});
};
return (
<View style={{ height: "100%", backgroundColor: "#0099CC" }}>
<View style={{ flex: 1, backgroundColor: "white" }}>
@ -54,10 +71,10 @@ export default function Setting(props) {
列車アイコンを表示する
</Text>
<View style={{ flex: 1 }} />
<Switch
value={iconSetting == "true" ? true : false}
color={iconSetting == "true" ? "red" : null}
onValueChange={(value) => setIconSetting(value.toString())}
<SimpleSwitch
bool={iconSetting}
setBool={setIconSetting}
color="red"
/>
</View>
<View style={{ flexDirection: "row", padding: 10 }}>
@ -73,11 +90,7 @@ export default function Setting(props) {
マップを表示する(beta)
</Text>
<View style={{ flex: 1 }} />
<Switch
value={mapSwitch == "true" ? true : false}
color={mapSwitch == "true" ? "red" : null}
onValueChange={(value) => setMapSwitch(value.toString())}
/>
<SimpleSwitch bool={mapSwitch} setBool={setMapSwitch} color="red" />
</View>
<View style={{ flexDirection: "row", padding: 10 }}>
<Text
@ -92,10 +105,10 @@ export default function Setting(props) {
駅メニューを表示
</Text>
<View style={{ flex: 1 }} />
<Switch
value={stationMenu == "true" ? true : false}
color={stationMenu == "true" ? "red" : null}
onValueChange={(value) => setStationMenu(value.toString())}
<SimpleSwitch
bool={stationMenu}
setBool={setStationMenu}
color="red"
/>
</View>
<View style={{ flexDirection: "row", padding: 10 }}>
@ -111,10 +124,10 @@ export default function Setting(props) {
時刻表PDFをアプリ外で表示
</Text>
<View style={{ flex: 1 }} />
<Switch
value={usePDFView == "true" ? true : false}
color={usePDFView == "true" ? "red" : null}
onValueChange={(value) => setUsePDFView(value.toString())}
<SimpleSwitch
bool={usePDFView}
setBool={setUsePDFView}
color="red"
/>
</View>
<View style={{ flexDirection: "row", padding: 10 }}>
@ -130,11 +143,7 @@ export default function Setting(props) {
列車メニュー
</Text>
<View style={{ flex: 1 }} />
<Switch
value={trainMenu == "true" ? true : false}
color={trainMenu == "true" ? "red" : null}
onValueChange={(value) => setTrainMenu(value.toString())}
/>
<SimpleSwitch bool={trainMenu} setBool={setTrainMenu} color="red" />
</View>
<View style={{ flexDirection: "row", padding: 10 }}>
<Text
@ -149,10 +158,10 @@ export default function Setting(props) {
列車現在位置表示(alpha)
</Text>
<View style={{ flex: 1 }} />
<Switch
value={trainPosition == "true" ? true : false}
color={trainPosition == "true" ? "red" : null}
onValueChange={(value) => setTrainPosition(value.toString())}
<SimpleSwitch
bool={trainPosition}
setBool={setTrainPosition}
color="red"
/>
</View>
<View style={{ flexDirection: "row", padding: 10 }}>
@ -165,11 +174,14 @@ export default function Setting(props) {
textAlignVertical: "center",
}}
>
内部バージョン: 4.6.4
内部バージョン: 5.0
</Text>
<View style={{ flex: 1 }} />
</View>
<View style={{ flexDirection: "row", padding: 10 }}>
<TouchableOpacity
style={{ flexDirection: "row", padding: 10 }}
//onPress={testNFC}
>
<Text
style={{
fontSize: 25,
@ -182,7 +194,7 @@ export default function Setting(props) {
releaseChannel: {Updates.channel}
</Text>
<View style={{ flex: 1 }} />
</View>
</TouchableOpacity>
<TouchableOpacity
style={{ flexDirection: "row", padding: 10 }}
onPress={() =>
@ -216,18 +228,7 @@ export default function Setting(props) {
borderRadius: 5,
alignItems: "center",
}}
onPress={() => {
Promise.all([
AS.setItem("iconSwitch", iconSetting.toString()),
AS.setItem("mapSwitch", mapSwitch.toString()),
AS.setItem("stationSwitch", stationMenu.toString()),
AS.setItem("usePDFView", usePDFView.toString()),
AS.setItem("trainSwitch", trainMenu.toString()),
AS.setItem("trainPositionSwitch", trainPosition.toString()),
]).then(() => {
Updates.reloadAsync();
});
}}
onPress={updateAndReload}
>
<View style={{ flex: 1 }} />
<Text style={{ fontSize: 25, fontWeight: "bold", color: "white" }}>
@ -238,3 +239,10 @@ export default function Setting(props) {
</View>
);
}
const SimpleSwitch = ({ bool, setBool, color }) => (
<Switch
value={bool == "true" ? true : false}
color={bool == "true" ? color : null}
onValueChange={(value) => setBool(value.toString())}
/>
);

View File

@ -6,10 +6,11 @@ export default function TrainMenu({
navigation: { navigate },
webview,
stationData,
style,
}) {
const mapRef = useRef();
return (
<View style={{ height: "100%", backgroundColor: "#0099CC" }}>
<View style={{ height: "100%", backgroundColor: "#0099CC", ...style }}>
<MapView
style={{ flex: 1, width: "100%", height: "100%" }}
showsUserLocation={true}
@ -46,65 +47,69 @@ export default function TrainMenu({
webview.current?.injectJavaScript(
`MoveDisplayStation('${d}_${D.MyStation}_${D.Station_JP}')`
);
navigate("Apps");
if (navigate) navigate("Apps");
}}
></Marker>
);
})
)}
</MapView>
<View style={{ flexDirection: "row" }}>
<UsefulBox
backgroundColor={"#F89038"}
icon="train-car"
flex={1}
onPressButton={() =>
navigate("howto", {
info: "https://train.jr-shikoku.co.jp/usage.htm",
})
}
{navigate && (
<View style={{ flexDirection: "row" }}>
<UsefulBox
backgroundColor={"#F89038"}
icon="train-car"
flex={1}
onPressButton={() =>
navigate("howto", {
info: "https://train.jr-shikoku.co.jp/usage.htm",
})
}
>
使い方
</UsefulBox>
<UsefulBox
backgroundColor={"#EA4752"}
icon="star"
flex={1}
onPressButton={() => navigate("favoriteList")}
>
お気に入り
</UsefulBox>
<UsefulBox
backgroundColor={"#91C31F"}
icon="clipboard-list-outline"
flex={1}
onPressButton={() =>
Linking.openURL(
"https://nexcloud.haruk.in/apps/forms/ZRHjWFF7znr5Xjr2"
)
}
>
フィードバック
</UsefulBox>
</View>
)}
{navigate && (
<TouchableOpacity
style={{
padding: 10,
flexDirection: "row",
borderColor: "white",
borderWidth: 1,
margin: 10,
borderRadius: 5,
alignItems: "center",
}}
onPress={() => navigate("Apps")}
>
使い方
</UsefulBox>
<UsefulBox
backgroundColor={"#EA4752"}
icon="star"
flex={1}
onPressButton={() => navigate("favoriteList")}
>
お気に入り
</UsefulBox>
<UsefulBox
backgroundColor={"#91C31F"}
icon="clipboard-list-outline"
flex={1}
onPressButton={() =>
Linking.openURL(
"https://nexcloud.haruk.in/apps/forms/ZRHjWFF7znr5Xjr2"
)
}
>
この機能のフィードバック
</UsefulBox>
</View>
<TouchableOpacity
style={{
padding: 10,
flexDirection: "row",
borderColor: "white",
borderWidth: 1,
margin: 10,
borderRadius: 5,
alignItems: "center",
}}
onPress={() => navigate("Apps")}
>
<View style={{ flex: 1 }} />
<Text style={{ fontSize: 25, fontWeight: "bold", color: "white" }}>
閉じる
</Text>
<View style={{ flex: 1 }} />
</TouchableOpacity>
<View style={{ flex: 1 }} />
<Text style={{ fontSize: 25, fontWeight: "bold", color: "white" }}>
閉じる
</Text>
<View style={{ flex: 1 }} />
</TouchableOpacity>
)}
</View>
);
}
@ -115,14 +120,14 @@ const UsefulBox = (props) => {
style={{
flex: flex,
backgroundColor: backgroundColor,
padding: 10,
padding: 5,
alignItems: "center",
margin: 2,
}}
onPress={onPressButton}
>
<MaterialCommunityIcons name={icon} color="white" size={50} />
<Text style={{ color: "white", fontWeight: "bold", fontSize: 18 }}>
<Text style={{ color: "white", fontWeight: "bold", fontSize: 16 }}>
{children}
</Text>
</TouchableOpacity>

View File

@ -390,7 +390,7 @@ const TrainName = ({
<View style={{ flex: 9 }}>
<Text
style={{
fontSize: trainName.length > 6 ? parseInt("13%") : parseInt("18%"),
fontSize: trainName.length > 6 ? parseInt("12%") : parseInt("16%"),
color: color,
fontWeight: "bold",
}}
@ -406,7 +406,7 @@ const LastStation = ({ lastStation }) => {
<View style={{ flex: 4, flexDirection: "row" }}>
<Text
style={{
fontSize: lastStation.length > 4 ? parseInt("13%") : parseInt("18%"),
fontSize: lastStation.length > 4 ? parseInt("12%") : parseInt("16%"),
color: "white",
fontWeight: "bold",
}}
@ -421,7 +421,7 @@ const DependTime = ({ time }) => (
<View style={{ flex: 3 }}>
<Text
style={{
fontSize: parseInt("18%"),
fontSize: parseInt("16%"),
color: "white",
fontWeight: "bold",
}}
@ -436,7 +436,7 @@ const StatusAndDelay = ({ trainDelayStatus }) => {
<View style={{ flex: 4 }}>
<Text
style={{
fontSize: parseInt("18%"),
fontSize: parseInt("16%"),
color: "white",
fontWeight: "bold",
paddingLeft: 1,
@ -464,7 +464,7 @@ const Description = ({ info, numberOfLines = 0, onClick }) => (
<View style={{ flex: 4 }}>
<Text
style={{
fontSize: parseInt("18%"),
fontSize: parseInt("16%"),
color: "green",
fontWeight: "bold",
}}

View File

@ -1 +1 @@
export const news = "2023-12-25";
export const news = "2024-3-10";

View File

@ -29,6 +29,12 @@
},
"production4.6": {
"channel": "costoco"
},
"beta5.0": {
"channel": "dshopping"
},
"production5.0": {
"channel": "dmm"
}
},
"submit": {

View File

@ -5,8 +5,8 @@ import { WebView } from "react-native-webview";
export default ({ navigation: { navigate }, route }) => {
const { info, goTo, useShow } = route.params;
const onExit = () => {
navigate(goTo);
useShow();
navigate(goTo || "Apps");
useShow && useShow();
};
return (
<View style={styles.View}>

11
index.js Normal file
View File

@ -0,0 +1,11 @@
import { registerRootComponent } from "expo";
import { registerWidgetTaskHandler } from "react-native-android-widget";
import App from "./App";
import { widgetTaskHandler } from "./components/AndroidWidget/widget-task-handler";
// registerRootComponent calls AppRegistry.registerComponent('main', () => App);
// It also ensures that whether you load the app in Expo Go or in a native build,
// the environment is set up appropriately
registerRootComponent(App);
registerWidgetTaskHandler(widgetTaskHandler);

View File

@ -0,0 +1,113 @@
// arrayは現在位置の駅ID(駅在宅の場合は1つの配列、駅間の場合は2つの配列)
// stopStationIDListは停車駅の駅IDの配列 [Y01,Y02,Y05,...]
export const findReversalPoints = (array, stopStationIDList) => {
try {
if (!stopStationIDList) return [];
// arrayが二次元配列だったら早期リターン
if (!array instanceof Array) return [];
if (!array) return [];
if (array[0] instanceof Array) return [];
const arrayNumber = array.map((d) => ({
line: d
.split("")
.filter((s) => "A" < s && s < "Z")
.join(""),
ID: d
.split("")
.filter((s) => "0" <= s && s <= "9")
.join(""),
}));
const stopStationIDListNumber = stopStationIDList.map((d) => {
if (!d) return { line: [], ID: [] };
return {
line: d
.split("")
.filter((s) => "A" < s && s < "Z")
.join(""),
ID: d
.split("")
.filter((s) => "0" <= s && s <= "9")
.join(""),
};
});
// 完全一致
if (array.length == 1) {
const index = stopStationIDList.indexOf(array[0]);
if (index != -1) return [index];
// 通過駅の場合
for (let i = 0; i < stopStationIDListNumber.length - 1; i++) {
if (stopStationIDListNumber[i].ID < arrayNumber[0].ID) {
if (stopStationIDListNumber[i + 1].ID > arrayNumber[0].ID) {
return [i + 1];
}
}
if (stopStationIDListNumber[i].ID > arrayNumber[0].ID) {
if (stopStationIDListNumber[i + 1].ID < arrayNumber[0].ID) {
return [i + 1];
}
}
}
}
// 駅間の場合
if (array.length == 2) {
const index1 = stopStationIDList.indexOf(array[0]);
const index2 = stopStationIDList.indexOf(array[1]);
if (index1 != -1 && index2 != -1) {
// 駅間で通過駅も無い場合
if (index1 < index2) {
if (index1 + 1 == index2) {
return [index2];
} else {
const returnArray = [];
for (let i = index1 + 1; i <= index2; i++) {
returnArray.push(i);
}
return returnArray;
}
}
if (index1 > index2) {
if (index2 + 1 == index1) return [index1];
else {
const returnArray = [];
for (let i = index2 + 1; i <= index1; i++) {
returnArray.push(i);
}
return returnArray;
}
}
} else {
const getNearStationID = (stationID) => {
for (let i = 0; i <= stopStationIDListNumber.length; i++) {
if (stopStationIDListNumber[i].ID < stationID) {
if (stopStationIDListNumber[i + 1].ID > stationID) {
return i + 1;
}
}
if (stopStationIDListNumber[i].ID > stationID) {
if (stopStationIDListNumber[i + 1].ID < stationID) {
return i + 1;
}
}
}
};
let newIndex1 = index1;
let newIndex2 = index2;
if (index1 == -1) {
newIndex1 = getNearStationID(arrayNumber[0].ID);
}
if (index2 == -1) {
newIndex2 = getNearStationID(arrayNumber[1].ID);
}
if (newIndex1 && newIndex2) {
return [newIndex1, newIndex2];
}
// 通過駅の場合
}
return [];
}
} catch (e) {
console.log(e);
}
};

View File

@ -0,0 +1,15 @@
// 駅名から駅情報を取得する
//stationName: 駅名
//stationList: 駅情報リスト
export const getStationData = (stationName, stationList) => {
const Stations = stationList.map((a) =>
a.filter((d) => d.StationName == stationName)
);
const Station =
Stations &&
Stations.reduce((newArray, e) => {
return newArray.concat(e);
}, []);
if (!Station[0]) return [];
return Station.map((d) => d.StationNumber)[0];
};

View File

@ -0,0 +1,11 @@
// 種別判定
export const getType = (string) => {
switch (string) {
case "express":
return "特急";
case "rapid":
return "快速";
default:
return "";
}
};

View File

@ -0,0 +1,7 @@
// Description: 電車名の変換を行う。
// マリンライナーやマリン表記をマリンライナーに変換する。
export const migrateTrainName = (string) => {
return string
.replace("マリン", "マリンライナー")
.replace("ライナーライナー", "ライナー");
};

View File

@ -0,0 +1,68 @@
export const openBackTrainInfo = (stationInfo, trainData, showNearTrain) => {
const migrationArray = (stationInfo) => {
const mainTrainStationPosition = trainData.findIndex(
(d) => d.split(",")[0] == stationInfo
);
const relationMain = (() => {
if (mainTrainStationPosition == 0) return "head";
if (mainTrainStationPosition == trainData.length - 1) return "tail";
return "middle";
})();
const subTrainStationPosition = showNearTrain.findIndex(
(d) => d.split(",")[0] == stationInfo
);
const relationSub = (() => {
if (subTrainStationPosition == 0) return "head";
if (subTrainStationPosition == showNearTrain.length - 1) return "tail";
return "middle";
})();
switch (relationMain) {
case "head":
if (relationSub == "head") {
return;
} else if (relationSub == "tail") {
return [
...showNearTrain.slice(0, subTrainStationPosition),
...trainData,
];
} else if (relationSub == "middle") {
return [
...showNearTrain.slice(0, subTrainStationPosition),
...trainData,
];
} else return;
case "tail":
if (relationSub == "head") {
return [
...trainData.slice(0, mainTrainStationPosition),
...showNearTrain,
];
} else if (relationSub == "tail") {
return;
} else if (relationSub == "middle") {
return [
...trainData.slice(0, mainTrainStationPosition),
...showNearTrain.slice(subTrainStationPosition),
];
} else return;
case "middle":
if (relationSub == "head") {
return [
...trainData.slice(0, mainTrainStationPosition),
...showNearTrain,
];
} else if (relationSub == "tail") {
return [
...showNearTrain.slice(0, subTrainStationPosition),
...trainData.slice(mainTrainStationPosition),
];
} else return;
}
};
const array = migrationArray(stationInfo);
if (!array) return null;
return array;
};

View File

@ -0,0 +1,13 @@
// S列番の列車からDやMの列車を検索する
export const searchSpecialTrain = (trainNum, trainList) => {
const searchBase = trainNum.replace("S", "").replace("X", "");
const search = (text) => {
const TD = trainList[searchBase + text];
if (TD) {
return true;
}
return false;
};
if (search("D")) return searchBase + "D";
if (search("M")) return searchBase + "M";
};

35
menu.js
View File

@ -395,11 +395,11 @@ const JRSTraInfoBox = () => {
let data = d.split(" ");
return (
<View style={{ flexDirection: "row" }} key={data[1] + "key"}>
<Text style={{ flex: 15, fontSize: 20 }}>
<Text style={{ flex: 15, fontSize: 18 }}>
{data[0].replace("\n", "")}
</Text>
<Text style={{ flex: 5, fontSize: 20 }}>{data[1]}</Text>
<Text style={{ flex: 6, fontSize: 20 }}>{data[3]}</Text>
<Text style={{ flex: 5, fontSize: 18 }}>{data[1]}</Text>
<Text style={{ flex: 6, fontSize: 18 }}>{data[3]}</Text>
</View>
);
})
@ -611,6 +611,11 @@ const FixedContentBottom = (props) => {
}}
>
{[
{
url: "https://twitter.com/jr_shikoku_info",
name: "JR四国列車運行情報",
},
{
url: "https://twitter.com/JRshikoku_eigyo",
name: "JR四国営業部【公式】",
@ -623,14 +628,6 @@ const FixedContentBottom = (props) => {
url: "https://twitter.com/JRshikoku_osaka",
name: "JR四国 大阪営業部【公式】",
},
{
url: "https://twitter.com/jr_shikoku_info",
name: "JR四国列車運行情報【公式】",
},
{
url: "https://twitter.com/Smile_Eki_Chan",
name: "すまいるえきちゃん♡JR四国【公式】",
},
{
url: "https://twitter.com/jrs_matsuyama",
name: "JR四国 松山駅 【公式】",
@ -647,18 +644,26 @@ const FixedContentBottom = (props) => {
url: "https://twitter.com/jrshikoku_uwjm",
name: "JR四国 宇和島駅【公式】",
},
{
url: "https://twitter.com/jrshikoku_wkama",
name: "JR四国 ワープ高松支店【公式】",
},
{
url: "https://twitter.com/JRshikoku_wkoch",
name: "JR四国 ワープ高知支店【公式】",
},
{
url: "https://twitter.com/jrshikoku_nihaw",
name: "JR四国 ワープ新居浜営業所【公式】",
},
{
url: "https://twitter.com/Yoakemonogatari",
name: "志国土佐 時代の夜明けのものがたり【公式】",
},
{
url: "https://twitter.com/Smile_Eki_Chan",
name: "すまいるえきちゃん♡JR四国【公式】",
},
{
url: "https://twitter.com/sper_ponchan",
name: "しこくたぬきのぽんちゃん 【四国家サポーターズクラブ】",
},
].map((d) => (
<ListItem onPress={() => Linking.openURL(d.url)}>
<Text>{d.name}</Text>

View File

@ -0,0 +1,92 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'maven-publish'
group = 'expo.modules.felicareader'
version = '0.2.0'
buildscript {
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
if (expoModulesCorePlugin.exists()) {
apply from: expoModulesCorePlugin
applyKotlinExpoModulesCorePlugin()
}
// Simple helper that allows the root project to override versions declared by this library.
ext.safeExtGet = { prop, fallback ->
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
// Ensures backward compatibility
ext.getKotlinVersion = {
if (ext.has("kotlinVersion")) {
ext.kotlinVersion()
} else {
ext.safeExtGet("kotlinVersion", "1.8.10")
}
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${getKotlinVersion()}")
}
}
afterEvaluate {
publishing {
publications {
release(MavenPublication) {
from components.release
}
}
repositories {
maven {
url = mavenLocal().url
}
}
}
}
android {
compileSdkVersion safeExtGet("compileSdkVersion", 33)
def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
if (agpVersion.tokenize('.')[0].toInteger() < 8) {
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.majorVersion
}
}
namespace "expo.modules.felicareader"
defaultConfig {
minSdkVersion safeExtGet("minSdkVersion", 21)
targetSdkVersion safeExtGet("targetSdkVersion", 34)
versionCode 2
versionName "0.2.0"
}
lintOptions {
abortOnError false
}
publishing {
singleVariant("release") {
withSourcesJar()
}
}
}
repositories {
mavenCentral()
}
dependencies {
implementation project(':expo-modules-core')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
}

View File

@ -0,0 +1,2 @@
<manifest>
</manifest>

View File

@ -0,0 +1,34 @@
package expo.modules.felicareader
import expo.modules.kotlin.modules.Module
import expo.modules.kotlin.modules.ModuleDefinition
import expo.modules.kotlin.Promise
import android.nfc.NfcAdapter
import android.nfc.Tag
class NfcReaderCallback(private val promise: Promise) : NfcAdapter.ReaderCallback {
override fun onTagDiscovered(tag: Tag?) {
val idmString = tag?.id?.joinToString("") { "%02x".format(it) }
promise.resolve(idmString)
}
}
class ExpoFelicaReaderModule : Module() {
var nfcAdapter: NfcAdapter? = null
override fun definition() = ModuleDefinition {
Name("ExpoFelicaReader")
AsyncFunction("scan") { promise: Promise ->
nfcAdapter?.enableReaderMode(
appContext.currentActivity,
NfcReaderCallback(promise),
NfcAdapter.FLAG_READER_NFC_F,
null
)
}
OnCreate {
nfcAdapter = NfcAdapter.getDefaultAdapter(appContext.reactContext)
}
}
}

View File

@ -0,0 +1,9 @@
{
"platforms": ["ios", "tvos", "android", "web"],
"ios": {
"modules": ["ExpoFelicaReaderModule"]
},
"android": {
"modules": ["expo.modules.felicareader.ExpoFelicaReaderModule"]
}
}

View File

@ -0,0 +1,27 @@
require 'json'
package = JSON.parse(File.read(File.join(__dir__, '../../../', 'package.json')))
Pod::Spec.new do |s|
s.name = 'ExpoFelicaReader'
s.version = "0.1.0"
s.summary = "A module for reading Felica cards in ExpoKit."
s.description = "Expo FeliCa reader module"
s.license = "MIT"
s.author = "Daiki Urata (https://github.com/7nohe)"
s.homepage = "https://github.com/7nohe/expo-felica-reader#readme"
s.platform = :ios, '13.0'
s.swift_version = '5.4'
s.source = { git: 'https://github.com/7nohe/expo-felica-reader' }
s.static_framework = true
s.dependency 'ExpoModulesCore'
# Swift/Objective-C compatibility
s.pod_target_xcconfig = {
'DEFINES_MODULE' => 'YES',
'SWIFT_COMPILATION_MODE' => 'wholemodule'
}
s.source_files = "**/*.{h,m,swift}"
end

View File

@ -0,0 +1,70 @@
import ExpoModulesCore
import CoreNFC
public class ExpoFelicaReaderModule: Module {
var session: NfcSession?
var semaphore: DispatchSemaphore?
public func definition() -> ModuleDefinition {
Name("ExpoFelicaReader")
AsyncFunction("scan") { (promise: Promise) in
session?.startSession()
DispatchQueue.global(qos: .background).async {
self.semaphore?.wait()
promise.resolve(self.session?.message)
}
}
OnCreate {
semaphore = DispatchSemaphore(value: 0)
session = NfcSession(semaphore: semaphore!)
}
}
}
class NfcSession: NSObject, NFCTagReaderSessionDelegate {
var session: NFCTagReaderSession?
let semaphore: DispatchSemaphore
var message: String?
init (semaphore: DispatchSemaphore) {
self.semaphore = semaphore
}
func tagReaderSessionDidBecomeActive(_ session: NFCTagReaderSession) {
print("tagReaderSessionDidBecomeActive")
}
func tagReaderSession(_ session: NFCTagReaderSession, didInvalidateWithError error: Error) {
print("Error: \(error.localizedDescription)")
self.semaphore.signal()
self.session = nil
}
func tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) {
let tag = tags.first!
session.connect(to: tag) { error in
if nil != error {
session.invalidate(errorMessage: "Error!")
self.semaphore.signal()
return
}
guard case .feliCa(let feliCaTag) = tag else {
session.invalidate(errorMessage: "This is not FeliCa!")
self.semaphore.signal()
return
}
let idm = feliCaTag.currentIDm.map { String(format: "%.2hhx", $0) }.joined()
self.message = idm
session.alertMessage = "Success!"
session.invalidate()
self.semaphore.signal()
}
}
func startSession() {
self.session = NFCTagReaderSession(pollingOption: [.iso14443, .iso15693, .iso18092], delegate: self, queue: nil)
session?.alertMessage = "Touch your FeliCa!"
session?.begin()
}
}

View File

@ -0,0 +1,5 @@
import { requireNativeModule } from 'expo-modules-core';
// It loads the native module object from the JSI or falls back to
// the bridge module (from NativeModulesProxy) if the remote debugger is on.
export default requireNativeModule('ExpoFelicaReader');

View File

@ -0,0 +1,5 @@
import ExpoFelicaReaderModule from "./ExpoFelicaReaderModule";
export async function scan(): Promise<string> {
return await ExpoFelicaReaderModule.scan();
}

View File

@ -1,5 +1,5 @@
{
"main": "node_modules/expo/AppEntry.js",
"main": "index.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
@ -7,48 +7,55 @@
"eject": "expo eject"
},
"dependencies": {
"@expo/vector-icons": "^13.0.0",
"@react-native-async-storage/async-storage": "1.18.2",
"@expo/ngrok": "^4.1.0",
"@expo/vector-icons": "^14.0.0",
"@react-native-async-storage/async-storage": "1.21.0",
"@react-native-community/masked-view": "0.1.10",
"@react-navigation/bottom-tabs": "^5.11.11",
"@react-navigation/native": "^5.9.4",
"@react-navigation/stack": "^5.14.5",
"dayjs": "^1.11.9",
"eas-cli": "^5.9.1",
"expo": "^49.0.21",
"expo-device": "~5.4.0",
"expo-font": "~11.4.0",
"expo-location": "~16.1.0",
"expo-notifications": "~0.20.1",
"expo-updates": "~0.18.17",
"expo-web-browser": "~12.3.2",
"expo": "^50.0.11",
"expo-dev-client": "~3.3.9",
"expo-device": "~5.9.3",
"expo-font": "~11.10.3",
"expo-location": "~16.5.5",
"expo-notifications": "~0.27.6",
"expo-screen-orientation": "~6.4.1",
"expo-sharing": "~11.10.0",
"expo-updates": "~0.24.11",
"expo-web-browser": "~12.8.2",
"firebase": "8.2.3",
"lottie-react-native": "5.1.6",
"lottie-react-native": "6.5.1",
"native-base": "^2.15.2",
"npm": "^7.18.1",
"pushy-react-native": "^1.0.18",
"react": "18.2.0",
"react-native": "0.72.6",
"react-native": "0.73.4",
"react-native-actions-sheet": "0.8.21",
"react-native-android-widget": "^0.11.2",
"react-native-auto-height-image": "^3.2.4",
"react-native-elements": "^3.4.2",
"react-native-gesture-handler": "~2.12.0",
"react-native-maps": "1.7.1",
"react-native-reanimated": "^3.6.1",
"react-native-gesture-handler": "~2.14.0",
"react-native-maps": "1.10.0",
"react-native-reanimated": "~3.6.2",
"react-native-remote-svg": "^2.0.6",
"react-native-responsive-screen": "^1.4.2",
"react-native-router-flux": "^4.3.1",
"react-native-safe-area-context": "4.6.3",
"react-native-screens": "~3.22.0",
"react-native-safe-area-context": "4.8.2",
"react-native-screens": "~3.29.0",
"react-native-snap-carousel": "^3.9.1",
"react-native-storage": "^1.0.1",
"react-native-svg": "13.9.0",
"react-native-svg": "14.1.0",
"react-native-svg-uri": "^1.2.3",
"react-native-vector-icons": "^8.1.0",
"react-native-webview": "^13.6.3"
"react-native-view-shot": "3.8.0",
"react-native-webview": "13.6.4",
"typescript": "^5.3.0"
},
"devDependencies": {
"babel-preset-expo": "^9.5.0"
"babel-preset-expo": "^10.0.0"
},
"private": true
}

View File

@ -1,4 +1,5 @@
import React, { createContext, useContext, useState } from "react";
import React, { createContext, useContext, useState, useEffect } from "react";
import useInterval from "../lib/useInterval";
const initialState = {
areaInfo: "",
setAreainfo: () => {},
@ -12,7 +13,14 @@ export const useAreaInfo = () => {
export const AreaInfoProvider = ({ children }) => {
const [areaInfo, setAreaInfo] = useState("");
const getAreaData = () =>
fetch(
"https://script.google.com/macros/s/AKfycbz80LcaEUrhnlEsLkJy0LG2IRO3DBVQhfNmN1d_0f_HvtsujNQpxM90SrV9yKWH_JG1Ww/exec"
)
.then((d) => d.text())
.then((d) => setAreaInfo(d));
useEffect(getAreaData, []);
useInterval(getAreaData, 60000); //60秒毎に全在線列車取得
return (
<AreaInfoContext.Provider value={{ areaInfo, setAreaInfo }}>
{children}

View File

@ -1,7 +1,13 @@
import React, { createContext, useContext, useState } from "react";
import React, { createContext, useContext, useState, useEffect } from "react";
import trainList from "../assets/originData/trainList";
import { AS } from "../storageControl";
const initialState = {
busAndTrainData: [],
setBusAndTrainData: () => {},
trainPairData: [],
setTrainPairData: () => {},
initializeTrainPairList: () => {},
getInfluencedTrainData: () => {},
};
const BusAndTrainDataContext = createContext(initialState);
@ -12,10 +18,86 @@ export const useBusAndTrainData = () => {
export const BusAndTrainDataProvider = ({ children }) => {
const [busAndTrainData, setBusAndTrainData] = useState([]);
const [trainPairData, setTrainPairData] = useState([]);
useEffect(() => {
AS.getItem("busAndTrain")
.then((d) => {
const returnData = JSON.parse(d);
setBusAndTrainData(returnData);
})
.catch(() => {
fetch(
"https://script.google.com/macros/s/AKfycbw0UW6ZeCDgUYFRP0zxpc_Oqfy-91dBdbWv-cM8n3narKp14IyCd2wy5HW7taXcW7E/exec"
)
.then((d) => d.json())
.then((d) => {
setBusAndTrainData(d);
AS.setItem("busAndTrain", JSON.stringify(d));
});
});
}, []);
useEffect(() => {
AS.getItem("trainPairData")
.then((d) => {
const returnData = JSON.parse(d);
setTrainPairData(returnData);
})
.catch(() => {
fetch(
"https://script.google.com/macros/s/AKfycbyoBH7_rBwzPmhU1ghRBNTAVuvGltIrZtWxE07gDdhGGlDL9Ip2qk3pFM5u2xtRBl8/exec"
)
.then((d) => d.json())
.then((d) => {
setTrainPairData(d);
AS.setItem("trainPairData", JSON.stringify(d));
});
});
}, []);
const initializeTrainPairList = () => {
const trainPairList = {};
trainPairData.forEach((d) => {
trainPairList[Object.keys(d)[0]] = d[Object.keys(d)[0]];
});
return trainPairList;
};
const getInfluencedTrainData = (trainNum) => {
const trainPairList = initializeTrainPairList();
const returnArray = [];
if (!trainNum) return;
if (trainPairList[trainNum]) {
returnArray.push(Object.keys(trainPairList[trainNum])[0]);
}
if (
// 列番が4xxDまたは5xxDの場合はxxDの列番を検索
new RegExp(/^4[1-9]\d\d[DM]$/).test(trainNum) ||
new RegExp(/^5[1-7]\d\d[DM]$/).test(trainNum)
) {
if (trainList[trainNum.substring(1)]) {
returnArray.push(trainNum.substring(1));
}
}
if (new RegExp(/^[1-9]\d\d[DM]$/).test(trainNum)) {
// 列番がxxDの場合は4xxDと5xxDの列番を検索
if (trainList["4" + trainNum]) returnArray.push("4" + trainNum);
if (trainList["5" + trainNum]) returnArray.push("5" + trainNum);
}
if (!returnArray[0]) return [[], []];
const TD = trainList[returnArray[0]];
if (!TD) return [[], []];
const TDArray = TD.split("#").filter((d) => d != "");
return [returnArray, TDArray];
};
return (
<BusAndTrainDataContext.Provider
value={{ busAndTrainData, setBusAndTrainData }}
value={{
busAndTrainData,
setBusAndTrainData,
trainPairData,
setTrainPairData,
initializeTrainPairList,
getInfluencedTrainData,
}}
>
{children}
</BusAndTrainDataContext.Provider>

View File

@ -0,0 +1,38 @@
import React, { createContext, useContext, useState, useEffect } from "react";
import { useWindowDimensions } from "react-native";
import * as ScreenOrientation from "expo-screen-orientation";
const initialState = { isLandscape: false, setIsLandscape: () => {} };
const DeviceOrientationChange = createContext(initialState);
export const useDeviceOrientationChange = () => {
return useContext(DeviceOrientationChange);
};
export const DeviceOrientationChangeProvider = ({ children }) => {
const [isLandscape, setIsLandscape] = useState(false);
const { height, width } = useWindowDimensions();
const data = async () => {
await ScreenOrientation.lockAsync(
ScreenOrientation.OrientationLock.PORTRAIT_UP
);
};
useEffect(() => {
data();
//ScreenOrientation.unlockAsync();
}, []);
useEffect(() => {
if (height / width > 1.5) {
setIsLandscape(false);
}
if (height / width < 1.5) {
//setIsLandscape(true);
}
}, [height, width]);
return (
<DeviceOrientationChange.Provider value={{ isLandscape, setIsLandscape }}>
{children}
</DeviceOrientationChange.Provider>
);
};

4
tsconfig.json Normal file
View File

@ -0,0 +1,4 @@
{
"compilerOptions": {},
"extends": "expo/tsconfig.base"
}

2594
yarn.lock

File diff suppressed because it is too large Load Diff