Skip to content

Commit 172e839

Browse files
authored
環状路線でオートモードを使うと逆向きに進むバグを修正 (#5376)
* 環状路線でオートモードを使うと逆向きに進むバグを修正 * コードチェック修正
1 parent 9bca01a commit 172e839

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/hooks/useSimulationMode.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ jest.mock('~/store/atoms/location', () => ({
4646
locationAtom: { toString: () => 'locationAtom' },
4747
}));
4848

49+
jest.mock('~/hooks/useLoopLine', () => ({
50+
useLoopLine: jest.fn(() => ({
51+
isLoopLine: false,
52+
})),
53+
}));
54+
4955
jest.mock('expo-location', () => ({
5056
hasStartedLocationUpdatesAsync: jest.fn(),
5157
stopLocationUpdatesAsync: jest.fn(),

src/hooks/useSimulationMode.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import getIsPass from '../utils/isPass';
2525
import { isBusLine } from '../utils/line';
2626
import { useCurrentLine } from './useCurrentLine';
2727
import { useCurrentTrainType } from './useCurrentTrainType';
28+
import { useLoopLine } from './useLoopLine';
2829

2930
export const useSimulationMode = (): void => {
3031
const {
@@ -39,6 +40,7 @@ export const useSimulationMode = (): void => {
3940

4041
const currentLine = useCurrentLine();
4142
const trainType = useCurrentTrainType();
43+
const { isLoopLine } = useLoopLine();
4244

4345
const segmentIndexRef = useRef(0);
4446
const childIndexRef = useRef(0);
@@ -80,8 +82,15 @@ export const useSimulationMode = (): void => {
8082

8183
const maybeRevsersedStations = useMemo(
8284
() =>
83-
selectedDirection === 'INBOUND' ? stations : stations.slice().reverse(),
84-
[stations, selectedDirection]
85+
// ループ線では INBOUND/OUTBOUND の進行方向が非ループ線と逆になる
86+
(
87+
isLoopLine
88+
? selectedDirection !== 'INBOUND'
89+
: selectedDirection === 'INBOUND'
90+
)
91+
? stations
92+
: stations.slice().reverse(),
93+
[stations, selectedDirection, isLoopLine]
8594
);
8695

8796
const enabled = useMemo(() => {

0 commit comments

Comments
 (0)