pager-view
Version:
A wrapper that works on multiple platforms: Android, iOS, and Web
15 lines (11 loc) • 440 B
text/typescript
import { useCallback, type ForwardedRef } from "react";
import type { Animated, View } from "react-native";
type UseScrollRef = ForwardedRef<Animated.FlatList<View>>;
const useScroll = (ref: UseScrollRef, width: number) =>
useCallback(
(index: number) => {
if ("current" in ref && ref.current) ref.current.scrollToOffset({ animated: true, offset: index * width });
},
[ref, width],
);
export { useScroll, type UseScrollRef };