Skip to content

Commit 69edc72

Browse files
fix(mobile): a sub-agent opened from its parent on a narrow iPad keeps Back
In split view the thread bar hid the native back item because the list sits beside the page. A thread pushed on top of its parent thread (iPad windows too narrow for the side column) is not beside the list, so it now keeps the back item and with it the edge-swipe pop. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 2d8a843 commit 69edc72

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

‎apps/mobile/src/components/ui/AppBar.tsx‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Toolbar } from "./Toolbar";
22
import { AppActivityIndicator } from "./AppActivityIndicator";
33
import type { HeaderBarButtonMailSearchToolbarItem, SearchBarCommands } from "react-native-screens";
4-
import { NavigationContext } from "@react-navigation/native";
5-
import { use, useId, useLayoutEffect, useRef } from "react";
4+
import { NavigationContext, NavigationRouteContext } from "@react-navigation/native";
5+
import { use, useId, useLayoutEffect, useRef, useSyncExternalStore } from "react";
66
import { View } from "react-native";
77
import { createNativeHeaderMenu } from "./nativeHeaderMenu.ios";
88
import { ScreenHeaderButton } from "./ScreenHeaderButton";
@@ -63,6 +63,17 @@ export function AppBar(props: AppBarProps) {
6363
? { ...props.backInSplitView, onPress: splitBackPress }
6464
: null;
6565
const navigation = use(NavigationContext);
66+
const route = use(NavigationRouteContext);
67+
// A thread opened from another thread sits on it, not beside the list, so it keeps Back.
68+
const threadBelow = useSyncExternalStore(
69+
(onChange) => navigation?.addListener("state", onChange) ?? (() => {}),
70+
() => {
71+
const routes = navigation?.getState()?.routes;
72+
const index = routes?.findIndex((candidate) => candidate.key === route?.key) ?? -1;
73+
return route?.name === "Thread" && index > 0 && routes?.[index - 1]?.name === "Thread";
74+
},
75+
);
76+
const listBeside = layout.usesSplitView && props.onBackToList !== undefined && !threadBelow;
6677
const rootBack =
6778
!layout.usesSplitView && props.onBackToList && navigation?.canGoBack() === false
6879
? props.onBackToList
@@ -113,7 +124,7 @@ export function AppBar(props: AppBarProps) {
113124
headerBackVisible:
114125
props.onClose === undefined &&
115126
splitBack === null &&
116-
!(layout.usesSplitView && props.onBackToList) &&
127+
!listBeside &&
117128
!(props.guardBack && props.onBack),
118129
...(props.guardBack ? { gestureEnabled: false } : undefined),
119130
title: props.title,

0 commit comments

Comments
 (0)