The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { HeaderHeightContext } from "@react-navigation/elements"; |
| 2 | import { use, useState, type ReactNode } from "react"; |
| 3 | import { View, type ColorValue } from "react-native"; |
| 4 | import { SafeAreaProvider, SafeAreaView } from "react-native-safe-area-context"; |
| 5 | import { NativeColumnLayoutMetricsContext } from "./native-layout-metrics"; |
| 6 | import type { NativeLayoutMetrics } from "../lib/reserved-regions"; |
| 7 | import { NativeLayoutObserver } from "./NativeLayoutObserver"; |
| 8 | import { |
| 9 | NativeWorkspaceTabActivityContext, |
| 10 | WorkspaceColumnMetricsContext, |
| 11 | } from "./v5-workspace-context"; |
| 12 | |
| 13 | export function NativeColumnContent(props: { |
| 14 | readonly children: ReactNode; |
| 15 | readonly primary?: boolean; |
| 16 | readonly insetHorizontally?: boolean; |
| 17 | readonly backgroundColor?: ColorValue; |
| 18 | /** Shares this column's metrics across workspace tabs; see `WorkspaceColumnMetricsContext`. */ |
| 19 | readonly column?: string; |
| 20 | }) { |
| 21 | const tabActivity = use(NativeWorkspaceTabActivityContext); |
| 22 | const shared = use(WorkspaceColumnMetricsContext); |
| 23 | const [measured, setMeasured] = useState<NativeLayoutMetrics | null>(null); |
| 24 | const onMetrics = (next: NativeLayoutMetrics) => { |
| 25 | // A hidden tab's insets lack the bars UIKit lays out only for the selected tab. |
| 26 | if (tabActivity && !tabActivity.isActive()) return; |
| 27 | setMeasured(next); |
| 28 | if (props.column !== undefined) shared?.publish(props.column, next); |
| 29 | }; |
| 30 | const metrics = |
| 31 | measured ?? (props.column === undefined ? null : (shared?.byColumn.get(props.column) ?? null)); |
| 32 | return ( |
| 33 | <View |
| 34 | className={props.primary ? "flex-1 bg-drawer" : "flex-1 bg-screen"} |
| 35 | style={ |
| 36 | props.backgroundColor === undefined ? undefined : { backgroundColor: props.backgroundColor } |
| 37 | } |
| 38 | > |
| 39 | <SafeAreaProvider style={{ flex: 1 }}> |
| 40 | <SafeAreaView |
| 41 | edges={props.insetHorizontally === false ? [] : ["left", "right"]} |
| 42 | style={{ flex: 1 }} |
| 43 | > |
| 44 | {/* Observe the inset body. UIKit can reserve other columns in its safe area. */} |
| 45 | <View style={{ flex: 1 }}> |
| 46 | <NativeLayoutObserver onChange={onMetrics} /> |
| 47 | <NativeColumnLayoutMetricsContext value={metrics}> |
| 48 | <HeaderHeightContext value={metrics?.safeArea.top ?? undefined}> |
| 49 | {props.children} |
| 50 | </HeaderHeightContext> |
| 51 | </NativeColumnLayoutMetricsContext> |
| 52 | </View> |
| 53 | </SafeAreaView> |
| 54 | </SafeAreaProvider> |
| 55 | </View> |
| 56 | ); |
| 57 | } |