Files
wehub-resource-sync 2114b14ee0
Sync main into demo / sync (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:35:26 +08:00

34 lines
1.1 KiB
TypeScript

import React, { useCallback, useEffect, useRef } from 'react';
import { useNavigate, useLocation, UNSAFE_NavigationContext } from 'react-router-dom';
import { useAppNavigationHandler } from '../../../os/hooks/useAppNavigationHandler';
export const CompassNavigationHandler: React.FC = () => {
const location = useLocation();
const navigate = useNavigate();
const { navigator } = React.useContext(UNSAFE_NavigationContext);
const historyIndexRef = useRef(0);
useEffect(() => {
const memoryNavigator = navigator as any;
if (typeof memoryNavigator?.index === 'number') {
historyIndexRef.current = memoryNavigator.index;
}
}, [location, navigator]);
const handleBackPress = useCallback((): boolean => {
const memoryNavigator = navigator as any;
const currentIndex =
typeof memoryNavigator?.index === 'number' ? memoryNavigator.index : historyIndexRef.current;
if (currentIndex > 0) {
navigate(-1);
return true;
}
return false;
}, [navigate, navigator]);
useAppNavigationHandler('compass', { onBack: handleBackPress });
return null;
};