Skip to content

Add imperative focus in SpatialNavigationVirtualizedGrid #166

@arthuruan

Description

@arthuruan

Is your feature request related to a problem? Please describe.
I'm trying to go back the focus to the header of SpatialNavigationVirtualizedGrid, but looks like from the third row I lose the reference of the component and I'm not able to do the imperative focus.

Describe the solution you'd like
I'd like to have I way to keep the header reference while scrolling down. Or even expose the SpatialNavigationVirtualizedList reference in the SpatialNavigationVirtualizedGrid component, would be very helpful. With that, I could scroll to the first grid item and then move the focus to the header. Like that:

 <SpatialNavigationVirtualizedGrid
      ref={virtualizedListRef}
      data={data}
      header={header}
      headerSize={headerSize}
      renderItem={renderItem}
      itemHeight={getItemHeight(itemAspectRatio)}
      numberOfColumns={NUMBER_OF_COLUMNS}
      onEndReachedThresholdRowsNumber={INFINITE_SCROLL_ROW_THRESHOLD}
      onEndReached={onEndReached}
      descendingArrowContainerStyle={styles.topArrowContainer}
      ascendingArrowContainerStyle={styles.bottomArrowContainer}
    />
 useRemoteControlKeys(
    [SupportedKeys.Back],
    useCallback(() => {
      if (isItemFocused) {
        virtualizedListRef.current?.focus(0);
        headerViewRef.current?.focus();
        return true;
      }

      return false;
    }, [isItemFocused]),
  );

Additional context

Screen.Recording.2024-11-06.at.11.28.34.mov

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions