Repository navigation
Expand file tree
/
Copy pathinspector-host.tsx
More file actions
127 lines (121 loc) · 4.19 KB
/
Copy pathinspector-host.tsx
File metadata and controls
127 lines (121 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { useGT } from "gt-react-native";
import { useSyncExternalStore, type ReactNode } from "react";
import { Split, Stack } from "react-native-screens";
import { RenderErrorBoundary, RenderFailureView } from "../../components/RenderErrorBoundary";
import { PaneContext } from "../../components/ui/Pane";
import { GLASS_HEADER_OPTIONS } from "../../native/glass-header-options";
import { NativeColumnContent } from "../../native/NativeColumnContent.ios";
import { V5StackHeader } from "../../native/V5StackHeader.ios";
import { WorkspaceSlotOptionsContext } from "../../native/v5-workspace-context";
import {
InspectorCloseContext,
useInspectorBarSlot,
type InspectorBarStore,
} from "./inspector-bar-store";
import {
useMountedInspectorPanes,
type InspectorContent,
type InspectorPane,
} from "./inspector-panes";
// A pane without an AppBar has no bar; one with it gets the glass the workspace's screens get.
const PANE_HEADER_OPTIONS = { ...GLASS_HEADER_OPTIONS, headerShown: false };
function PaneHeader(props: { readonly store: InspectorBarStore }) {
const options = useSyncExternalStore(props.store.subscribe, props.store.getSnapshot);
// Its own search identity, so opening the inspector doesn't morph the sidebar's search into it.
return (
<V5StackHeader
options={{ ...PANE_HEADER_OPTIONS, ...options }}
canGoBack={false}
searchIdentifier="inspector-search"
/>
);
}
function PaneScreenContent(props: {
readonly pane: InspectorPane;
readonly resetKeys: ReadonlyArray<unknown> | undefined;
readonly onClose: () => void;
}) {
const gt = useGT();
const { store, slot } = useInspectorBarSlot();
const content = (
<WorkspaceSlotOptionsContext value={slot}>
<RenderErrorBoundary
resetKeys={props.resetKeys}
renderFallback={(fallback) => (
<RenderFailureView {...fallback} title={gt("The inspector couldn't be displayed")} />
)}
>
{props.pane.render()}
</RenderErrorBoundary>
</WorkspaceSlotOptionsContext>
);
return (
<InspectorCloseContext value={props.onClose}>
<PaneContext value="inspector">
<PaneHeader store={store} />
<NativeColumnContent>{content}</NativeColumnContent>
</PaneContext>
</InspectorCloseContext>
);
}
/**
* The inspector column's panes, each a screen of its stack like the detail column's routes.
* Only the active one is attached, so UIKit sees one bar, one toolbar and one scroll view.
* The inspector stays mounted without panes: Split.Host recreates its columns when it appears.
*/
export function InspectorColumnScreens(props: {
readonly content: InspectorContent | undefined;
readonly onClose: () => void;
/** Drawn over the active pane. */
readonly overlay?: ReactNode;
}) {
const panes = useMountedInspectorPanes(props.content);
return (
<Split.Inspector>
<Stack.Host>
{panes.map((pane) => {
const active = pane.key === props.content?.active;
return (
<Stack.Screen
key={pane.key}
screenKey={`inspector:${pane.key}`}
activityMode={active ? "attached" : "detached"}
>
<PaneScreenContent
pane={pane}
resetKeys={props.content?.resetKeys}
onClose={props.onClose}
/>
{active ? props.overlay : null}
</Stack.Screen>
);
})}
</Stack.Host>
</Split.Inspector>
);
}
/** The inspector's panes where it has no column: a native stack with the active one attached. */
export function InspectorPanes(props: {
readonly content: InspectorContent | undefined;
readonly onClose: () => void;
}) {
const panes = useMountedInspectorPanes(props.content);
if (panes.length === 0) return null;
return (
<Stack.Host>
{panes.map((pane) => (
<Stack.Screen
key={pane.key}
screenKey={`inspector:${pane.key}`}
activityMode={pane.key === props.content?.active ? "attached" : "detached"}
>
<PaneScreenContent
pane={pane}
resetKeys={props.content?.resetKeys}
onClose={props.onClose}
/>
</Stack.Screen>
))}
</Stack.Host>
);
}