From e8a2547ca4df0358efac46215fd0b4928140964b Mon Sep 17 00:00:00 2001 From: harukin-expo-dev-env Date: Fri, 5 Dec 2025 10:43:57 +0000 Subject: [PATCH] =?UTF-8?q?tsx=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Apps.js => Apps.tsx | 37 ++++- MenuPage.tsx | 2 +- .../{EachTrainInfo.js => EachTrainInfo.tsx} | 8 +- .../EachTrainInfo/EachStopList.tsx | 15 +- ...ickyContent.js => ScrollStickyContent.tsx} | 0 ...owSpecialTrain.js => ShowSpecialTrain.tsx} | 0 .../EachTrainInfo/TrainDataView.tsx | 4 +- ...TrainInfoCore.js => EachTrainInfoCore.tsx} | 149 ++++++++++-------- .../{useAutoScroll.js => useAutoScroll.ts} | 16 +- ...ndedStations.js => useExtendedStations.ts} | 0 ...{useNearbyTrains.js => useNearbyTrains.ts} | 0 ...StopStationIDs.js => useStopStationIDs.ts} | 4 +- ...roughStations.js => useThroughStations.ts} | 0 ...nDiagramData.js => useTrainDiagramData.ts} | 0 ...seTrainPosition.js => useTrainPosition.ts} | 18 ++- .../{JRSTraInfo.js => JRSTraInfo.tsx} | 0 ...ionDeteilView.js => StationDeteilView.tsx} | 0 ...eSelector.js => TrainMenuLineSelector.tsx} | 0 ...creen.jsx => HelloWidgetPreviewScreen.tsx} | 0 .../{InfoWidget.jsx => InfoWidget.tsx} | 0 ...raInfoEXWidget.jsx => TraInfoEXWidget.tsx} | 0 ...sk-handler.jsx => widget-task-handler.tsx} | 0 components/{Apps.js => Apps.tsx} | 73 ++------- components/Apps/{WebView.jsx => WebView.tsx} | 0 ...inListView.js => CurrentTrainListView.tsx} | 0 ...ollView.js => DynamicHeaderScrollView.tsx} | 62 ++++++-- ...ontentBottom.js => FixedContentBottom.tsx} | 0 components/Menu/{TitleBar.js => TitleBar.tsx} | 0 ...tingsItem.js => FavoiliteSettingsItem.tsx} | 0 ...voriteSettings.js => FavoriteSettings.tsx} | 0 ...onSettings.js => LauncherIconSettings.tsx} | 0 .../{LayoutSettings.js => LayoutSettings.tsx} | 0 ...onSettings.js => NotificationSettings.tsx} | 0 .../{SettingTopPage.js => SettingTopPage.tsx} | 0 .../{WidgetSettings.js => WidgetSettings.tsx} | 0 .../Settings/{settings.js => settings.tsx} | 0 components/TrainMenu/MapPin.tsx | 2 +- .../{SimpleSwitch.js => SimpleSwitch.tsx} | 0 .../atom/{SwitchArea.js => SwitchArea.tsx} | 0 components/atom/{TextBox.js => TextBox.tsx} | 0 .../atom/{TicketBox.js => TicketBox.tsx} | 0 ...ipleSwitchArea.js => TripleSwitchArea.tsx} | 0 components/{trainMenu.js => trainMenu.tsx} | 0 .../{trainMenu.web.js => trainMenu.web.tsx} | 0 .../{trainbaseview.js => trainbaseview.tsx} | 0 components/発車時刻表/EachData.tsx | 5 +- .../LED_Vision_Component/{Footer.js => Footer.tsx} | 0 .../{SwitchBox.js => SwitchBox.tsx} | 0 components/駅名表/{Sign.js => Sign.tsx} | 0 howto.js => howto.tsx | 26 ++- index.ts | 14 ++ ...eversalPoints.js => findReversalPoints.ts} | 0 .../{getStationData.js => getStationData.ts} | 0 ...nBackTrainInfo.js => openBackTrainInfo.ts} | 0 lib/initIcon.tsx | 12 +- 55 files changed, 257 insertions(+), 190 deletions(-) rename Apps.js => Apps.tsx (68%) rename components/ActionSheetComponents/{EachTrainInfo.js => EachTrainInfo.tsx} (71%) rename components/ActionSheetComponents/EachTrainInfo/{ScrollStickyContent.js => ScrollStickyContent.tsx} (100%) rename components/ActionSheetComponents/EachTrainInfo/{ShowSpecialTrain.js => ShowSpecialTrain.tsx} (100%) rename components/ActionSheetComponents/{EachTrainInfoCore.js => EachTrainInfoCore.tsx} (75%) rename components/ActionSheetComponents/EachTrainInfoCore/hooks/{useAutoScroll.js => useAutoScroll.ts} (67%) rename components/ActionSheetComponents/EachTrainInfoCore/hooks/{useExtendedStations.js => useExtendedStations.ts} (100%) rename components/ActionSheetComponents/EachTrainInfoCore/hooks/{useNearbyTrains.js => useNearbyTrains.ts} (100%) rename components/ActionSheetComponents/EachTrainInfoCore/hooks/{useStopStationIDs.js => useStopStationIDs.ts} (82%) rename components/ActionSheetComponents/EachTrainInfoCore/hooks/{useThroughStations.js => useThroughStations.ts} (100%) rename components/ActionSheetComponents/EachTrainInfoCore/hooks/{useTrainDiagramData.js => useTrainDiagramData.ts} (100%) rename components/ActionSheetComponents/EachTrainInfoCore/hooks/{useTrainPosition.js => useTrainPosition.ts} (85%) rename components/ActionSheetComponents/{JRSTraInfo.js => JRSTraInfo.tsx} (100%) rename components/ActionSheetComponents/{StationDeteilView.js => StationDeteilView.tsx} (100%) rename components/ActionSheetComponents/{TrainMenuLineSelector.js => TrainMenuLineSelector.tsx} (100%) rename components/AndroidWidget/{HelloWidgetPreviewScreen.jsx => HelloWidgetPreviewScreen.tsx} (100%) rename components/AndroidWidget/{InfoWidget.jsx => InfoWidget.tsx} (100%) rename components/AndroidWidget/{TraInfoEXWidget.jsx => TraInfoEXWidget.tsx} (100%) rename components/AndroidWidget/{widget-task-handler.jsx => widget-task-handler.tsx} (100%) rename components/{Apps.js => Apps.tsx} (59%) rename components/Apps/{WebView.jsx => WebView.tsx} (100%) rename components/{CurrentTrainListView.js => CurrentTrainListView.tsx} (100%) rename components/{DynamicHeaderScrollView.js => DynamicHeaderScrollView.tsx} (68%) rename components/Menu/{FixedContentBottom.js => FixedContentBottom.tsx} (100%) rename components/Menu/{TitleBar.js => TitleBar.tsx} (100%) rename components/Settings/FavoliteSettings/{FavoiliteSettingsItem.js => FavoiliteSettingsItem.tsx} (100%) rename components/Settings/{FavoriteSettings.js => FavoriteSettings.tsx} (100%) rename components/Settings/{LauncherIconSettings.js => LauncherIconSettings.tsx} (100%) rename components/Settings/{LayoutSettings.js => LayoutSettings.tsx} (100%) rename components/Settings/{NotificationSettings.js => NotificationSettings.tsx} (100%) rename components/Settings/{SettingTopPage.js => SettingTopPage.tsx} (100%) rename components/Settings/{WidgetSettings.js => WidgetSettings.tsx} (100%) rename components/Settings/{settings.js => settings.tsx} (100%) rename components/atom/{SimpleSwitch.js => SimpleSwitch.tsx} (100%) rename components/atom/{SwitchArea.js => SwitchArea.tsx} (100%) rename components/atom/{TextBox.js => TextBox.tsx} (100%) rename components/atom/{TicketBox.js => TicketBox.tsx} (100%) rename components/atom/{TripleSwitchArea.js => TripleSwitchArea.tsx} (100%) rename components/{trainMenu.js => trainMenu.tsx} (100%) rename components/{trainMenu.web.js => trainMenu.web.tsx} (100%) rename components/{trainbaseview.js => trainbaseview.tsx} (100%) rename components/発車時刻表/LED_Vision_Component/{Footer.js => Footer.tsx} (100%) rename components/発車時刻表/LED_Vision_Component/{SwitchBox.js => SwitchBox.tsx} (100%) rename components/駅名表/{Sign.js => Sign.tsx} (100%) rename howto.js => howto.tsx (58%) create mode 100644 index.ts rename lib/eachTrainInfoCoreLib/{findReversalPoints.js => findReversalPoints.ts} (100%) rename lib/eachTrainInfoCoreLib/{getStationData.js => getStationData.ts} (100%) rename lib/eachTrainInfoCoreLib/{openBackTrainInfo.js => openBackTrainInfo.ts} (100%) diff --git a/Apps.js b/Apps.tsx similarity index 68% rename from Apps.js rename to Apps.tsx index 0f1830a..59ffb9c 100644 --- a/Apps.js +++ b/Apps.tsx @@ -1,5 +1,5 @@ import React from "react"; -import { NavigationContainer } from "@react-navigation/native"; +import { NavigationContainer, NavigationContainerRef } from "@react-navigation/native"; import { createBottomTabNavigator } from "@react-navigation/bottom-tabs"; import { Platform } from "react-native"; import { useFonts } from "expo-font"; @@ -10,17 +10,40 @@ import { MenuPage } from "./MenuPage"; import { useAreaInfo } from "./stateBox/useAreaInfo"; import "./components/ActionSheetComponents/sheets"; +type RootTabParamList = { + positions: undefined; + topMenu: undefined; + information: undefined; +}; + +type TabProps = { + name: string; + label: string; + icon: string; + iconFamily: string; + tabBarBadge?: string; + isInfo?: boolean; +}; + export function AppContainer() { - const Tab = createBottomTabNavigator(); + const Tab = createBottomTabNavigator(); const { areaInfo, areaIconBadgeText, isInfo } = useAreaInfo(); - const navigationRef = React.useRef(); - const getTabProps = (name, label, icon, iconFamily, tabBarBadge, isInfo) => ({ + const navigationRef = React.useRef>(null); + + const getTabProps = ( + name: keyof RootTabParamList, + label: string, + icon: string, + iconFamily: "Ionicons" | "AntDesign", + tabBarBadge?: string, + isInfo?: boolean + ) => ({ name, options: { tabBarLabel: label, headerShown: false, gestureEnabled: true, - tabBarIcon: initIcon(icon, iconFamily,tabBarBadge,isInfo), + tabBarIcon: initIcon(icon as any, iconFamily, tabBarBadge, isInfo), }, }); @@ -32,15 +55,13 @@ export function AppContainer() { }); return ( + {/* @ts-expect-error - Tab.Navigator type definition issue */} (); const { addListener } = navigation; useEffect(() => { AS.getItem(STORAGE_KEYS.START_PAGE) diff --git a/components/ActionSheetComponents/EachTrainInfo.js b/components/ActionSheetComponents/EachTrainInfo.tsx similarity index 71% rename from components/ActionSheetComponents/EachTrainInfo.js rename to components/ActionSheetComponents/EachTrainInfo.tsx index bcf35e3..7dd98b1 100644 --- a/components/ActionSheetComponents/EachTrainInfo.js +++ b/components/ActionSheetComponents/EachTrainInfo.tsx @@ -1,21 +1,19 @@ import React, { useRef } from "react"; import { Platform } from "react-native"; -import ActionSheet from "react-native-actions-sheet"; +import ActionSheet, { useScrollHandlers } from "react-native-actions-sheet"; import { EachTrainInfoCore } from "./EachTrainInfoCore"; export const EachTrainInfo = ({ payload }) => { if (!payload) return <>; - const actionSheetRef = useRef(null); + const scrollHandlers = useScrollHandlers(); return ( } - ref={actionSheetRef} drawUnderStatusBar={false} isModal={Platform.OS == "ios"} - //useBottomSafeAreaPadding={Platform.OS == "android"} > - + ); }; diff --git a/components/ActionSheetComponents/EachTrainInfo/EachStopList.tsx b/components/ActionSheetComponents/EachTrainInfo/EachStopList.tsx index f73cd98..4f823cf 100644 --- a/components/ActionSheetComponents/EachTrainInfo/EachStopList.tsx +++ b/components/ActionSheetComponents/EachTrainInfo/EachStopList.tsx @@ -33,10 +33,12 @@ type currentTrainDataType = { Type: string; Line: string; }; +type StationInfo = { StationName: string; StationNumber: string | null }; + type props = { i: string; index: number; - stationList: { StationName: string; StationNumber: string }[][]; + stationList: StationInfo[][]; points: boolean; currentTrainData?: currentTrainDataType; openStationACFromEachTrainInfo?: (station: string) => void; @@ -84,18 +86,17 @@ export const EachStopList: FC = ({ .reduce((newArray, e) => newArray.concat(e), []); /*Array [ Object { - "StationName": "佐古", + "Station_JP": "佐古", "StationNumber": "T01", }, Object { - "StationName": "佐古", + "Station_JP": "佐古", "StationNumber": "B01", }, ] */ - const StationNumbers = - Stations && - Stations.filter((d) => d.StationNumber).map((d) => d.StationNumber); - + const StationNumbers = Stations + .filter((d) => d.StationNumber != null) + .map((d) => d.StationNumber as string); // SE文字列を表示用に変換 const [seString, seType] = parseSeString(se); diff --git a/components/ActionSheetComponents/EachTrainInfo/ScrollStickyContent.js b/components/ActionSheetComponents/EachTrainInfo/ScrollStickyContent.tsx similarity index 100% rename from components/ActionSheetComponents/EachTrainInfo/ScrollStickyContent.js rename to components/ActionSheetComponents/EachTrainInfo/ScrollStickyContent.tsx diff --git a/components/ActionSheetComponents/EachTrainInfo/ShowSpecialTrain.js b/components/ActionSheetComponents/EachTrainInfo/ShowSpecialTrain.tsx similarity index 100% rename from components/ActionSheetComponents/EachTrainInfo/ShowSpecialTrain.js rename to components/ActionSheetComponents/EachTrainInfo/ShowSpecialTrain.tsx diff --git a/components/ActionSheetComponents/EachTrainInfo/TrainDataView.tsx b/components/ActionSheetComponents/EachTrainInfo/TrainDataView.tsx index e084a24..ccdef3c 100644 --- a/components/ActionSheetComponents/EachTrainInfo/TrainDataView.tsx +++ b/components/ActionSheetComponents/EachTrainInfo/TrainDataView.tsx @@ -194,9 +194,9 @@ export const TrainDataView:FC = ({ diff --git a/components/ActionSheetComponents/EachTrainInfoCore.js b/components/ActionSheetComponents/EachTrainInfoCore.tsx similarity index 75% rename from components/ActionSheetComponents/EachTrainInfoCore.js rename to components/ActionSheetComponents/EachTrainInfoCore.tsx index fa3292b..0f1f7e2 100644 --- a/components/ActionSheetComponents/EachTrainInfoCore.js +++ b/components/ActionSheetComponents/EachTrainInfoCore.tsx @@ -8,8 +8,7 @@ import { BackHandler, Linking, } from "react-native"; -import { SheetManager } from "react-native-actions-sheet"; -import { useScrollHandlers } from "react-native-actions-sheet"; +import { SheetManager, useScrollHandlers } from "react-native-actions-sheet"; import { getTrainType } from "../../lib/getTrainType"; import { customTrainDataDetector } from "../custom-train-data"; import { useDeviceOrientationChange } from "../../stateBox/useDeviceOrientationChange"; @@ -35,32 +34,31 @@ import { useAutoScroll } from "./EachTrainInfoCore/hooks/useAutoScroll"; import { useExtendedStations } from "./EachTrainInfoCore/hooks/useExtendedStations"; export const EachTrainInfoCore = ({ - actionSheetRef, data, openStationACFromEachTrainInfo, from, navigate, + scrollHandlers, }) => { const { stationList } = useStationList(); const { allCustomTrainData } = useAllTrainDiagram(); const { setTrainInfo } = useTrainMenu(); const { height } = useWindowDimensions(); const { isLandscape } = useDeviceOrientationChange(); - - const scrollHandlers = actionSheetRef - ? useScrollHandlers("scrollview-1", actionSheetRef) - : null; // Custom hooks for data management - const { trainData, setTrainData, trueTrainID } = useTrainDiagramData(data.trainNum); - const { trainDataWithThrough, haveThrough } = useThroughStations(trainData); - const { headStation, tailStation, nearTrainIDList } = useNearbyTrains(data.trainNum, trainData); - const stopStationIDList = useStopStationIDs(trainDataWithThrough); - const { currentTrainData, currentPosition, points, pointsDisplay } = useTrainPosition( - data.trainNum, - stopStationIDList + const { trainData, setTrainData, trueTrainID } = useTrainDiagramData( + data.trainNum ); - + const { trainDataWithThrough, haveThrough } = useThroughStations(trainData); + const { headStation, tailStation, nearTrainIDList } = useNearbyTrains( + data.trainNum, + trainData + ); + const stopStationIDList = useStopStationIDs(trainDataWithThrough); + const { currentTrainData, currentPosition, points, pointsDisplay } = + useTrainPosition(data.trainNum, stopStationIDList); + const { showHeadStation, showTailStation, @@ -73,7 +71,14 @@ export const EachTrainInfoCore = ({ const [isJumped, setIsJumped] = useState(false); // Auto scroll to current position - useAutoScroll(points, trainDataWithThrough, scrollHandlers, isJumped, setIsJumped, setShowThrew); + useAutoScroll( + points, + trainDataWithThrough, + scrollHandlers, + isJumped, + setIsJumped, + setShowThrew + ); // Back button handler useEffect(() => { @@ -81,7 +86,10 @@ export const EachTrainInfoCore = ({ SheetManager.hide("EachTrainInfo"); return true; }; - const backHandler = BackHandler.addEventListener("hardwareBackPress", backAction); + const backHandler = BackHandler.addEventListener( + "hardwareBackPress", + backAction + ); return () => backHandler.remove(); }, []); @@ -91,13 +99,13 @@ export const EachTrainInfoCore = ({ const openTrainInfo = (trainNum) => { const train = customTrainDataDetector(trainNum, allCustomTrainData); - + let trainNumber = ""; - if (train.train_num_distance && !isNaN(train.train_num_distance)) { + if (train.train_num_distance && !isNaN(Number(train.train_num_distance))) { const numericPart = parseInt(trainNum.replace("M", "").replace("D", "")); - trainNumber = `${numericPart - train.train_num_distance}号`; + trainNumber = `${numericPart - Number(train.train_num_distance)}号`; } - + const limitedData = getTrainType({ type: train.type }); const payload = { data: { @@ -107,12 +115,15 @@ export const EachTrainInfoCore = ({ navigate, from: from === "LED" ? "LED2" : "NearTrainDiagramView", }; - + if (isLandscape) { setTrainInfo(payload.data); } else { SheetManager.hide("EachTrainInfo").then(() => { - setTimeout(() => SheetManager.show("EachTrainInfo", { payload }), 200); + setTimeout(() => { + // @ts-expect-error - SheetManager payload type is too restrictive + SheetManager.show("EachTrainInfo", { payload }); + }, 200); }); } }; @@ -121,25 +132,24 @@ export const EachTrainInfoCore = ({ - {isLandscape || ( - - - - )} + + + )} {headStation.length > 0 && - headStation.map((item, index) => - !showHeadStation.includes(index) && ( - extendToHeadStation(item.station, item.dia, index)} - style={styles.extendStationButton} - key={`${item.station}-head${index}`} - > - - 「本当の始発駅」を表示 - - - ) + headStation.map( + (item, index) => + !showHeadStation.includes(index) && ( + + extendToHeadStation(item.station, item.dia, index) + } + style={styles.extendStationButton} + key={`${item.station}-head${index}`} + > + + 「本当の始発駅」を表示 + + + ) )} - - Twitterで検索 - + Twitterで検索 )} {trainDataWithThrough.map((item, index, array) => @@ -234,9 +246,9 @@ export const EachTrainInfoCore = ({ {tailStation.length > 0 && - tailStation.map(({ station, dia }, index) => - !showTailStation.includes(index) && ( - extendToTailStation(station, dia, index)} - style={styles.extendStationButton} - key={`${station}-tail${index}`} - > - - 「本当の終着駅」を表示 - - - ) + tailStation.map( + ({ station, dia }, index) => + !showTailStation.includes(index) && ( + extendToTailStation(station, dia, index)} + style={styles.extendStationButton} + key={`${station}-tail${index}`} + > + + 「本当の終着駅」を表示 + + + ) )} diff --git a/components/ActionSheetComponents/EachTrainInfoCore/hooks/useAutoScroll.js b/components/ActionSheetComponents/EachTrainInfoCore/hooks/useAutoScroll.ts similarity index 67% rename from components/ActionSheetComponents/EachTrainInfoCore/hooks/useAutoScroll.js rename to components/ActionSheetComponents/EachTrainInfoCore/hooks/useAutoScroll.ts index 3f27d3c..75533e0 100644 --- a/components/ActionSheetComponents/EachTrainInfoCore/hooks/useAutoScroll.js +++ b/components/ActionSheetComponents/EachTrainInfoCore/hooks/useAutoScroll.ts @@ -1,9 +1,17 @@ -import { useEffect } from 'react'; -import { LayoutAnimation } from 'react-native'; +import React,{ useEffect, MutableRefObject } from 'react'; +import { LayoutAnimation, ScrollView } from 'react-native'; -export const useAutoScroll = (points, trainDataWithThrough, scrollHandlers, isJumped, setIsJumped, setShowThrew) => { + +export const useAutoScroll = ( + points: boolean[] | undefined, + trainDataWithThrough: string[], + scrollHandlers: any, + isJumped: boolean, + setIsJumped: (value: boolean) => void, + setShowThrew: (value: boolean) => void +) => { useEffect(() => { - if (isJumped || !points?.length) return; + if (isJumped || !points?.length || !scrollHandlers) return; const currentPositionIndex = points.findIndex((d) => d === true); if (currentPositionIndex === -1) return; diff --git a/components/ActionSheetComponents/EachTrainInfoCore/hooks/useExtendedStations.js b/components/ActionSheetComponents/EachTrainInfoCore/hooks/useExtendedStations.ts similarity index 100% rename from components/ActionSheetComponents/EachTrainInfoCore/hooks/useExtendedStations.js rename to components/ActionSheetComponents/EachTrainInfoCore/hooks/useExtendedStations.ts diff --git a/components/ActionSheetComponents/EachTrainInfoCore/hooks/useNearbyTrains.js b/components/ActionSheetComponents/EachTrainInfoCore/hooks/useNearbyTrains.ts similarity index 100% rename from components/ActionSheetComponents/EachTrainInfoCore/hooks/useNearbyTrains.js rename to components/ActionSheetComponents/EachTrainInfoCore/hooks/useNearbyTrains.ts diff --git a/components/ActionSheetComponents/EachTrainInfoCore/hooks/useStopStationIDs.js b/components/ActionSheetComponents/EachTrainInfoCore/hooks/useStopStationIDs.ts similarity index 82% rename from components/ActionSheetComponents/EachTrainInfoCore/hooks/useStopStationIDs.js rename to components/ActionSheetComponents/EachTrainInfoCore/hooks/useStopStationIDs.ts index 5e9ce98..30b4647 100644 --- a/components/ActionSheetComponents/EachTrainInfoCore/hooks/useStopStationIDs.js +++ b/components/ActionSheetComponents/EachTrainInfoCore/hooks/useStopStationIDs.ts @@ -1,9 +1,9 @@ import { useState, useEffect } from 'react'; import { useStationList } from '@/stateBox/useStationList'; -export const useStopStationIDs = (trainDataWithThrough) => { +export const useStopStationIDs = (trainDataWithThrough: string[]) => { const { stationList } = useStationList(); - const [stopStationIDList, setStopStationIDList] = useState([]); + const [stopStationIDList, setStopStationIDList] = useState([]); useEffect(() => { const stationIDs = trainDataWithThrough.map((item) => { diff --git a/components/ActionSheetComponents/EachTrainInfoCore/hooks/useThroughStations.js b/components/ActionSheetComponents/EachTrainInfoCore/hooks/useThroughStations.ts similarity index 100% rename from components/ActionSheetComponents/EachTrainInfoCore/hooks/useThroughStations.js rename to components/ActionSheetComponents/EachTrainInfoCore/hooks/useThroughStations.ts diff --git a/components/ActionSheetComponents/EachTrainInfoCore/hooks/useTrainDiagramData.js b/components/ActionSheetComponents/EachTrainInfoCore/hooks/useTrainDiagramData.ts similarity index 100% rename from components/ActionSheetComponents/EachTrainInfoCore/hooks/useTrainDiagramData.js rename to components/ActionSheetComponents/EachTrainInfoCore/hooks/useTrainDiagramData.ts diff --git a/components/ActionSheetComponents/EachTrainInfoCore/hooks/useTrainPosition.js b/components/ActionSheetComponents/EachTrainInfoCore/hooks/useTrainPosition.ts similarity index 85% rename from components/ActionSheetComponents/EachTrainInfoCore/hooks/useTrainPosition.js rename to components/ActionSheetComponents/EachTrainInfoCore/hooks/useTrainPosition.ts index 0479c32..4ce5f7b 100644 --- a/components/ActionSheetComponents/EachTrainInfoCore/hooks/useTrainPosition.js +++ b/components/ActionSheetComponents/EachTrainInfoCore/hooks/useTrainPosition.ts @@ -5,11 +5,21 @@ import { logger } from '@/utils/logger'; import { useCurrentTrain } from '@/stateBox/useCurrentTrain'; import { findReversalPoints } from '@/lib/eachTrainInfoCoreLib/findReversalPoints'; -export const useTrainPosition = (trainNum, stopStationIDList) => { +type TrainData = { + trainNum: string; + position?: string[]; + delay?: number | "入線"; + [key: string]: unknown; +}; + +export const useTrainPosition = ( + trainNum: string, + stopStationIDList: string[][] +) => { const { currentTrain, getCurrentStationData, getPosition } = useCurrentTrain(); - const [currentTrainData, setCurrentTrainData] = useState(); - const [currentPosition, setCurrentPosition] = useState([]); - const [trainPositionSwitch, setTrainPositionSwitch] = useState('false'); + const [currentTrainData, setCurrentTrainData] = useState(); + const [currentPosition, setCurrentPosition] = useState([]); + const [trainPositionSwitch, setTrainPositionSwitch] = useState('false'); useEffect(() => { const trainPosData = getCurrentStationData(trainNum); diff --git a/components/ActionSheetComponents/JRSTraInfo.js b/components/ActionSheetComponents/JRSTraInfo.tsx similarity index 100% rename from components/ActionSheetComponents/JRSTraInfo.js rename to components/ActionSheetComponents/JRSTraInfo.tsx diff --git a/components/ActionSheetComponents/StationDeteilView.js b/components/ActionSheetComponents/StationDeteilView.tsx similarity index 100% rename from components/ActionSheetComponents/StationDeteilView.js rename to components/ActionSheetComponents/StationDeteilView.tsx diff --git a/components/ActionSheetComponents/TrainMenuLineSelector.js b/components/ActionSheetComponents/TrainMenuLineSelector.tsx similarity index 100% rename from components/ActionSheetComponents/TrainMenuLineSelector.js rename to components/ActionSheetComponents/TrainMenuLineSelector.tsx diff --git a/components/AndroidWidget/HelloWidgetPreviewScreen.jsx b/components/AndroidWidget/HelloWidgetPreviewScreen.tsx similarity index 100% rename from components/AndroidWidget/HelloWidgetPreviewScreen.jsx rename to components/AndroidWidget/HelloWidgetPreviewScreen.tsx diff --git a/components/AndroidWidget/InfoWidget.jsx b/components/AndroidWidget/InfoWidget.tsx similarity index 100% rename from components/AndroidWidget/InfoWidget.jsx rename to components/AndroidWidget/InfoWidget.tsx diff --git a/components/AndroidWidget/TraInfoEXWidget.jsx b/components/AndroidWidget/TraInfoEXWidget.tsx similarity index 100% rename from components/AndroidWidget/TraInfoEXWidget.jsx rename to components/AndroidWidget/TraInfoEXWidget.tsx diff --git a/components/AndroidWidget/widget-task-handler.jsx b/components/AndroidWidget/widget-task-handler.tsx similarity index 100% rename from components/AndroidWidget/widget-task-handler.jsx rename to components/AndroidWidget/widget-task-handler.tsx diff --git a/components/Apps.js b/components/Apps.tsx similarity index 59% rename from components/Apps.js rename to components/Apps.tsx index f49720d..ea6a459 100644 --- a/components/Apps.js +++ b/components/Apps.tsx @@ -1,11 +1,5 @@ import React from "react"; -import { - View, - Platform, - useWindowDimensions, - LayoutAnimation, - Text, -} from "react-native"; +import { View, Platform, useWindowDimensions } from "react-native"; import Constants from "expo-constants"; import * as Updates from "expo-updates"; @@ -13,16 +7,12 @@ import { lineList } from "../lib/getStationList"; 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 { useNavigation } from "@react-navigation/native"; import { useTrainMenu } from "../stateBox/useTrainMenu"; import { AppsWebView } from "./Apps/WebView"; import { NewMenu } from "./Apps/NewMenu"; -import { MapsButton } from "./Apps/MapsButton"; import { ReloadButton } from "./Apps/ReloadButton"; -import { LandscapeBackButton } from "./Apps/LandscapeBackButton"; import { useStationList } from "../stateBox/useStationList"; import { FixedPositionBox } from "./Apps/FixedPositionBox"; /* @@ -58,10 +48,16 @@ export default function Apps() { currentStation: returnDataBase, navigate, goTo: "Apps", - useShow: () => SheetManager.show("StationDetailView", { payload }), + useShow: () => { + // @ts-expect-error - SheetManager payload type is too restrictive + SheetManager.show("StationDetailView", { payload }); + }, onExit: () => SheetManager.hide("StationDetailView"), }; - setTimeout(() => SheetManager.show("StationDetailView", { payload }), 50); + setTimeout(() => { + // @ts-expect-error - SheetManager payload type is too restrictive + SheetManager.show("StationDetailView", { payload }); + }, 50); } else { SheetManager.hide("StationDetailView"); } @@ -75,61 +71,14 @@ export default function Apps() { }} onLayout={handleLayout} > - {!trainInfo.trainNum && isLandscape ? ( - - ) : null} {/* {Status} */} - {isLandscape && trainInfo.trainNum && ( - - - - )} - {isLandscape || ( - { - navigate("trainMenu", { webview }); - }} - /> - )} - {isLandscape && trainInfo.trainNum && ( - { - LayoutAnimation.easeInEaseOut(); - setTrainInfo({ - trainNum: undefined, - limited: undefined, - trainData: undefined, - }); - }} - /> - )} - {fixedPosition.type && ( - - )} + + {fixedPosition.type && } {mapSwitch == "true" ? ( { +type HeaderSize = "small" | "big" | "default"; + +type DynamicHeaderScrollViewProps = { + children: ReactNode; + containerProps?: Record; + shortHeader?: ReactNode; + longHeader?: ReactNode; + topStickyContent?: ReactNode; + styles?: { header: ViewStyle }; + from?: string; + scrollHandlers?: any; +}; + +export const DynamicHeaderScrollView: React.FC = (props) => { const { children, containerProps = {}, @@ -88,7 +101,7 @@ export const DynamicHeaderScrollView = (props) => { opacity: 0, }, }; - const StickyStyle = { + const StickyStyle: Record = { on: { position: "absolute", width: "100%", @@ -106,9 +119,10 @@ export const DynamicHeaderScrollView = (props) => { }; const [headerVisible, setHeaderVisible] = useState(false); + const fallbackScrollRef = useRef(null); const onScroll = (event) => { - scrollHandlers.onScroll(event); + scrollHandlers?.onScroll(event); switch (headerSize) { case "big": setHeaderVisible(false); @@ -152,14 +166,37 @@ export const DynamicHeaderScrollView = (props) => { {topStickyContent} - + {Platform.OS === 'ios' ? ( + + + + {topStickyContent && ( + + )} + {children} + + + ) : ( { paddingTop: Min_Header_Height + 40, flexDirection: "column", }} - index={1} /> )} {children} - + )} ); }; diff --git a/components/Menu/FixedContentBottom.js b/components/Menu/FixedContentBottom.tsx similarity index 100% rename from components/Menu/FixedContentBottom.js rename to components/Menu/FixedContentBottom.tsx diff --git a/components/Menu/TitleBar.js b/components/Menu/TitleBar.tsx similarity index 100% rename from components/Menu/TitleBar.js rename to components/Menu/TitleBar.tsx diff --git a/components/Settings/FavoliteSettings/FavoiliteSettingsItem.js b/components/Settings/FavoliteSettings/FavoiliteSettingsItem.tsx similarity index 100% rename from components/Settings/FavoliteSettings/FavoiliteSettingsItem.js rename to components/Settings/FavoliteSettings/FavoiliteSettingsItem.tsx diff --git a/components/Settings/FavoriteSettings.js b/components/Settings/FavoriteSettings.tsx similarity index 100% rename from components/Settings/FavoriteSettings.js rename to components/Settings/FavoriteSettings.tsx diff --git a/components/Settings/LauncherIconSettings.js b/components/Settings/LauncherIconSettings.tsx similarity index 100% rename from components/Settings/LauncherIconSettings.js rename to components/Settings/LauncherIconSettings.tsx diff --git a/components/Settings/LayoutSettings.js b/components/Settings/LayoutSettings.tsx similarity index 100% rename from components/Settings/LayoutSettings.js rename to components/Settings/LayoutSettings.tsx diff --git a/components/Settings/NotificationSettings.js b/components/Settings/NotificationSettings.tsx similarity index 100% rename from components/Settings/NotificationSettings.js rename to components/Settings/NotificationSettings.tsx diff --git a/components/Settings/SettingTopPage.js b/components/Settings/SettingTopPage.tsx similarity index 100% rename from components/Settings/SettingTopPage.js rename to components/Settings/SettingTopPage.tsx diff --git a/components/Settings/WidgetSettings.js b/components/Settings/WidgetSettings.tsx similarity index 100% rename from components/Settings/WidgetSettings.js rename to components/Settings/WidgetSettings.tsx diff --git a/components/Settings/settings.js b/components/Settings/settings.tsx similarity index 100% rename from components/Settings/settings.js rename to components/Settings/settings.tsx diff --git a/components/TrainMenu/MapPin.tsx b/components/TrainMenu/MapPin.tsx index 59f91af..94e554d 100644 --- a/components/TrainMenu/MapPin.tsx +++ b/components/TrainMenu/MapPin.tsx @@ -8,7 +8,7 @@ type Props = { index: number; indexBase: number; latlng: string[]; - D: StationProps[][]; + D: StationProps; d: string; navigate: (screen: string) => void; webview: React.RefObject; diff --git a/components/atom/SimpleSwitch.js b/components/atom/SimpleSwitch.tsx similarity index 100% rename from components/atom/SimpleSwitch.js rename to components/atom/SimpleSwitch.tsx diff --git a/components/atom/SwitchArea.js b/components/atom/SwitchArea.tsx similarity index 100% rename from components/atom/SwitchArea.js rename to components/atom/SwitchArea.tsx diff --git a/components/atom/TextBox.js b/components/atom/TextBox.tsx similarity index 100% rename from components/atom/TextBox.js rename to components/atom/TextBox.tsx diff --git a/components/atom/TicketBox.js b/components/atom/TicketBox.tsx similarity index 100% rename from components/atom/TicketBox.js rename to components/atom/TicketBox.tsx diff --git a/components/atom/TripleSwitchArea.js b/components/atom/TripleSwitchArea.tsx similarity index 100% rename from components/atom/TripleSwitchArea.js rename to components/atom/TripleSwitchArea.tsx diff --git a/components/trainMenu.js b/components/trainMenu.tsx similarity index 100% rename from components/trainMenu.js rename to components/trainMenu.tsx diff --git a/components/trainMenu.web.js b/components/trainMenu.web.tsx similarity index 100% rename from components/trainMenu.web.js rename to components/trainMenu.web.tsx diff --git a/components/trainbaseview.js b/components/trainbaseview.tsx similarity index 100% rename from components/trainbaseview.js rename to components/trainbaseview.tsx diff --git a/components/発車時刻表/EachData.tsx b/components/発車時刻表/EachData.tsx index d703fed..ebfc5b0 100644 --- a/components/発車時刻表/EachData.tsx +++ b/components/発車時刻表/EachData.tsx @@ -69,9 +69,8 @@ export const EachData: FC = (props) => { openStationACFromEachTrainInfo, from: "LED", }; - SheetManager.show("EachTrainInfo", { - payload, - }); + // @ts-expect-error - SheetManager payload type is too restrictive + SheetManager.show("EachTrainInfo", { payload }); }; const [train, setTrain] = useState( diff --git a/components/発車時刻表/LED_Vision_Component/Footer.js b/components/発車時刻表/LED_Vision_Component/Footer.tsx similarity index 100% rename from components/発車時刻表/LED_Vision_Component/Footer.js rename to components/発車時刻表/LED_Vision_Component/Footer.tsx diff --git a/components/発車時刻表/LED_Vision_Component/SwitchBox.js b/components/発車時刻表/LED_Vision_Component/SwitchBox.tsx similarity index 100% rename from components/発車時刻表/LED_Vision_Component/SwitchBox.js rename to components/発車時刻表/LED_Vision_Component/SwitchBox.tsx diff --git a/components/駅名表/Sign.js b/components/駅名表/Sign.tsx similarity index 100% rename from components/駅名表/Sign.js rename to components/駅名表/Sign.tsx diff --git a/howto.js b/howto.tsx similarity index 58% rename from howto.js rename to howto.tsx index ec21ff8..fb8124a 100644 --- a/howto.js +++ b/howto.tsx @@ -1,9 +1,21 @@ import React from "react"; -import { View } from "react-native"; +import { View, StyleSheet } from "react-native"; import { WebView } from "react-native-webview"; import { BigButton } from "./components/atom/BigButton"; import { useNavigation } from "@react-navigation/native"; -export default ({ navigation: { navigate }, route }) => { + +type RouteParams = { + info: string; + goTo?: string; + useShow?: () => void; +}; + +type Props = { + navigation: { navigate: (screen: string) => void }; + route: { params?: RouteParams }; +}; + +export default ({ navigation: { navigate }, route }: Props) => { if (!route.params) { return null } @@ -17,7 +29,7 @@ export default ({ navigation: { navigate }, route }) => { goBack(); }; return ( - + { ); }; -const styles = { height: "100%", backgroundColor: "#0099CC" }; + +const styles = StyleSheet.create({ + container: { + height: "100%" as const, + backgroundColor: "#0099CC", + }, +}); diff --git a/index.ts b/index.ts new file mode 100644 index 0000000..dc98efe --- /dev/null +++ b/index.ts @@ -0,0 +1,14 @@ +import { registerRootComponent } from "expo"; +import { registerWidgetTaskHandler } from "react-native-android-widget"; +import { Platform } from "react-native"; + +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); +if (Platform.OS === "android") { + registerWidgetTaskHandler(widgetTaskHandler); +} diff --git a/lib/eachTrainInfoCoreLib/findReversalPoints.js b/lib/eachTrainInfoCoreLib/findReversalPoints.ts similarity index 100% rename from lib/eachTrainInfoCoreLib/findReversalPoints.js rename to lib/eachTrainInfoCoreLib/findReversalPoints.ts diff --git a/lib/eachTrainInfoCoreLib/getStationData.js b/lib/eachTrainInfoCoreLib/getStationData.ts similarity index 100% rename from lib/eachTrainInfoCoreLib/getStationData.js rename to lib/eachTrainInfoCoreLib/getStationData.ts diff --git a/lib/eachTrainInfoCoreLib/openBackTrainInfo.js b/lib/eachTrainInfoCoreLib/openBackTrainInfo.ts similarity index 100% rename from lib/eachTrainInfoCoreLib/openBackTrainInfo.js rename to lib/eachTrainInfoCoreLib/openBackTrainInfo.ts diff --git a/lib/initIcon.tsx b/lib/initIcon.tsx index 3dc8a82..dabc436 100644 --- a/lib/initIcon.tsx +++ b/lib/initIcon.tsx @@ -1,13 +1,13 @@ import React, { FC } from "react"; import { Ionicons, AntDesign } from "@expo/vector-icons"; import { Text, View } from "react-native"; -type name = keyof typeof Ionicons.glyphMap & keyof typeof AntDesign.glyphMap; -type type = "Ionicons" | "AntDesign"; +type IconName = string; +type IconType = "Ionicons" | "AntDesign"; export const initIcon = ( - name: name, - type: type, - tabBarBadge: string, - isInfo: boolean + name: IconName, + type: IconType, + tabBarBadge?: string, + isInfo?: boolean ) => { const IconComponent = type == "Ionicons" ? Ionicons : AntDesign; return ({ focused, color, size }) => (