| ... | ... | @@ -1,4 +1,5 @@ |
| 1 | 1 | import { requireOptionalNativeModule } from "expo"; |
| 2 | import { useEffect, useState } from "react"; |
| 2 | 3 | import { Platform } from "react-native"; |
| 3 | 4 | import { useNativeLayoutMetrics } from "./native-layout-metrics"; |
| 4 | 5 | |
| ... | ... | @@ -9,15 +10,27 @@ const nativeControls = requireOptionalNativeModule<{ |
| 9 | 10 | export const NATIVE_WORKSPACE_COLUMNS_SUPPORTED = |
| 10 | 11 | Platform.OS === "ios" && Platform.isPad && nativeControls?.supportsWorkspaceColumns === true; |
| 11 | 12 | |
| 13 | // Binaries without the native no-hinge fallback never report metrics on ordinary |
| 14 | // iPhones running iOS 27.1 or later. Use the compact navigator rather than staying blank. |
| 15 | const NATIVE_METRICS_TIMEOUT_MS = 1000; |
| 16 | |
| 12 | 17 | export function useNativeWorkspaceColumnsReady() { |
| 13 | 18 | const metrics = useNativeLayoutMetrics(); |
| 19 | const [timedOut, setTimedOut] = useState(false); |
| 14 | 20 | // Choose the phone's native host before attaching any screens. Older clients |
| 15 | 21 | // without the observer can immediately use the compact navigator. |
| 16 | | return ( |
| 17 | | (Platform.OS === "ios" && Platform.isPad) || |
| 18 | | !nativeControls?.ViewPrototypes?.T3NativeControls_LayoutMetrics || |
| 19 | | metrics !== null |
| 20 | | ); |
| 22 | const waiting = |
| 23 | !(Platform.OS === "ios" && Platform.isPad) && |
| 24 | !!nativeControls?.ViewPrototypes?.T3NativeControls_LayoutMetrics && |
| 25 | metrics === null; |
| 26 | |
| 27 | useEffect(() => { |
| 28 | if (!waiting) return; |
| 29 | const timeout = setTimeout(() => setTimedOut(true), NATIVE_METRICS_TIMEOUT_MS); |
| 30 | return () => clearTimeout(timeout); |
| 31 | }, [waiting]); |
| 32 | |
| 33 | return !waiting || timedOut; |
| 21 | 34 | } |
| 22 | 35 | |
| 23 | 36 | export function useNativeWorkspaceColumnsSupported() { |