Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 将本机ScrollView Scroll响应到spring动画_React Native_React Animated_React Native Scrollview - Fatal编程技术网

React native 将本机ScrollView Scroll响应到spring动画

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; }}

我正在使用React Native的
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 */ });
}