react-native-reanimated
Version:
More powerful alternative to Animated library for React Native.
22 lines (18 loc) • 579 B
text/typescript
import type { Component } from 'react';
import type { ScrollView } from 'react-native';
import type { AnimatedRef } from '../hook/commonTypes';
export function scrollTo<T extends Component>(
animatedRef: AnimatedRef<T>,
x: number,
y: number,
animated: boolean
) {
const element = animatedRef();
// This prevents crashes if ref has not been set yet
if (element !== -1) {
// By ScrollView we mean any scrollable component
const scrollView = element as HTMLElement as unknown as ScrollView;
scrollView?.scrollTo({ x, y, animated });
}
}
;