import * as React from "react"; import { BaseFocusable } from "../BaseFocusable"; import { FocusableGroupContextProvider } from "../../Contexts/FocusableGroupContext"; import { withFocusableContext } from "../../Contexts/FocusableGroupContext/withFocusableContext"; type Props = { testID?: string; shouldUsePreferredFocus?: boolean; id: string; node?: Record; children: any; preferredFocus?: boolean; isWithMemory?: boolean; style?: Record; prioritiseFocusOn?: number; groupId?: string; hasTVPreferredFocus?: boolean; onFocus?: () => void; onBlur?: () => void; willReceiveFocus?: (event?: any) => void; hasLostFocus?: any; nextFocusUp?: any; nextFocusDown?: any; nextFocusLeft?: any; nextFocusRight?: any; onLayout?: any; excludeFromFocusSearching?: boolean; }; class FocusableGroup extends BaseFocusable { constructor(props) { super(props); this.isGroup = true; this.shouldUsePreferredFocus = this.shouldUsePreferredFocus.bind(this); this.isPreferredFocus = this.isPreferredFocus.bind(this); this.isWithMemory = this.isWithMemory.bind(this); } getId() { const { id } = this.props; return id; } /** * tells whether the group should give focus to a preferred item when it gains focus from another * group * @returns {boolean} */ shouldUsePreferredFocus() { return this.props.shouldUsePreferredFocus || false; } /** * indicates whether the underlying component should claim preferred focus * when navigating into the group of this item * @returns {boolean} */ isPreferredFocus() { return this.props.preferredFocus || false; } /** * indicates whether the Group should remember last focused item * or focus on preferredFocus * @returns {boolean} */ isWithMemory() { return this.props.isWithMemory ?? true; } render() { const { children, id, style } = this.props; const focusableId = `focusable-group-${id}`; return (
{children}
); } } const FocusableGroupWithFocusableContext = withFocusableContext(FocusableGroup); export { FocusableGroupWithFocusableContext as FocusableGroup };