fix(android): align back navigation with UI

This commit is contained in:
Erwan Leboucher committed 2026-08-01 14:27:06 +02:00
1 parent fd5c07b641
commit 26b55f7fb4
2 files changed
+17 -2

No files matched your search

+12 -2
View File
@@ -6,16 +6,18 @@ import { resolveSection } from '$pages/pathUtils';
import { HOME_ROOM_PATH, DIRECT_ROOM_PATH, SPACE_ROOM_PATH } from '$pages/paths';
import { lastVisitedRoomAtom } from '$state/room/lastRoom';
import { isRoomAlias, isRoomId } from '$utils/matrix';
import { useAndroidBackHandler } from '$utils/androidBack';
type BackRouteHandlerProps = {
children: (onBack: () => void) => ReactNode;
};
export function BackRouteHandler({ children }: BackRouteHandlerProps) {
export function useBackRoute(): () => void {
const navigate = useNavigate();
const location = useLocation();
const setLastRoom = useSetAtom(lastVisitedRoomAtom);
const goBack = useCallback(() => {
return useCallback(() => {
const section = resolveSection(location.pathname);
if (!section) return;
@@ -32,6 +34,14 @@ export function BackRouteHandler({ children }: BackRouteHandlerProps) {
navigate(section.listPath);
}, [navigate, location, setLastRoom]);
}
export function BackRouteHandler({ children }: BackRouteHandlerProps) {
const goBack = useBackRoute();
useAndroidBackHandler(() => {
goBack();
return true;
});
return children(goBack);
}
@@ -2,6 +2,7 @@ import type { ReactNode } from 'react';
import { Box, IconButton, Text } from 'folds';
import { ScreenSize, useScreenSizeContext } from '$hooks/useScreenSize';
import { ArrowLeft, composerIcon, X } from '$components/icons/phosphor';
import { useAndroidBackHandler } from '$utils/androidBack';
import { Page, PageHeader } from './Page';
import { SettingsSectionBody, SettingsSectionHeader } from './style.css';
@@ -27,6 +28,10 @@ export function SettingsSectionPage({
const screenSize = useScreenSizeContext();
const closeLabel = actionLabel ?? 'Close';
const showBack = screenSize === ScreenSize.Mobile && requestBack;
useAndroidBackHandler(() => {
requestBack?.();
return true;
}, !!showBack);
return (
<Page>