@@ -81,6 +81,7 @@ import { RenderErrorBoundary, RenderFailureView } from "../../components/RenderE
8181import { PaneContext } from "../../components/ui/Pane" ;
8282import { WORKSPACE_PANE_TIMING } from "./workspace-pane-animation" ;
8383import { WorkspaceInspectorPane } from "./workspace-inspector-pane" ;
84+ import { WorkspaceInspectorSheet } from "./workspace-inspector-sheet" ;
8485import {
8586 WorkspaceContentWidthContext ,
8687 WorkspaceSettledContentWidthContext ,
@@ -129,11 +130,6 @@ export function Inspector(props: {
129130 </ NavigationRouteContext . Provider >
130131 </ NavigationContext . Provider >
131132 ) ;
132- const reveal =
133- props . revealKey === undefined || route === undefined
134- ? undefined
135- : { routeKey : route . key , key : props . revealKey } ;
136-
137133 const focusedRef = useRef ( false ) ;
138134 const deactivateRef = useRef < ( ( ) => void ) | null > ( null ) ;
139135
@@ -142,7 +138,7 @@ export function Inspector(props: {
142138 deactivateRef . current ?.( ) ;
143139 return ;
144140 }
145- deactivateRef . current = registerWorkspaceInspector ( render , reveal ) ;
141+ deactivateRef . current = registerWorkspaceInspector ( render , route ?. key , props . revealKey ) ;
146142 } ) ;
147143
148144 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- Navigation focus events own the inspector registration lifetime.
@@ -356,7 +352,17 @@ function AdaptiveWorkspaceLayoutContent(
356352 const [ workspaceInspector , setWorkspaceInspector ] = useState < {
357353 readonly render : ( ) => ReactNode ;
358354 readonly active : boolean ;
355+ readonly routeKey : string | undefined ;
359356 } | null > ( null ) ;
357+ // Without a column the inspector is a sheet, opened only on request for the route on top, and
358+ // shown again when that route returns to the top.
359+ const [ inspectorSheetRoute , setInspectorSheetRoute ] = useState < string | null > ( null ) ;
360+ const inspectorSheetOpen =
361+ ! fileInspector . supported &&
362+ ! workspacePage &&
363+ inspectorSheetRoute !== null &&
364+ workspaceInspector ?. active === true &&
365+ workspaceInspector . routeKey === inspectorSheetRoute ;
360366 const inspectorActive = workspaceInspector ?. active ?? false ;
361367 const panes = useMemo (
362368 ( ) =>
@@ -388,17 +394,22 @@ function AdaptiveWorkspaceLayoutContent(
388394 const workspaceInspectorOwner = useRef < symbol | null > ( null ) ;
389395 const registerWorkspaceInspector = (
390396 render : ( ) => ReactNode ,
391- reveal ?: { readonly routeKey : string ; readonly key : string } ,
397+ routeKey : string | undefined ,
398+ revealKey ?: string ,
392399 ) => {
393400 const owner = Symbol ( "workspace-inspector" ) ;
394401 workspaceInspectorOwner . current = owner ;
395- setWorkspaceInspector ( { render, active : true } ) ;
396- if ( reveal && revealedInspectors . current . get ( reveal . routeKey ) !== reveal . key ) {
402+ setWorkspaceInspector ( { render, active : true , routeKey } ) ;
403+ if (
404+ routeKey !== undefined &&
405+ revealKey !== undefined &&
406+ revealedInspectors . current . get ( routeKey ) !== revealKey
407+ ) {
397408 const state = rootStackState ( navigation ) ;
398409 const live = new Set ( state ?. routes . slice ( 0 , state . index + 1 ) . map ( ( route ) => route . key ) ) ;
399410 revealedInspectors . current = new Map (
400- [ ...revealedInspectors . current , [ reveal . routeKey , reveal . key ] as const ] . filter (
401- ( [ routeKey ] ) => live . has ( routeKey ) || routeKey === reveal . routeKey ,
411+ [ ...revealedInspectors . current , [ routeKey , revealKey ] as const ] . filter (
412+ ( [ key ] ) => live . has ( key ) || key === routeKey ,
402413 ) ,
403414 ) ;
404415 setFileInspectorPreferredVisible ( true ) ;
@@ -452,7 +463,16 @@ function AdaptiveWorkspaceLayoutContent(
452463 } ;
453464 const sidebarCommands = primarySidebarPinned ? [ ] : ( [ "toggleSidebar" ] as const ) ;
454465 useHardwareKeyboardCommand ( sidebarCommands , handleToggleSidebarCommand ) ;
455- const showInspector = ( ) => setFileInspectorPreferredVisible ( true ) ;
466+ const showInspector = ( ) => {
467+ if ( fileInspector . supported ) {
468+ setFileInspectorPreferredVisible ( true ) ;
469+ setInspectorSheetRoute ( null ) ;
470+ return ;
471+ }
472+ const state = rootStackState ( navigation ) ;
473+ const top = workspaceRoutesOf ( state ?. routes . slice ( 0 , state . index + 1 ) ?? [ ] ) . workspace . at ( - 1 ) ;
474+ setInspectorSheetRoute ( top ?. key ?? null ) ;
475+ } ;
456476 const handleOpenFilesCommand = ( ) => {
457477 const activeThread = parseActiveThreadPath ( pathname ) ;
458478 if ( ! layout . usesSplitView || ! fileInspector . supported || activeThread === null ) {
@@ -466,7 +486,13 @@ function AdaptiveWorkspaceLayoutContent(
466486 return true ;
467487 } ;
468488 useHardwareKeyboardCommand ( "files" , handleOpenFilesCommand ) ;
469- const toggleAuxiliaryPane = ( ) => setFileInspectorPreferredVisible ( ( current ) => ! current ) ;
489+ const toggleAuxiliaryPane = ( ) => {
490+ if ( fileInspector . supported ) {
491+ setFileInspectorPreferredVisible ( ( current ) => ! current ) ;
492+ setInspectorSheetRoute ( null ) ;
493+ } else if ( inspectorSheetOpen ) setInspectorSheetRoute ( null ) ;
494+ else showInspector ( ) ;
495+ } ;
470496 /**
471497 * The one way to open a workspace tab: replaces the workspace with the tab's list and, when the
472498 * window has columns, the page it last showed, keeping any sheet on top. An overlay sidebar
@@ -502,6 +528,7 @@ function AdaptiveWorkspaceLayoutContent(
502528 threadSelectionDeferral . run ( ( ) => {
503529 if ( Platform . OS === "android" ) Keyboard . dismiss ( ) ;
504530 setFileInspectorPreferredVisible ( false ) ;
531+ setInspectorSheetRoute ( null ) ;
505532 if ( layout . variant === "medium" ) setPrimarySidebarVisible ( false ) ;
506533 workspace ?. dispatch ( {
507534 type : "select" ,
@@ -783,6 +810,11 @@ function AdaptiveWorkspaceLayoutContent(
783810 sidebarByOrientation,
784811 } ;
785812
813+ const inspectorSheet = (
814+ < WorkspaceInspectorSheet open = { inspectorSheetOpen } onClose = { ( ) => setInspectorSheetRoute ( null ) } >
815+ { workspaceInspector ?. render ( ) }
816+ </ WorkspaceInspectorSheet >
817+ ) ;
786818 if ( nativeWorkspace ) {
787819 return (
788820 < HomeListOptionsProvider
@@ -791,9 +823,14 @@ function AdaptiveWorkspaceLayoutContent(
791823 >
792824 < AdaptiveWorkspaceContext value = { contextValue } >
793825 < NativeWorkspaceInspectorContext
794- value = { { render : workspaceInspector ?. render , visible : inspectorColumnTargetWidth > 0 } }
826+ value = { {
827+ // Without a column the sheet shows it; the hidden native column must not mount it too.
828+ render : fileInspector . supported ? workspaceInspector ?. render : undefined ,
829+ visible : inspectorColumnTargetWidth > 0 ,
830+ } }
795831 >
796832 { props . children }
833+ { inspectorSheet }
797834 </ NativeWorkspaceInspectorContext >
798835 </ AdaptiveWorkspaceContext >
799836 </ HomeListOptionsProvider >
@@ -952,6 +989,7 @@ function AdaptiveWorkspaceLayoutContent(
952989 onClosed = { handleWorkspaceInspectorClosed }
953990 />
954991 </ PaneContext >
992+ { inspectorSheet }
955993 { shouldRenderNavigationRail && navigationRailWidth > 0 ? (
956994 // The rail reserves its slot above and draws over the panes, so it can widen over
957995 // the list in place. It takes the whole workspace only while it is open.
0 commit comments