Skip to content
TypeScript

fix(mobile): every inspector pane draws its bar through AppBar

Julius Marminge0e233fc3ec49
diff --git a/apps/mobile/src/features/devices/DevicePreviewRouteScreen.tsx b/apps/mobile/src/features/devices/DevicePreviewRouteScreen.tsx
index 1f6e01d7858..482d553467c 100644
--- a/apps/mobile/src/features/devices/DevicePreviewRouteScreen.tsx
+++ b/apps/mobile/src/features/devices/DevicePreviewRouteScreen.tsx
@@ -9,7 +9,8 @@ import {
import { useIsFocused, useNavigation, type StaticScreenProps } from "@react-navigation/native";
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
import * as Cause from "effect/Cause";
-import { useEffect, useRef, useState, type RefObject } from "react";
+import { use, useEffect, useRef, useState, type RefObject } from "react";
+import { HeaderHeightContext } from "@react-navigation/elements";
import * as Haptics from "expo-haptics";
import { Accelerometer } from "expo-sensors";
import { Pressable, StatusBar, View } from "react-native";
@@ -26,6 +27,7 @@ import {
androidHeaderMenuActions,
findHeaderMenuAction,
} from "../../components/ui/headerMenu.android";
+import { AppBar } from "../../components/ui/AppBar";
import type { AppBarMenuItem } from "../../components/ui/AppBar.types";
import { useAppForeground } from "../../lib/appState";
import { useHardwareBack } from "../../lib/backHandler";
@@ -88,6 +90,8 @@ export function DevicePreviewScreen({
}) {
const embedded = onMaximize !== undefined;
const insets = useSafeAreaInsets();
+ // In a pane the stream sits below the pane's bar, which content otherwise slides under.
+ const headerHeight = use(HeaderHeightContext) ?? 0;
// NativeColumnContent already insets the sides, so only a book fold moves the hidden-controls pill.
const handleBounds = deriveBottomControlInsets(useNativeColumnLayoutMetrics());
const { themeVariables } = useAppearancePreferences();
@@ -265,20 +269,19 @@ export function DevicePreviewScreen({
<View className="flex-1" style={{ backgroundColor: themeVariables["--color-sheet-solid"] }}>
{!embedded ? <StatusBar hidden animated /> : null}
{embedded ? (
- <View
- className="flex-row items-center gap-1 px-2 pb-2"
- style={{ paddingTop: Math.max(insets.top, 8) }}
- >
- <SheetCloseButton accessibilityLabel="Close device preview" onClose={onClose} />
- <AppText numberOfLines={1} className="min-w-0 flex-1 font-t3-medium text-sm">
- {preview?.name ?? "Devices"}
- </AppText>
- <ControlPill
- accessibilityLabel="Maximize device"
- icon="arrow.up.left.and.arrow.down.right"
- onPress={() => onMaximize(preview?.key ?? null)}
+ <>
+ <AppBar
+ title={preview?.name ?? "Devices"}
+ actions={[
+ {
+ accessibilityLabel: "Maximize device",
+ icon: "arrow.up.left.and.arrow.down.right",
+ onPress: () => onMaximize(preview?.key ?? null),
+ },
+ ]}
/>
- </View>
+ <View style={{ height: headerHeight }} />
+ </>
) : null}
{preview && focused && foreground ? (
<OpenDevicePreview
diff --git a/apps/mobile/src/features/layout/inspector-host.tsx b/apps/mobile/src/features/layout/inspector-host.tsx
index bec36d336bd..4a24eafb9b6 100644
--- a/apps/mobile/src/features/layout/inspector-host.tsx
+++ b/apps/mobile/src/features/layout/inspector-host.tsx
@@ -47,14 +47,8 @@ function PaneScreenContent(props: {
return (
<InspectorCloseContext value={props.onClose}>
<PaneContext value="inspector">
- {props.pane.nativeStack ? (
- content
- ) : (
- <>
- <PaneHeader store={store} />
- <NativeColumnContent>{content}</NativeColumnContent>
- </>
- )}
+ <PaneHeader store={store} />
+ <NativeColumnContent>{content}</NativeColumnContent>
</PaneContext>
</InspectorCloseContext>
);
diff --git a/apps/mobile/src/features/layout/inspector-panes.ts b/apps/mobile/src/features/layout/inspector-panes.ts
index ab0366341c0..54dd8ef86fc 100644
--- a/apps/mobile/src/features/layout/inspector-panes.ts
+++ b/apps/mobile/src/features/layout/inspector-panes.ts
@@ -5,8 +5,6 @@ export interface InspectorPane {
readonly render: () => ReactNode;
/** Opening one of these panes soon mounts the others too, so switching between them is instant. */
readonly prewarm?: boolean;
- /** The pane is a native stack of its own, which draws its bar and insets its content itself. */
- readonly nativeStack?: boolean;
}
/** What a route shows in the workspace's inspector: its panes and the one on screen. */
diff --git a/apps/mobile/src/features/threads/ThreadRouteScreen.tsx b/apps/mobile/src/features/threads/ThreadRouteScreen.tsx
index 4432da72cfb..53c06fe6733 100644
--- a/apps/mobile/src/features/threads/ThreadRouteScreen.tsx
+++ b/apps/mobile/src/features/threads/ThreadRouteScreen.tsx
@@ -631,8 +631,6 @@ function ThreadRouteContent(
{
key: "preview",
render: renderPreviewInspector,
- // A thread preview runs its own navigator, whose screens draw its bar.
- nativeStack: previewTarget?.type === "thread",
},
]
: []),
diff --git a/apps/mobile/src/features/threads/thread-inspector-preview.tsx b/apps/mobile/src/features/threads/thread-inspector-preview.tsx
index b999e225e75..85c08546e7d 100644
--- a/apps/mobile/src/features/threads/thread-inspector-preview.tsx
+++ b/apps/mobile/src/features/threads/thread-inspector-preview.tsx
@@ -1,20 +1,33 @@
import {
+ createNavigatorFactory,
NavigationContainer,
NavigationIndependentTree,
+ StackRouter,
useIsFocused,
useNavigation,
+ useNavigationBuilder,
+ type NavigatorTypeBagBase,
+ type ParamListBase,
+ type StackActionHelpers,
+ type StackNavigationState,
+ type StackRouterOptions,
+ type StaticConfig,
type StaticScreenProps,
+ type TypedNavigator,
} from "@react-navigation/native";
+import type {
+ NativeStackNavigationEventMap,
+ NativeStackNavigationOptions,
+ NativeStackNavigatorProps,
+ NativeStackTypeBag,
+} from "@react-navigation/native-stack";
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
import { type ReactNode } from "react";
import { View } from "react-native";
-import { IconButton } from "../../components/ui/IconButton";
+import { AppBar } from "../../components/ui/AppBar";
import { SheetHeader } from "../../components/ui/SheetHeader";
-import { InspectorCloseContext } from "../layout/inspector-bar-store";
-import { createV5StackNavigator } from "../../native/createV5StackNavigator";
import { NativeStackScreenOptions } from "../../native/StackHeader";
-import { WorkspaceSlotOptionsContext } from "../../native/v5-workspace-context";
import { useMobileNavigationTheme } from "../../lib/useMobileNavigationTheme";
import { DevicePreviewScreen } from "../devices/DevicePreviewRouteScreen";
import {
@@ -26,50 +39,96 @@ import {
type ThreadInspectorTarget,
} from "./thread-inspector-navigation";
-export interface ThreadInspectorPresentation {
- readonly onClose: () => void;
- readonly onMaximize?: () => void;
-}
+/** A thread shown outside its route: in the inspector pane, or presented full screen with a close. */
+export type ThreadInspectorPresentation =
+ | { readonly onMaximize: () => void }
+ | { readonly onClose: () => void };
export function ThreadInspectorHeader(
props: ThreadInspectorPresentation & { readonly title: string },
) {
+ if ("onMaximize" in props) {
+ return (
+ <AppBar
+ title={props.title}
+ actions={[
+ {
+ accessibilityLabel: "Maximize thread",
+ icon: "arrow.up.left.and.arrow.down.right",
+ onPress: props.onMaximize,
+ },
+ ]}
+ />
+ );
+ }
return (
<>
<NativeStackScreenOptions options={{ headerShown: true, headerTransparent: true }} />
- <SheetHeader
- title={props.title}
- onClose={props.onClose}
- accessibilityLabel="Close thread preview"
- trailing={
- props.onMaximize ? (
- <IconButton
- icon="arrow.up.left.and.arrow.down.right"
- accessibilityLabel="Maximize thread"
- onPress={props.onMaximize}
- />
- ) : undefined
- }
- />
+ <SheetHeader title={props.title} onClose={props.onClose} accessibilityLabel="Close thread" />
</>
);
}
-const PreviewStack = createV5StackNavigator<{
+/**
+ * Gives the previewed thread a route of its own, so its route hooks and actions never reach the
+ * host thread. It draws nothing: the thread's AppBar writes into the pane's bar.
+ */
+function PreviewRouteNavigator({
+ id,
+ initialRouteName,
+ UNSTABLE_routeNamesChangeBehavior,
+ children,
+ layout,
+ screenListeners,
+ screenOptions,
+ screenLayout,
+ UNSTABLE_router,
+}: NativeStackNavigatorProps) {
+ const { state, descriptors, NavigationContent } = useNavigationBuilder<
+ StackNavigationState<ParamListBase>,
+ StackRouterOptions,
+ StackActionHelpers<ParamListBase>,
+ NativeStackNavigationOptions,
+ NativeStackNavigationEventMap
+ >(StackRouter, {
+ id,
+ initialRouteName,
+ UNSTABLE_routeNamesChangeBehavior,
+ children,
+ layout,
+ screenListeners,
+ screenOptions,
+ screenLayout,
+ UNSTABLE_router,
+ });
+ const route = state.routes[state.index];
+ return <NavigationContent>{route ? descriptors[route.key]?.render() : null}</NavigationContent>;
+}
+
+type PreviewTypeBag<ParamList extends ParamListBase> = Omit<
+ NativeStackTypeBag<ParamList, undefined>,
+ "Navigator"
+> & { Navigator: typeof PreviewRouteNavigator };
+function createPreviewRouteNavigator<
+ const ParamList extends ParamListBase,
+ const TypeBag extends NavigatorTypeBagBase = PreviewTypeBag<ParamList>,
+ const Config extends StaticConfig<TypeBag> = StaticConfig<TypeBag>,
+>(config?: Config): TypedNavigator<TypeBag, Config> {
+ return createNavigatorFactory(PreviewRouteNavigator)(config);
+}
+
+const PreviewStack = createPreviewRouteNavigator<{
Thread: { readonly environmentId: string; readonly threadId: string };
}>();
+/** A thread shown beside or over the workspace does not take the workspace's content width. */
export function InspectorContentScope({ children }: { readonly children: ReactNode }) {
return (
- <WorkspaceSlotOptionsContext value={null}>
- <InspectorCloseContext value={null}>
- <WorkspaceContentWidthContext value={null}>
- <WorkspaceSettledContentWidthContext value={null}>
- {children}
- </WorkspaceSettledContentWidthContext>
- </WorkspaceContentWidthContext>
- </InspectorCloseContext>
- </WorkspaceSlotOptionsContext>
+ <WorkspaceContentWidthContext value={null}>
+ <WorkspaceSettledContentWidthContext value={null}>
+ {children}
+ </WorkspaceSettledContentWidthContext>
+ </WorkspaceContentWidthContext>
);
}
@@ -112,16 +171,12 @@ export function ThreadInspectorPreview(props: {
<View className="flex-1 bg-screen">
<NavigationIndependentTree>
<NavigationContainer theme={theme} onUnhandledAction={navigation.dispatch}>
- <PreviewStack.Navigator
- key={`${target.environmentId}:${target.threadId}`}
- screenOptions={{ headerBackVisible: false }}
- >
+ <PreviewStack.Navigator key={`${target.environmentId}:${target.threadId}`}>
<PreviewStack.Screen name="Thread" initialParams={target}>
{(screen) =>
props.renderThread({
route: screen.route,
inspectorPresentation: {
- onClose: props.onClose,
onMaximize: () =>
navigation.navigate("ThreadInspectorFullscreen", {
environmentId: screen.route.params.environmentId,