React native 将本机ScrollView Scroll响应到spring动画
我正在使用React Native的React native 将本机ScrollView Scroll响应到spring动画,react-native,react-animated,react-native-scrollview,React Native,React Animated,React Native Scrollview,我正在使用React Native的ScrollView的scrollTo方法来设置滚动视图的动画。如何使此动画弹簧加载,如动画.spring(不使用第三方库)?跟踪滚动位置 <ScrollView ref={(ref) => { this.scrollView = ref; }} onScroll={(event) => { this.scrollY = event.nativeEvent.contentOffset.y; }}
ScrollView
的scrollTo
方法来设置滚动视图的动画。如何使此动画弹簧加载,如动画.spring
(不使用第三方库)?跟踪滚动位置
<ScrollView
ref={(ref) => { this.scrollView = ref; }}
onScroll={(event) => {
this.scrollY = event.nativeEvent.contentOffset.y;
}}
scrollEventThrottle={16}
>
scrollTo(y) {
if (!this.scrollY) this.scrollY = 0;
const animatedValue = new Animated.Value(this.scrollY);
const id = animatedValue.addListener(({ value }) => {
this.scrollView.scrollTo({ x: 0, y: value, animated: false });
});
Animated.spring(animatedValue, { toValue: y }).start(() => { animatedValue.removeListener(id); /* finished callback */ });
}