Skip to content

Commit d143fb8

Browse files
authored
SortableList ref prop (#2948)
* Added forwarding ref to the inner flat list of SortableList * Changed ref to be a prop * Moved ref to original prop type * removed extra lines * Changed ref prop name
1 parent d0195c5 commit d143fb8

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/components/sortableList/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function generateLockedIds<ItemT extends SortableListItemProps>(data: SortableLi
2626

2727
const SortableList = <ItemT extends SortableListItemProps>(props: SortableListProps<ItemT>) => {
2828
const themeProps = useThemeProps(props, 'SortableList');
29-
const {data, onOrderChange, enableHaptic, scale, itemProps, horizontal, ...others} = themeProps;
29+
const {data, onOrderChange, enableHaptic, scale, itemProps, horizontal, listRef, ...others} = themeProps;
3030

3131
const itemsOrder = useSharedValue<string[]>(generateItemsOrder(data));
3232
const lockedIds = useSharedValue<Dictionary<boolean>>(generateLockedIds(data));
@@ -75,12 +75,12 @@ const SortableList = <ItemT extends SortableListItemProps>(props: SortableListPr
7575
scale
7676
};
7777
}, [data]);
78-
7978
return (
8079
<GestureHandlerRootView>
8180
<SortableListContext.Provider value={context}>
8281
<FlatList
8382
{...others}
83+
ref={listRef}
8484
horizontal={horizontal}
8585
data={data}
8686
CellRendererComponent={SortableListItem}

src/components/sortableList/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import {FlatListProps} from 'react-native';
1+
import {ForwardedRef} from 'react';
2+
import {FlatListProps, FlatList} from 'react-native';
23
import {SortableListContextType} from './SortableListContext';
34

45
export interface SortableListItemProps {
@@ -30,4 +31,8 @@ export interface SortableListProps<ItemT extends SortableListItemProps>
3031
* Extra props for the item
3132
*/
3233
itemProps?: {margins?: {marginTop?: number; marginBottom?: number; marginLeft?: number; marginRight?: number}};
34+
/**
35+
* List forwarded ref.
36+
*/
37+
listRef?: ForwardedRef<FlatList<ItemT>>
3338
}

0 commit comments

Comments
 (0)