mirror of
https://github.com/SableClient/Sable.git
synced 2026-12-01 06:12:31 -08:00
fix(android): align back navigation with UI
This commit is contained in:
2 files changed
+17
-2
No files matched your search
@@ -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>
|
||||
|
||||
Reference in new issue
Block a user