Skip to content
TypeScript

refactor(mobile): Android's sidebar is the Home route in the sidebar column (#27087)

Julius Marminged1b9b230081f
diff --git a/apps/mobile/src/Stack.tsx b/apps/mobile/src/Stack.tsx
index c95e0864ca6..9986176c7a3 100644
--- a/apps/mobile/src/Stack.tsx
+++ b/apps/mobile/src/Stack.tsx
@@ -50,7 +50,6 @@ import { ConnectOnboardingRouteScreen } from "./features/cloud/ConnectOnboarding
import { AttachmentFileScreen } from "./features/files/AttachmentFileScreen";
import { ThreadFilesTreeScreen, ThreadFileScreen } from "./features/files/ThreadFilesRouteScreen";
import { AdaptiveWorkspaceLayout } from "./features/layout/AdaptiveWorkspaceLayout";
-import { selectedPullRequestKey } from "./features/pull-requests/pullRequestSelection";
import {
HardwareKeyboardCommandOverlay,
HardwareKeyboardCommandProvider,
@@ -535,7 +534,6 @@ function RootStackLayout(props: {
pathname={workspaceLocation.pathname}
workspaceRouteKey={workspaceLocation.routeKey}
workspaceRouteName={workspaceLocation.routeName}
- selectedPullRequestKey={selectedPullRequestKey(props.state)}
>
{props.children}
<HardwareKeyboardCommandOverlay />
@@ -619,6 +617,9 @@ const RootStackConfig = createWorkspaceStackNavigator({
contentStyle: { backgroundColor: "transparent" },
headerBackVisible: false,
...getCompactBrandHeaderOptions(),
+ // Android draws Home's bars itself. Set here, not by the screen: Home also renders in the
+ // sidebar column, and that copy clears the route's set options when it unmounts.
+ headerShown: Platform.OS !== "android",
},
}),
PullRequest: createNativeStackScreen({
diff --git a/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx b/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
index a4e81e85559..504a8309b83 100644
--- a/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
+++ b/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
@@ -7,10 +7,6 @@ import { SafeAreaInsetsContext, useSafeAreaInsets } from "react-native-safe-area
import { AdaptiveWorkspaceContext, useAdaptiveWorkspaceLayout } from "./adaptive-workspace-context";
import { threadSelectionDeferral } from "./deferred-navigation";
import { uuidv4 } from "../../lib/uuid";
-import type {
- EnvironmentProject,
- EnvironmentThreadShell,
-} from "@t3tools/client-runtime/state/shell";
import { EnvironmentId, ThreadId, type SidebarProjectGroupingMode } from "@t3tools/contracts";
import { useAtomValue } from "@effect/atom-react";
import { NavigationContext, NavigationRouteContext, useNavigation } from "@react-navigation/native";
@@ -44,7 +40,6 @@ import {
isPrimarySidebarPinned,
isWorkspaceListPath,
} from "../../lib/layout";
-import { scopedThreadKey } from "../../lib/scopedEntities";
import type { ThreadListFilters } from "../../persistence/mobile-preferences";
import { appAtomRegistry } from "../../state/atom-registry";
import { useProjects } from "../../state/entities";
@@ -61,13 +56,11 @@ import {
import { useAndroidControlSizing } from "../../components/ui/useAndroidControlSizing";
import { useEnabledNavigationTabs } from "../workspace/navigation-tabs";
import { FLOATING_TABS, floatingTabsMetrics } from "../workspace/floating-workspace-tabs";
-import { AndroidHomeFabLayout } from "../home/AndroidHomeFab";
import {
AndroidWorkspaceNavigation,
FloatingWorkspaceTabs,
ANDROID_WORKSPACE_RAIL_WIDTH,
} from "../workspace/AndroidWorkspaceNavigation";
-import { AndroidWorkspaceSidebar } from "../workspace/AndroidWorkspaceSidebar";
import {
selectWorkspaceDetail,
type WorkspaceDetail,
@@ -77,9 +70,6 @@ import { startOpeningDetail } from "../workspace/useSelectWorkspaceDetail";
import { useWorkspaceTabs } from "../workspace/WorkspaceTabsContext";
import { HomeListOptionsProvider } from "../home/home-list-options";
import { newTaskDestination } from "../threads/new-task-project-selection";
-import { usePendingTaskListActions } from "../home/usePendingTaskListActions";
-import { ThreadNavigationSidebar } from "../threads/ThreadNavigationSidebar";
-import { useOpenThreadPullRequests } from "../threads/use-open-thread-pull-requests";
import { RenderErrorBoundary, RenderFailureView } from "../../components/RenderErrorBoundary";
import { PaneContext } from "../../components/ui/Pane";
import { WORKSPACE_PANE_TIMING } from "./workspace-pane-animation";
@@ -97,7 +87,6 @@ import { useNativeLayoutMetrics } from "../../native/native-layout-metrics";
import { AndroidHingeObserver } from "../../native/AndroidHingeObserver";
import { WindowHingeContext } from "../../native/window-hinge-context";
import { useAndroidWorkspaceRoot } from "../workspace/AndroidWorkspaceTabsProvider";
-import { openSettings } from "../settings/settings-navigation";
import { dispatchRootStackReset, rootStackState } from "../../lib/root-stack-reset";
import {
currentWorkspaceSelections,
@@ -110,6 +99,7 @@ import {
import type { WorkspaceTab } from "../workspace/workspace-tabs-state";
import { workspaceRoutesOf } from "./workspace-overlay-routes";
import { SettingsWorkspaceLayout } from "../settings/SettingsWorkspaceLayout";
+import { WorkspaceThreadSidebar } from "../workspace/WorkspaceThreadSidebar";
export { useAdaptiveWorkspaceLayout };
@@ -187,7 +177,6 @@ export function AdaptiveWorkspaceLayout(props: {
readonly pathname: string;
readonly workspaceRouteKey: string | undefined;
readonly workspaceRouteName: string | undefined;
- readonly selectedPullRequestKey?: string | null;
}) {
const preferencesResult = useAtomValue(mobilePreferencesAtom);
if (!AsyncResult.isSuccess(preferencesResult)) {
@@ -214,7 +203,6 @@ function AdaptiveWorkspaceLayoutContent(
readonly pathname: string;
readonly workspaceRouteKey: string | undefined;
readonly workspaceRouteName: string | undefined;
- readonly selectedPullRequestKey?: string | null;
} & {
readonly projectGroupingMode: SidebarProjectGroupingMode;
readonly savedThreadListFilters?: ThreadListFilters | undefined;
@@ -375,26 +363,6 @@ function AdaptiveWorkspaceLayoutContent(
workspacePage,
],
);
- const activeThread = parseActiveThreadPath(pathname);
- const environmentId = activeThread?.environmentId ?? null;
- const threadId = activeThread?.threadId ?? null;
- const selectedThreadRef = (() => {
- if (environmentId === null || threadId === null) {
- return null;
- }
- try {
- return {
- environmentId: EnvironmentId.make(environmentId),
- threadId: ThreadId.make(threadId),
- };
- } catch {
- return null;
- }
- })();
- const selectedThreadKey =
- selectedThreadRef === null
- ? null
- : scopedThreadKey(selectedThreadRef.environmentId, selectedThreadRef.threadId);
// Routes still on the stack remember their reveal, so going back to one keeps the user's choice.
const revealedInspectors = useRef<ReadonlyMap<string, string>>(new Map());
const workspaceInspectorOwner = useRef<symbol | null>(null);
@@ -570,38 +538,6 @@ function AdaptiveWorkspaceLayoutContent(
return true;
});
- // Create at root: the iOS sidebar renders in an independent navigation tree.
- const handleOpenEnvironmentSettings = () => {
- openSettings(navigation, "SettingsEnvironments");
- };
-
- const handleOpenThreadPullRequests = useOpenThreadPullRequests();
- const { openPendingTask: handleOpenPendingTask } =
- usePendingTaskListActions(handleSelectThreadRoute);
-
- const handleNewThreadOnBranch = (thread: EnvironmentThreadShell) => {
- handleSelectThreadRoute({
- draft: {
- requestId: uuidv4(),
- environmentId: String(thread.environmentId),
- projectId: String(thread.projectId),
- branch: thread.branch,
- worktreePath: thread.worktreePath,
- },
- });
- };
-
- const handleNewThreadInProject = (project: EnvironmentProject) => {
- handleSelectThreadRoute({
- draft: {
- requestId: uuidv4(),
- environmentId: String(project.environmentId),
- projectId: String(project.id),
- title: project.title,
- },
- });
- };
-
const inspectorColumnTargetWidth = panes.auxiliaryPaneVisible
? (panes.auxiliaryPaneWidth ?? 0)
: 0;
@@ -776,13 +712,6 @@ function AdaptiveWorkspaceLayoutContent(
: ("100%" as const),
}));
- const handleSelectThread = (thread: EnvironmentThreadShell) => {
- handleSelectThreadRoute({
- environmentId: String(thread.environmentId),
- threadId: String(thread.id),
- });
- };
-
// Rotating flips the overlay; until the new size reaches JS, predict the reset above.
const sidebarOverRotates =
nativeWorkspace && nativeMetrics?.hasHinge === true && layout.usesSplitView;
@@ -814,6 +743,7 @@ function AdaptiveWorkspaceLayoutContent(
toggleAuxiliaryPane,
sidebarToggleable: layout.usesSplitView && !primarySidebarPinned && !workspacePage,
togglePrimarySidebar,
+ revealPrimarySidebar,
setPrimarySidebarVisible,
openWorkspaceTab,
setAuxiliaryPaneWidth: setFileInspectorPreferredWidth,
@@ -838,7 +768,7 @@ function AdaptiveWorkspaceLayoutContent(
</HomeListOptionsProvider>
);
}
- const renderColumns = (children: ReactNode) => (
+ const renderColumns = (children: ReactNode, sidebar?: ReactNode) => (
<View
testID="adaptive-workspace-layout"
className={Platform.OS === "android" ? "flex-1 flex-row bg-header" : "flex-1 flex-row"}
@@ -875,32 +805,8 @@ function AdaptiveWorkspaceLayoutContent(
/>
)}
>
- <AndroidWorkspaceSidebar
- onRequestVisibility={revealPrimarySidebar}
- selectedPullRequestKey={props.selectedPullRequestKey ?? null}
- >
- <AndroidHomeFabLayout
- sidebar
- disabled={workspacePage}
- onStartNewTask={handleStartNewTask}
- >
- <ThreadNavigationSidebar
- width={layout.listPaneWidth}
- visible={panes.primarySidebarVisible}
- onRequestVisibility={revealPrimarySidebar}
- selectedThreadKey={selectedThreadKey}
- onOpenSettings={handleOpenSettings}
- onOpenEnvironmentSettings={handleOpenEnvironmentSettings}
- onNewThreadInProject={handleNewThreadInProject}
- onNewThreadOnBranch={handleNewThreadOnBranch}
- onOpenPendingTask={handleOpenPendingTask}
- onSelectThread={handleSelectThread}
- onOpenThreadPullRequests={handleOpenThreadPullRequests}
- onSearchQueryChange={setPrimarySidebarSearchQuery}
- searchQuery={primarySidebarSearchQuery}
- />
- </AndroidHomeFabLayout>
- </AndroidWorkspaceSidebar>
+ {/* Without a sidebar route (iPadOS before 26) the columns draw the thread list. */}
+ {sidebar ?? <WorkspaceThreadSidebar />}
</RenderErrorBoundary>
</PaneContext>
{/* Keep the pill under the content throughout the sidebar's clipping animation. */}
diff --git a/apps/mobile/src/features/layout/adaptive-workspace-context.ts b/apps/mobile/src/features/layout/adaptive-workspace-context.ts
index 86630ae8d90..f443a56d652 100644
--- a/apps/mobile/src/features/layout/adaptive-workspace-context.ts
+++ b/apps/mobile/src/features/layout/adaptive-workspace-context.ts
@@ -34,6 +34,8 @@ interface AdaptiveWorkspaceContextValue {
*/
readonly sidebarToggleable: boolean;
readonly togglePrimarySidebar: () => void;
+ /** Shows the sidebar, setting aside the keyboard or an inspector that took its room. */
+ readonly revealPrimarySidebar: () => void;
readonly setPrimarySidebarVisible: (visible: boolean) => void;
/** Opens a workspace tab with its list and, with columns, the page it last showed. */
readonly openWorkspaceTab: (
@@ -78,6 +80,7 @@ export const AdaptiveWorkspaceContext = createContext<AdaptiveWorkspaceContextVa
toggleAuxiliaryPane: () => undefined,
sidebarToggleable: false,
togglePrimarySidebar: () => undefined,
+ revealPrimarySidebar: () => undefined,
setPrimarySidebarVisible: () => undefined,
openWorkspaceTab: () => undefined,
setAuxiliaryPaneWidth: () => undefined,
diff --git a/apps/mobile/src/features/layout/createWorkspaceStackNavigator.android.tsx b/apps/mobile/src/features/layout/createWorkspaceStackNavigator.android.tsx
index 765b2324379..46592527501 100644
--- a/apps/mobile/src/features/layout/createWorkspaceStackNavigator.android.tsx
+++ b/apps/mobile/src/features/layout/createWorkspaceStackNavigator.android.tsx
@@ -46,6 +46,8 @@ function WorkspaceStackView(props: ViewProps) {
if (!visibleRoute) return <NativeStackView {...props} />;
const visibleDescriptor = props.descriptors[visibleRoute.key]!;
+ // Home is the sidebar beside the pages, and under them the page shown when none is selected.
+ const home = workspaceRoutes.find((route) => route.name === "Home");
const baseRoute = { key: `${props.state.key}:workspace`, name: "Workspace" };
const baseDescriptor: Descriptor = {
...visibleDescriptor,
@@ -61,6 +63,7 @@ function WorkspaceStackView(props: ViewProps) {
preloadedRoutes: props.state.preloadedRoutes.filter((route) => !isOverlay(route)),
}}
/>,
+ home ? props.descriptors[home.key]?.render() : null,
),
};
const routes = [baseRoute, ...projection.overlays];
diff --git a/apps/mobile/src/features/layout/workspace-presentation-context.tsx b/apps/mobile/src/features/layout/workspace-presentation-context.tsx
index ec1544dce82..b59ad953da5 100644
--- a/apps/mobile/src/features/layout/workspace-presentation-context.tsx
+++ b/apps/mobile/src/features/layout/workspace-presentation-context.tsx
@@ -2,6 +2,7 @@ import { createContext, type ReactElement, type ReactNode } from "react";
/** Android's native presentation stack surrounds all workspace columns. */
export const WorkspacePresentationHostContext = createContext(false);
+/** Lays out the workspace columns around the navigator's content and its sidebar route. */
export const WorkspaceColumnsRendererContext = createContext<
- ((children: ReactNode) => ReactElement) | null
+ ((content: ReactNode, sidebar: ReactNode) => ReactElement) | null
>(null);
diff --git a/apps/mobile/src/features/threads/use-visible-second-clock.ts b/apps/mobile/src/features/threads/use-visible-second-clock.ts
index e48ab5a9869..4242544231e 100644
--- a/apps/mobile/src/features/threads/use-visible-second-clock.ts
+++ b/apps/mobile/src/features/threads/use-visible-second-clock.ts
@@ -3,6 +3,7 @@ import { secondTick } from "@t3tools/client-runtime/clock";
import { useSyncExternalStore } from "react";
import { useAppActive } from "../../lib/appState";
+import { usePaneRole } from "../../components/ui/Pane";
const subscribeNever = () => () => undefined;
@@ -12,8 +13,10 @@ const subscribeNever = () => () => undefined;
*/
export function useVisibleSecondClock(enabled: boolean): number {
const focused = useIsFocused();
+ // The sidebar's route stays unfocused under the page beside it.
+ const inSidebar = usePaneRole() === "sidebar";
const appActive = useAppActive();
- const ticking = enabled && focused && appActive;
+ const ticking = enabled && (focused || inSidebar) && appActive;
// While paused the snapshot still reads the shared tick, so resuming shows
// the current second rather than the one the clock stopped on.
return useSyncExternalStore(
diff --git a/apps/mobile/src/features/workspace/AndroidWorkspaceSidebar.android.tsx b/apps/mobile/src/features/workspace/AndroidWorkspaceSidebar.android.tsx
index 7d3ce6f36b2..73cd078c9b8 100644
--- a/apps/mobile/src/features/workspace/AndroidWorkspaceSidebar.android.tsx
+++ b/apps/mobile/src/features/workspace/AndroidWorkspaceSidebar.android.tsx
@@ -2,7 +2,7 @@ import { useAndroidFloatingTabs } from "../settings/appearance/AppearancePrefere
import { WorkspaceNoTabs } from "./WorkspaceNoTabs";
import { useEnabledNavigationTabs } from "./navigation-tabs";
import { NAVIGATION_TAB_ORDER } from "./navigation-tab-order";
-import { type ReactNode } from "react";
+import { useNavigationState } from "@react-navigation/native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { useAndroidControlSizing } from "../../components/ui/useAndroidControlSizing";
import { FLOATING_TABS } from "./floating-workspace-tabs";
@@ -10,20 +10,27 @@ import { View } from "react-native";
import { ScreenContent } from "../../components/ui/ScreenContent";
import { PullRequestsScreen } from "../pull-requests/PullRequestsScreen";
import { PullRequestToolbar } from "../pull-requests/PullRequestToolbar.android";
+import { selectedPullRequestKey } from "../pull-requests/pullRequestSelection";
+import { AndroidHomeFabLayout } from "../home/AndroidHomeFab";
+import { useAdaptiveWorkspaceLayout } from "../layout/adaptive-workspace-context";
+import { useAndroidWorkspaceRoot } from "./AndroidWorkspaceTabsProvider";
import { WorkspaceTabsContext, useWorkspaceTabs } from "./WorkspaceTabsContext";
import { WorkspaceTabPanes } from "./WorkspaceTabPanes";
+import { WorkspaceThreadSidebar } from "./WorkspaceThreadSidebar";
import { WorkspaceAppBarScope } from "../../components/ui/WorkspaceAppBar.android";
-export function AndroidWorkspaceSidebar(props: {
- readonly children: ReactNode;
- readonly onRequestVisibility: () => void;
- readonly selectedPullRequestKey: string | null;
-}) {
+/** The Home route in the sidebar column: the selected tab's list. */
+export function AndroidWorkspaceSidebar() {
const floatingTabsEnabled = useAndroidFloatingTabs();
const workspace = useWorkspaceTabs()!;
const enabled = useEnabledNavigationTabs();
const insets = useSafeAreaInsets();
const { fabSize } = useAndroidControlSizing();
+ const { revealPrimarySidebar, startNewTask } = useAdaptiveWorkspaceLayout();
+ const selectedPullRequest = useNavigationState(selectedPullRequestKey);
+ // Settings and Usage cover the sidebar.
+ const coveredByPage =
+ (useAndroidWorkspaceRoot()?.settingsOpen ?? false) || workspace.state.selectedTab === "usage";
const bottomClearance = floatingTabsEnabled
? insets.bottom + FLOATING_TABS.bottom + FLOATING_TABS.edge + fabSize
: 16;
@@ -36,19 +43,21 @@ export function AndroidWorkspaceSidebar(props: {
selected={workspace.state.selectedTab}
renderTab={(tab) =>
tab === "threads" ? (
- props.children
+ <AndroidHomeFabLayout sidebar disabled={coveredByPage} onStartNewTask={startNewTask}>
+ <WorkspaceThreadSidebar />
+ </AndroidHomeFabLayout>
) : tab !== "pullRequests" ? (
<View className="flex-1 bg-screen" />
) : (
<WorkspaceTabsContext value={context}>
<PullRequestsScreen
sidebar
- selectedPullRequestKey={props.selectedPullRequestKey}
+ selectedPullRequestKey={selectedPullRequest}
renderFrame={(filters, list) => (
<View className="flex-1 bg-header">
<PullRequestToolbar
filters={filters}
- onRequestVisibility={props.onRequestVisibility}
+ onRequestVisibility={revealPrimarySidebar}
/>
<ScreenContent insetHorizontal>{list}</ScreenContent>
</View>
diff --git a/apps/mobile/src/features/workspace/AndroidWorkspaceSidebar.tsx b/apps/mobile/src/features/workspace/AndroidWorkspaceSidebar.tsx
deleted file mode 100644
index 6dbfa1cfa94..00000000000
--- a/apps/mobile/src/features/workspace/AndroidWorkspaceSidebar.tsx
+++ /dev/null
@@ -1,9 +0,0 @@
-import type { ReactNode } from "react";
-
-export function AndroidWorkspaceSidebar(props: {
- readonly children: ReactNode;
- readonly onRequestVisibility: () => void;
- readonly selectedPullRequestKey: string | null;
-}) {
- return props.children;
-}
diff --git a/apps/mobile/src/features/workspace/WorkspaceRootScreen.android.tsx b/apps/mobile/src/features/workspace/WorkspaceRootScreen.android.tsx
index 89c0177d46a..f2503f41b46 100644
--- a/apps/mobile/src/features/workspace/WorkspaceRootScreen.android.tsx
+++ b/apps/mobile/src/features/workspace/WorkspaceRootScreen.android.tsx
@@ -19,11 +19,17 @@ import { FLOATING_TABS } from "./floating-workspace-tabs";
import { WorkspaceTabsContext, useWorkspaceTabs } from "./WorkspaceTabsContext";
import { WorkspaceTabPanes } from "./WorkspaceTabPanes";
import { WorkspaceAppBarScope } from "../../components/ui/WorkspaceAppBar.android";
+import { usePaneRole } from "../../components/ui/Pane";
+import { AndroidWorkspaceSidebar } from "./AndroidWorkspaceSidebar.android";
import type { WorkspaceTab } from "./workspace-tabs-state";
const TABS: readonly WorkspaceTab[] = NAVIGATION_TAB_ORDER;
export function WorkspaceRootScreen() {
+ return usePaneRole() === "sidebar" ? <AndroidWorkspaceSidebar /> : <WorkspaceRoot />;
+}
+
+function WorkspaceRoot() {
const floatingTabsEnabled = useAndroidFloatingTabs();
const { layout, startNewTask } = useAdaptiveWorkspaceLayout();
const workspace = useWorkspaceTabs()!;
diff --git a/apps/mobile/src/features/workspace/WorkspaceThreadSidebar.tsx b/apps/mobile/src/features/workspace/WorkspaceThreadSidebar.tsx
new file mode 100644
index 00000000000..9b968908094
--- /dev/null
+++ b/apps/mobile/src/features/workspace/WorkspaceThreadSidebar.tsx
@@ -0,0 +1,100 @@
+import type {
+ EnvironmentProject,
+ EnvironmentThreadShell,
+} from "@t3tools/client-runtime/state/shell";
+import { EnvironmentId, ThreadId } from "@t3tools/contracts";
+import { useNavigation, useNavigationState } from "@react-navigation/native";
+
+import { scopedThreadKey } from "../../lib/scopedEntities";
+import { uuidv4 } from "../../lib/uuid";
+import { usePendingTaskListActions } from "../home/usePendingTaskListActions";
+import { useAdaptiveWorkspaceLayout } from "../layout/adaptive-workspace-context";
+import { openSettings } from "../settings/settings-navigation";
+import { ThreadNavigationSidebar } from "../threads/ThreadNavigationSidebar";
+import { useOpenThreadPullRequests } from "../threads/use-open-thread-pull-requests";
+import { useSelectWorkspaceDetail } from "./useSelectWorkspaceDetail";
+
+type Route = { readonly name: string; readonly params?: object };
+
+function selectedThreadKey(state: { readonly index: number; readonly routes: readonly Route[] }) {
+ const params = state.routes
+ .slice(0, state.index + 1)
+ .findLast((route) => route.name.startsWith("Thread"))?.params;
+ if (
+ !params ||
+ !("environmentId" in params) ||
+ !("threadId" in params) ||
+ typeof params.environmentId !== "string" ||
+ typeof params.threadId !== "string"
+ ) {
+ return null;
+ }
+ try {
+ return scopedThreadKey(
+ EnvironmentId.make(params.environmentId),
+ ThreadId.make(params.threadId),
+ );
+ } catch {
+ return null;
+ }
+}
+
+/** The thread list in the workspace's sidebar column. */
+export function WorkspaceThreadSidebar() {
+ const navigation = useNavigation();
+ const {
+ layout,
+ panes,
+ primarySidebarSearchQuery,
+ setPrimarySidebarSearchQuery,
+ revealPrimarySidebar,
+ openWorkspaceTab,
+ } = useAdaptiveWorkspaceLayout();
+ const selectDetail = useSelectWorkspaceDetail();
+ const openThreadPullRequests = useOpenThreadPullRequests();
+ const selectedThread = useNavigationState(selectedThreadKey);
+ const selectThreadRoute = (params: ReactNavigation.RootParamList["Thread"]) =>
+ selectDetail({ name: "Thread", params });
+ const { openPendingTask } = usePendingTaskListActions(selectThreadRoute);
+ return (
+ <ThreadNavigationSidebar
+ width={layout.listPaneWidth ?? 0}
+ visible={panes.primarySidebarVisible}
+ onRequestVisibility={revealPrimarySidebar}
+ selectedThreadKey={selectedThread}
+ onOpenSettings={() => openWorkspaceTab("settings")}
+ onOpenEnvironmentSettings={() => openSettings(navigation, "SettingsEnvironments")}
+ onNewThreadInProject={(project: EnvironmentProject) =>
+ selectThreadRoute({
+ draft: {
+ requestId: uuidv4(),
+ environmentId: String(project.environmentId),
+ projectId: String(project.id),
+ title: project.title,
+ },
+ })
+ }
+ onNewThreadOnBranch={(thread: EnvironmentThreadShell) =>
+ selectThreadRoute({
+ draft: {
+ requestId: uuidv4(),
+ environmentId: String(thread.environmentId),
+ projectId: String(thread.projectId),
+ branch: thread.branch,
+ worktreePath: thread.worktreePath,
+ },
+ })
+ }
+ onOpenPendingTask={openPendingTask}
+ onSelectThread={(thread) =>
+ selectThreadRoute({
+ environmentId: String(thread.environmentId),
+ threadId: String(thread.id),
+ })
+ }
+ onOpenThreadPullRequests={openThreadPullRequests}
+ onSearchQueryChange={setPrimarySidebarSearchQuery}
+ searchQuery={primarySidebarSearchQuery}
+ />
+ );
+}
diff --git a/apps/mobile/src/features/workspace/workspace-tabs-state.test.ts b/apps/mobile/src/features/workspace/workspace-tabs-state.test.ts
index fde64ea6ff7..2838de7543d 100644
--- a/apps/mobile/src/features/workspace/workspace-tabs-state.test.ts
+++ b/apps/mobile/src/features/workspace/workspace-tabs-state.test.ts
@@ -232,6 +232,8 @@ vi.mock("./AndroidWorkspaceNavigation", () => ({
FloatingWorkspaceTabs: () => null,
}));
vi.mock("./WorkspaceNoTabs", () => ({ WorkspaceNoTabs: () => null }));
+vi.mock("../../components/ui/Pane", () => ({ usePaneRole: () => "screen" }));
+vi.mock("./AndroidWorkspaceSidebar.android", () => ({ AndroidWorkspaceSidebar: () => null }));
vi.mock("../../components/ui/WorkspaceAppBar.android", () => ({
WorkspaceAppBarScope: ({ children }: { children: ReactNode }) => children,
}));
diff --git a/apps/mobile/src/lib/backHandler.ts b/apps/mobile/src/lib/backHandler.ts
index 1a7e399106e..57990fa3b88 100644
--- a/apps/mobile/src/lib/backHandler.ts
+++ b/apps/mobile/src/lib/backHandler.ts
@@ -2,13 +2,17 @@ import { useIsFocused } from "@react-navigation/native";
import { useEffect, useEffectEvent } from "react";
import { BackHandler } from "react-native";
+import { usePaneRole } from "../components/ui/Pane";
+
/**
* Android hardware back while `active` and the owning screen is focused.
* Keyed on those alone, not `onBack`: BackHandler calls the newest listener
* first, so re-registering per render lets a covered screen consume Back.
*/
export function useHardwareBack(active: boolean, onBack: () => boolean) {
- const focused = useIsFocused();
+ // The sidebar's route stays unfocused under the page beside it.
+ const inSidebar = usePaneRole() === "sidebar";
+ const focused = useIsFocused() || inSidebar;
const handleBack = useEffectEvent(onBack);
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes to BackHandler for the focused screen's lifetime
useEffect(() => {