Skip to content

Commit 75e7e25

Browse files
committed
forward ref
1 parent 7efc322 commit 75e7e25

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/components/NestableDraggableFlatList.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ import { DraggableFlatListProps } from "../types";
55
import DraggableFlatList from "../components/DraggableFlatList";
66
import { useNestableScrollContainerContext } from "../context/nestableScrollContainerContext";
77
import { useNestedAutoScroll } from "../hooks/useNestedAutoScroll";
8+
import { FlatList } from "react-native-gesture-handler";
89

9-
export function NestableDraggableFlatList<T>(props: DraggableFlatListProps<T>) {
10+
export function NestableDraggableFlatListInner<T>(
11+
props: DraggableFlatListProps<T>,
12+
ref?: React.ForwardedRef<FlatList<T>>
13+
) {
1014
const hasSuppressedWarnings = useRef(false);
1115

1216
if (!hasSuppressedWarnings.current) {
@@ -47,6 +51,7 @@ export function NestableDraggableFlatList<T>(props: DraggableFlatListProps<T>) {
4751
return (
4852
<Animated.View ref={viewRef} onLayout={onListContainerLayout}>
4953
<DraggableFlatList
54+
ref={ref}
5055
activationDistance={20}
5156
autoscrollSpeed={50}
5257
scrollEnabled={false}
@@ -71,3 +76,11 @@ export function NestableDraggableFlatList<T>(props: DraggableFlatListProps<T>) {
7176
</Animated.View>
7277
);
7378
}
79+
80+
// Generic forwarded ref type assertion taken from:
81+
// https://fettblog.eu/typescript-react-generic-forward-refs/#option-1%3A-type-assertion
82+
export const NestableDraggableFlatList = React.forwardRef(
83+
NestableDraggableFlatListInner
84+
) as <T>(
85+
props: DraggableFlatListProps<T> & { ref?: React.ForwardedRef<FlatList<T>> }
86+
) => ReturnType<typeof NestableDraggableFlatListInner>;

0 commit comments

Comments
 (0)