gameflow-deck/src/mainview/components/AutoFocus.tsx
Simeon Radivoev 813785f4f3
feat: Bundled NW.js with appimages
feat: Implemented self update
feat: Added rclone saves for emulators
fix: Fixed auto focus in builds
feat: Added helper cards on empty library
2026-04-26 03:26:15 +03:00

39 lines
No EOL
1.1 KiB
TypeScript

import { doesFocusableExist, FocusDetails, getCurrentFocusKey } from "@noriginmedia/norigin-spatial-navigation";
import { useEffect, useLayoutEffect } from "react";
export function AutoFocus (data: {
parentKey?: string;
focus: (focusDetails?: FocusDetails | undefined) => void;
force?: boolean;
delay?: number;
})
{
useEffect(() =>
{
let delayTimeout: number | undefined;
const focusDoesntExist = !doesFocusableExist(getCurrentFocusKey());
const parentFocus = getCurrentFocusKey() === data.parentKey;
const noFocus = !getCurrentFocusKey();
if (data.force || noFocus || parentFocus || focusDoesntExist)
{
if (data.delay)
{
delayTimeout = window.setTimeout(() => data.focus({ instant: true }), data.delay);
} else
{
data.focus({ instant: true });
}
}
return () =>
{
if (delayTimeout)
{
window.clearTimeout(delayTimeout);
}
};
}, []);
return <></>;
}