pager-view
Version:
A wrapper that works on multiple platforms: Android, iOS, and Web
19 lines (15 loc) • 459 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 };