From 421289156607320d9d351fb1f46f58d96f5657f9 Mon Sep 17 00:00:00 2001 From: Richard Lindhout Date: Sat, 23 Jul 2022 13:44:49 +0200 Subject: [PATCH] fix: forward refs --- src/AutocompleteFlatList.tsx | 2 +- src/AutocompleteScrollView.tsx | 2 +- src/createAutocompleteScrollable.tsx | 2 +- src/shared.tsx | 9 +++++++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/AutocompleteFlatList.tsx b/src/AutocompleteFlatList.tsx index 3ef35aa..5f44bf4 100644 --- a/src/AutocompleteFlatList.tsx +++ b/src/AutocompleteFlatList.tsx @@ -6,7 +6,7 @@ import { useScrollableProps } from './shared'; function AutocompleteFlatList(rest: FlatListProps, ref: any) { const { scrollableRef, scrollX, scrollY, scrollableProps } = - useScrollableProps(); + useScrollableProps(rest); const Flat = Animated.FlatList as any; return ( diff --git a/src/AutocompleteScrollView.tsx b/src/AutocompleteScrollView.tsx index 9266f6c..5ba99f8 100644 --- a/src/AutocompleteScrollView.tsx +++ b/src/AutocompleteScrollView.tsx @@ -6,7 +6,7 @@ import { useScrollableProps } from './shared'; function AutocompleteScrollView(rest: ScrollViewProps, ref: any) { const { scrollableRef, scrollX, scrollY, scrollableProps } = - useScrollableProps(); + useScrollableProps(rest); return ( diff --git a/src/createAutocompleteScrollable.tsx b/src/createAutocompleteScrollable.tsx index 0ef59ab..dfaef6e 100644 --- a/src/createAutocompleteScrollable.tsx +++ b/src/createAutocompleteScrollable.tsx @@ -7,7 +7,7 @@ export default function createAutocompleteScrollable< >(WrappedComponent: T): React.ComponentType { return React.forwardRef(function (rest, ref) { const { scrollableRef, scrollX, scrollY, scrollableProps } = - useScrollableProps(); + useScrollableProps(rest); const WW = WrappedComponent as any; return ( diff --git a/src/shared.tsx b/src/shared.tsx index 339b518..2fda9ff 100644 --- a/src/shared.tsx +++ b/src/shared.tsx @@ -3,7 +3,11 @@ import { useAnimatedScrollHandler, useSharedValue, } from 'react-native-reanimated'; -import type { NativeScrollEvent, NativeSyntheticEvent } from 'react-native'; +import type { + NativeScrollEvent, + NativeSyntheticEvent, + ScrollViewProps, +} from 'react-native'; export type AutocompleteScrollableProps = { ref?: any; @@ -19,7 +23,7 @@ export type AutocompleteScrollableProps = { | undefined; }; -export function useScrollableProps() { +export function useScrollableProps(props: ScrollViewProps) { const scrollableRef = useAnimatedRef(); const scrollX = useSharedValue(0); const scrollY = useSharedValue(0); @@ -27,6 +31,7 @@ export function useScrollableProps() { const { x, y } = e.contentOffset; scrollX.value = x; scrollY.value = y; + props?.onScroll?.(e as any); }); const scrollableProps: AutocompleteScrollableProps = { ref: scrollableRef,