Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {FlashList} from '@shopify/flash-list';
import React, {useCallback} from 'react';
import Animated from 'react-native-reanimated';
import type {SearchListItem} from '@components/SelectionListWithSections/types';
import type BaseSearchListProps from './types';
import type {SearchListDataItem} from './types';

const AnimatedFlashListComponent = Animated.createAnimatedComponent(FlashList<SearchListItem>);
const AnimatedFlashListComponent = Animated.createAnimatedComponent(FlashList<SearchListDataItem>);

function BaseSearchList({
data,
Expand All @@ -20,7 +20,7 @@ function BaseSearchList({
contentContainerStyle,
}: BaseSearchListProps) {
const renderItemWithoutKeyboardFocus = useCallback(
({item, index}: {item: SearchListItem; index: number}) => {
({item, index}: {item: SearchListDataItem; index: number}) => {
return renderItem(item, index, false, undefined);
},
[renderItem],
Expand Down
7 changes: 4 additions & 3 deletions src/components/Search/SearchList/BaseSearchList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import {FlashList} from '@shopify/flash-list';
import React, {useCallback, useEffect, useMemo, useRef} from 'react';
import type {NativeSyntheticEvent} from 'react-native';
import Animated from 'react-native-reanimated';
import type {ExtendedTargetedEvent, SearchListItem} from '@components/SelectionListWithSections/types';
import type {ExtendedTargetedEvent} from '@components/SelectionListWithSections/types';
import useArrowKeyFocusManager from '@hooks/useArrowKeyFocusManager';
import useKeyboardShortcut from '@hooks/useKeyboardShortcut';
import {isMobileChrome} from '@libs/Browser';
import {addKeyDownPressListener, removeKeyDownPressListener} from '@libs/KeyboardShortcut/KeyDownPressListener';
import CONST from '@src/CONST';
import type BaseSearchListProps from './types';
import type {SearchListDataItem} from './types';

const AnimatedFlashListComponent = Animated.createAnimatedComponent(FlashList<SearchListItem>);
const AnimatedFlashListComponent = Animated.createAnimatedComponent(FlashList<SearchListDataItem>);

function BaseSearchList({
data,
Expand Down Expand Up @@ -58,7 +59,7 @@ function BaseSearchList({
});

const renderItemWithKeyboardFocus = useCallback(
({item, index}: {item: SearchListItem; index: number}) => {
({item, index}: {item: SearchListDataItem; index: number}) => {
const isItemFocused = focusedIndex === index;

const onFocus = (event: NativeSyntheticEvent<ExtendedTargetedEvent>) => {
Expand Down
18 changes: 10 additions & 8 deletions src/components/Search/SearchList/BaseSearchList/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import type {FlashListProps, FlashListRef} from '@shopify/flash-list';
import type {ForwardedRef} from 'react';
import type {NativeSyntheticEvent} from 'react-native';
import type {SearchColumnType, SelectedTransactions} from '@components/Search/types';
import type {SearchColumnType, SearchListItemDescriptor, SelectedTransactions} from '@components/Search/types';
import type {ExtendedTargetedEvent, SearchListItem} from '@components/SelectionListWithSections/types';
import type {Transaction} from '@src/types/onyx';

export type SearchListDataItem = SearchListItem | SearchListItemDescriptor;

type BaseSearchListProps = Pick<
FlashListProps<SearchListItem>,
FlashListProps<SearchListDataItem>,
| 'onScroll'
| 'contentContainerStyle'
| 'onEndReached'
Expand All @@ -17,11 +19,11 @@ type BaseSearchListProps = Pick<
| 'showsVerticalScrollIndicator'
| 'onLayout'
> & {
/** The data to display in the list */
data: SearchListItem[];
/** The data to display in the list (full items or descriptors when using useSearchListItem) */
data: SearchListDataItem[];

/** The function to render each item in the list */
renderItem: (item: SearchListItem, index: number, isItemFocused: boolean, onFocus?: (event: NativeSyntheticEvent<ExtendedTargetedEvent>) => void) => React.JSX.Element;
renderItem: (item: SearchListDataItem, index: number, isItemFocused: boolean, onFocus?: (event: NativeSyntheticEvent<ExtendedTargetedEvent>) => void) => React.JSX.Element;

/** The columns that might change to trigger re-render via extraData */
columns: SearchColumnType[];
Expand All @@ -32,11 +34,11 @@ type BaseSearchListProps = Pick<
/** The length of the flattened items in the list */
flattenedItemsLength: number;

/** The callback, which is run when a row is pressed */
onSelectRow: (item: SearchListItem) => void;
/** The callback, which is run when a row is pressed (receives item or descriptor when using descriptor flow) */
onSelectRow: (item: SearchListDataItem) => void;

/** The ref to the list */
ref: ForwardedRef<FlashListRef<SearchListItem>>;
ref: ForwardedRef<FlashListRef<SearchListDataItem>>;

/** The function to scroll to an index */
scrollToIndex?: (index: number, animated?: boolean) => void;
Expand Down
Loading
Loading