import { Platform } from 'react-native'; import { useEffect } from 'react'; type FocusableRef = { focus?: () => void; requestTVFocus?: () => void; }; export function useTVPreferredFocus( ref: React.RefObject, enabled: boolean, ): void { useEffect(() => { if (!enabled) { return; } const timer = setTimeout(() => { if (typeof ref.current?.requestTVFocus === 'function') { ref.current.requestTVFocus(); return; } if (Platform.isTV) { return; } ref.current?.focus?.(); }, 0); return () => clearTimeout(timer); }, [enabled, ref]); }