From 26b55f7fb4f04ca98943e8ae6ceb277ff047b345 Mon Sep 17 00:00:00 2001 From: Erwan Leboucher Date: Sat, 1 Aug 2026 14:27:06 +0200 Subject: [PATCH] fix(android): align back navigation with UI --- src/app/components/BackRouteHandler.tsx | 14 ++++++++++++-- src/app/components/page/SettingsSectionPage.tsx | 5 +++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/app/components/BackRouteHandler.tsx b/src/app/components/BackRouteHandler.tsx index 65ff218c5..cf727bfdb 100644 --- a/src/app/components/BackRouteHandler.tsx +++ b/src/app/components/BackRouteHandler.tsx @@ -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); } diff --git a/src/app/components/page/SettingsSectionPage.tsx b/src/app/components/page/SettingsSectionPage.tsx index 84c46860f..e023bf6ee 100644 --- a/src/app/components/page/SettingsSectionPage.tsx +++ b/src/app/components/page/SettingsSectionPage.tsx @@ -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 (