The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | import { requireOptionalNativeModule } from "expo"; |
| 2 | import { Platform } from "react-native"; |
| 3 | import { useDeadlinePassed } from "../lib/clock"; |
| 4 | import type { NativeLayoutMetrics } from "../lib/reserved-regions"; |
| 5 | import { useNativeLayoutMetrics, useNativeLayoutMetricsDeadline } from "./native-layout-metrics"; |
| 6 | |
| 7 | export { NATIVE_METRICS_TIMEOUT_MS } from "./native-layout-metrics"; |
| 8 | |
| 9 | const nativeControls = requireOptionalNativeModule<{ |
| 10 | readonly supportsWorkspaceColumns?: boolean; |
| 11 | readonly ViewPrototypes?: { readonly T3NativeControls_LayoutMetrics?: unknown }; |
| 12 | }>("T3NativeControls"); |
| 13 | export const NATIVE_WORKSPACE_COLUMNS_SUPPORTED = |
| 14 | Platform.OS === "ios" && Platform.isPad && nativeControls?.supportsWorkspaceColumns === true; |
| 15 | |
| 16 | /** Whether a window with these metrics lays the workspace out in UIKit columns. */ |
| 17 | export function nativeWorkspaceColumnsSupportedFor(metrics: NativeLayoutMetrics | null) { |
| 18 | return ( |
| 19 | NATIVE_WORKSPACE_COLUMNS_SUPPORTED || |
| 20 | (nativeControls?.supportsWorkspaceColumns === true && metrics?.hasHinge === true) |
| 21 | ); |
| 22 | } |
| 23 | |
| 24 | export function useNativeWorkspaceColumnsReady() { |
| 25 | const metrics = useNativeLayoutMetrics(); |
| 26 | const metricsDeadline = useNativeLayoutMetricsDeadline(); |
| 27 | const waiting = |
| 28 | !(Platform.OS === "ios" && Platform.isPad) && |
| 29 | !!nativeControls?.ViewPrototypes?.T3NativeControls_LayoutMetrics && |
| 30 | metrics === null; |
| 31 | // Without metrics by the deadline, use the compact navigator rather than staying blank. |
| 32 | const timedOut = useDeadlinePassed(waiting ? metricsDeadline : null); |
| 33 | return !waiting || timedOut; |
| 34 | } |
| 35 | |
| 36 | export function useNativeWorkspaceColumnsSupported() { |
| 37 | return nativeWorkspaceColumnsSupportedFor(useNativeLayoutMetrics()); |
| 38 | } |