diff --git a/src/components/AutoScrollScrollView.tsx b/src/components/AutoScrollScrollView.tsx index 00d3c34..08509d6 100644 --- a/src/components/AutoScrollScrollView.tsx +++ b/src/components/AutoScrollScrollView.tsx @@ -35,13 +35,13 @@ export interface ScrollAnimInfo { export function AutoScrollScrollView( props: Omit, 'ref'> & { - innerRef?: AnimatedRef; + innerRef?: ((ref: Animated.ScrollView) => void) | AnimatedRef; manualActivate?: boolean; manualScrollBy?: AutoScrollBy; } ) { const { - innerRef, + innerRef: innerRefProps, horizontal: horizontalProps, manualActivate, manualScrollBy, @@ -62,6 +62,8 @@ export function AutoScrollScrollView( const scrollAnimInfo = useSharedValue(null); const animatedRef = useAnimatedRef(); + const innerRef = typeof innerRefProps === 'function' && 'current' in innerRefProps ? innerRefProps : void 0 + const innerRefFn = typeof innerRefProps === 'function' && !('current' in innerRefProps) ? innerRefProps : void 0 const scrollRef = innerRef ?? animatedRef; const scrollHandler = useScrollViewOffset(scrollRef); const scrollSize = useSharedValue(0); @@ -70,6 +72,11 @@ export function AutoScrollScrollView( height: 0, }); + const onRef = useCallback((ref: Animated.ScrollView) => { + innerRefFn?.(ref) + scrollRef.current = ref + }, [innerRefFn, scrollRef]) + const needScroll = useCallback( (scrollBy) => { 'worklet'; @@ -258,7 +265,7 @@ export function AutoScrollScrollView( { scrollSize.value = nativeEvent.layout.height;