| ... | @@ -1,4 +1,5 @@ | ... | @@ -1,4 +1,5 @@ |
| 1 | import { requireOptionalNativeModule } from "expo"; | 1 | import { requireOptionalNativeModule } from "expo"; |
| | 2 | import { useEffect, useState } from "react"; |
| 2 | import { Platform } from "react-native"; | 3 | import { Platform } from "react-native"; |
| 3 | import { useNativeLayoutMetrics } from "./native-layout-metrics"; | 4 | import { useNativeLayoutMetrics } from "./native-layout-metrics"; |
| 4 | | 5 | |
| ... | @@ -9,15 +10,27 @@ const nativeControls = requireOptionalNativeModule<{ | ... | @@ -9,15 +10,27 @@ const nativeControls = requireOptionalNativeModule<{ |
| 9 | export const NATIVE_WORKSPACE_COLUMNS_SUPPORTED = | 10 | export const NATIVE_WORKSPACE_COLUMNS_SUPPORTED = |
| 10 | Platform.OS === "ios" && Platform.isPad && nativeControls?.supportsWorkspaceColumns === true; | 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 | export function useNativeWorkspaceColumnsReady() { | 17 | export function useNativeWorkspaceColumnsReady() { |
| 13 | const metrics = useNativeLayoutMetrics(); | 18 | const metrics = useNativeLayoutMetrics(); |
| | 19 | const [timedOut, setTimedOut] = useState(false); |
| 14 | // Choose the phone's native host before attaching any screens. Older clients | 20 | // Choose the phone's native host before attaching any screens. Older clients |
| 15 | // without the observer can immediately use the compact navigator. | 21 | // without the observer can immediately use the compact navigator. |
| 16 | return ( | 22 | const waiting = |
| 17 | (Platform.OS === "ios" && Platform.isPad) || | 23 | !(Platform.OS === "ios" && Platform.isPad) && |
| 18 | !nativeControls?.ViewPrototypes?.T3NativeControls_LayoutMetrics || | 24 | !!nativeControls?.ViewPrototypes?.T3NativeControls_LayoutMetrics && |
| 19 | metrics !== null | 25 | metrics === null; |
| 20 | ); | 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 | export function useNativeWorkspaceColumnsSupported() { | 36 | export function useNativeWorkspaceColumnsSupported() { |