import * as React from "react";
import { StyleSheet } from "react-native";
import { shallow } from "zustand/shallow";
import { FocusableGroup } from "../../FocusableGroup";
import {
useContentId,
useNavbarId,
usePathname,
} from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
import { useZappHookModalStore } from "../../../Contexts/ZappHookModalContext";
import { useInitialFocus } from "../../Screen/TV/hooks";
const styles = StyleSheet.create({
container: { flex: 1 },
});
type Props = {
children: React.ReactElement;
};
/**
* A general content screen presented as a full-screen hook is rendered straight
* through `ComponentsMap`, bypassing the web `River` wrapper. That wrapper is what
* normally creates the `quick-brick-content` FocusableGroup (with `preferredFocus`)
* the focus manager relies on and what lets initial focus land on the content.
*
* Without it the hook screen renders but nothing is focusable on web TV. This
* recreates that content group and triggers initial focus, mirroring `River`.
*/
const FocusedHookContent = ({ children }: Props) => {
const contentId = useContentId();
const navbarId = useNavbarId();
const pathname = usePathname();
useInitialFocus();
return (
{React.cloneElement(children, { groupId: contentId })}
);
};
export const HookContentFocusGroup = ({ children }: Props) => {
const isRunningInBackground = useZappHookModalStore(
(state) => state.isRunningInBackground,
shallow
);
// A hook presented full screen (either as a `/hooks/` screen or a
// full-screen modal) needs the content focus group. Only background runs,
// which render invisibly, must be left alone so they don't steal focus.
if (isRunningInBackground) {
return <>{children}>;
}
return {children};
};