// `rnx get screens` — print the current navigation stack + shell state + // any presented modal + keyboard. answers "what screen am I on?" without // having to dump the whole tree or scrape screen-specific testIDs. // // sources: // - navigation-runtime snapshot (test bridge) for screen stack + phase // - mainShell.getState() for active app + switcher / launch progress // - __sootsimKeyboard.getLayout() for keyboard visibility + spec import { inspectScreens } from './core' import type { WsBridge } from '../../ws-bridge' export async function runScreensSubcommand( bridge: WsBridge, opts: { json?: boolean } = {}, ): Promise { const { nav, route, keyboard, shell } = await inspectScreens(bridge) if (opts.json) { console.log(JSON.stringify({ shell: shell ?? null, nav, route, keyboard }, null, 2)) return } const lines: string[] = [] // shell — what app, what switcher state if (shell) { const activeApp = shell.activeApp ?? shell.state ?? '' const switcher = shell.showSwitcher ? ' (app switcher open)' : '' const launchProgress = typeof shell.launchProgress === 'number' && shell.launchProgress < 0.98 ? ` launching (${Math.round(shell.launchProgress * 100)}%)` : '' lines.push(`shell: ${activeApp}${switcher}${launchProgress}`) } else { lines.push(`shell: `) } // navigation stack if (nav) { const phase = nav.transitionPhase !== 'idle' ? ` (${nav.transitionPhase}, ${nav.activeTransitionCount} active)` : '' lines.push(`nav: phase=${nav.transitionPhase}${phase}`) if (nav.screens.length === 0) { lines.push(` `) } else { for (const s of nav.screens) { const marker = s.isActive ? '▶' : ' ' const route = s.routeName ? ` ${s.routeName}` : '' const header = s.headerHeight > 0 ? ` header=${s.headerHeight}` : '' const lt = s.largeTitleState && s.largeTitleState !== 'expanded' ? ` large-title=${s.largeTitleState}` : '' lines.push(` ${marker} #${s.id}${route}${header}${lt}`) } } } else { lines.push(`nav: `) } lines.push(`route: ${route?.currentPath ?? ''}`) if (route?.coveringPath) { lines.push(`covered: a presented screen (${route.coveringPath}) is above this route`) } // keyboard if (keyboard && keyboard.visible) { const type = keyboard.spec?.keyboardType ?? 'default' const ret = keyboard.spec?.returnKeyType ?? 'default' lines.push(`keyboard: visible (${type}, return=${ret}, mode=${keyboard.mode ?? '?'})`) } else { lines.push(`keyboard: hidden`) } console.log(lines.join('\n')) }