1
-import {
2
- createNavigatorFactory,
3
- NavigationContainer,
4
- NavigationIndependentTree,
5
- StackRouter,
6
- useIsFocused,
7
- useNavigation,
8
- useNavigationBuilder,
9
- type NavigatorTypeBagBase,
10
- type ParamListBase,
11
- type StackActionHelpers,
12
- type StackNavigationState,
13
- type StackRouterOptions,
14
- type StaticConfig,
15
- type StaticScreenProps,
16
- type TypedNavigator,
17
-} from "@react-navigation/native";
18
-import type {
19
- NativeStackNavigationEventMap,
20
- NativeStackNavigationOptions,
21
- NativeStackNavigatorProps,
22
- NativeStackTypeBag,
23
-} from "@react-navigation/native-stack";
1
+import { useIsFocused, useNavigation, type StaticScreenProps } from "@react-navigation/native";
2
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
3
import { type ReactNode } from "react";
4
import { View } from "react-native";
5
6
import { AppBar } from "../../components/ui/AppBar";
7
import { SheetHeader } from "../../components/ui/SheetHeader";
30
-import { NativeStackScreenOptions } from "../../native/StackHeader";
31
-import { useMobileNavigationTheme } from "../../lib/useMobileNavigationTheme";
8
import { DevicePreviewScreen } from "../devices/DevicePreviewRouteScreen";
9
import {
10
WorkspaceContentWidthContext,
14
ThreadInspectorNavigationContext,
15
type ThreadInspectorTarget,
16
} from "./thread-inspector-navigation";
17
+import { ThreadPreviewRoute } from "./thread-preview-route";
18
19
/** A thread shown outside its route: in the inspector pane, or presented full screen with a close. */
20
export type ThreadInspectorPresentation =
39
);
40
}
41
return (
65
- <>
66
- <NativeStackScreenOptions options={{ headerShown: true, headerTransparent: true }} />
67
- <SheetHeader title={props.title} onClose={props.onClose} accessibilityLabel="Close thread" />
68
- </>
42
+ <SheetHeader title={props.title} onClose={props.onClose} accessibilityLabel="Close thread" />
43
);
44
}
45
72
-/**
73
- * Gives the previewed thread a route of its own, so its route hooks and actions never reach the
74
- * host thread. It draws nothing: the thread's AppBar writes into the pane's bar.
75
- */
76
-function PreviewRouteNavigator({
77
- id,
78
- initialRouteName,
79
- UNSTABLE_routeNamesChangeBehavior,
80
- children,
81
- layout,
82
- screenListeners,
83
- screenOptions,
84
- screenLayout,
85
- UNSTABLE_router,
86
-}: NativeStackNavigatorProps) {
87
- const { state, descriptors, NavigationContent } = useNavigationBuilder<
88
- StackNavigationState<ParamListBase>,
89
- StackRouterOptions,
90
- StackActionHelpers<ParamListBase>,
91
- NativeStackNavigationOptions,
92
- NativeStackNavigationEventMap
93
- >(StackRouter, {
94
- id,
95
- initialRouteName,
96
- UNSTABLE_routeNamesChangeBehavior,
97
- children,
98
- layout,
99
- screenListeners,
100
- screenOptions,
101
- screenLayout,
102
- UNSTABLE_router,
103
- });
104
- const route = state.routes[state.index];
105
- return <NavigationContent>{route ? descriptors[route.key]?.render() : null}</NavigationContent>;
106
-}
107
-
108
-type PreviewTypeBag<ParamList extends ParamListBase> = Omit<
109
- NativeStackTypeBag<ParamList, undefined>,
110
- "Navigator"
111
-> & { Navigator: typeof PreviewRouteNavigator };
112
-function createPreviewRouteNavigator<
113
- const ParamList extends ParamListBase,
114
- const TypeBag extends NavigatorTypeBagBase = PreviewTypeBag<ParamList>,
115
- const Config extends StaticConfig<TypeBag> = StaticConfig<TypeBag>,
116
->(config?: Config): TypedNavigator<TypeBag, Config> {
117
- return createNavigatorFactory(PreviewRouteNavigator)(config);
118
-}
119
-
120
-const PreviewStack = createPreviewRouteNavigator<{
121
- Thread: { readonly environmentId: string; readonly threadId: string };
122
-}>();
123
-
46
/** A thread shown beside or over the workspace does not take the workspace's content width. */
47
export function InspectorContentScope({ children }: { readonly children: ReactNode }) {
48
return (
66
}) {
67
const navigation = useNavigation();
68
const focused = useIsFocused();
147
- const theme = useMobileNavigationTheme();
69
const { target } = props;
70
const maximizeDevice = (deviceKey: string | null) => {
71
props.onOpen({ ...target, deviceKey: deviceKey ?? undefined });
90
/>
91
) : (
92
<View className="flex-1 bg-screen">
172
- <NavigationIndependentTree>
173
- <NavigationContainer theme={theme} onUnhandledAction={navigation.dispatch}>
174
- <PreviewStack.Navigator key={`${target.environmentId}:${target.threadId}`}>
175
- <PreviewStack.Screen name="Thread" initialParams={target}>
176
- {(screen) =>
177
- props.renderThread({
178
- route: screen.route,
179
- inspectorPresentation: {
180
- onMaximize: () =>
181
- navigation.navigate("ThreadInspectorFullscreen", {
182
- environmentId: screen.route.params.environmentId,
183
- threadId: screen.route.params.threadId,
184
- }),
185
- },
186
- })
187
- }
188
- </PreviewStack.Screen>
189
- </PreviewStack.Navigator>
190
- </NavigationContainer>
191
- </NavigationIndependentTree>
93
+ <ThreadPreviewRoute environmentId={target.environmentId} threadId={target.threadId}>
94
+ {(route) =>
95
+ props.renderThread({
96
+ route,
97
+ inspectorPresentation: {
98
+ onMaximize: () =>
99
+ navigation.navigate("ThreadInspectorFullscreen", {
100
+ environmentId: route.params.environmentId,
101
+ threadId: route.params.threadId,
102
+ }),
103
+ },
104
+ })
105
+ }
106
+ </ThreadPreviewRoute>
107
</View>
108
)}
109
</InspectorContentScope>