2

我现在有一个包含一堆项目的平面列表,当我按下按钮时,平面列表使用 ref 和 scrollToIndex 方法向下滚动。但是滚动动画比我需要的要快,无论如何增加滚动动画的持续时间?

这是向上滚动(向上滑动手势)功能的代码

const scrollUp = () => {
    console.log("Up Gesture", currentIndex);
    if (currentIndex <= DATA.length - 1) {
        if (currentIndex != DATA.length - 1) {
            flatlistRef.current.scrollToIndex({
                index: currentIndex + 1,
                animated: true,
                viewOffset: 200,

            });
            setCurrentIndex(currentIndex + 1);
        }

    }
}

这是返回的 jsx

return (
    <>
        <StatusBar hidden={true} />
        <Button title="click me" style={{ position: 'absolute', zIndex: 20, top: 20, }} onPress={() => scrollUp()} />
        <AnimatedFlatList
            {...{ onScroll, ListFooterComponent, ListHeaderComponent, onScrollEndDrag }}
            ref={flatlistRef}
            overScrollMode='never'
            // scrollEnabled={false}
            scrollEventThrottle={1}
            data={DATA}
            style={{ width: WINDOW_WIDTH, height: WINDOW_HEIGHT, backgroundColor: 'black' }}
            keyExtractor={(item, index) => index.toString()}
            renderItem={({ item, index }) => {
                return <SinglePost aspectRatio={item.aspectRatio} uri={item.imgUrl} y={y} index={index} />
            }}
        />
    </>
);

任何帮助将不胜感激,过去几天我一直在研究这个错误,但我没有找到任何明确的解决方案:(

4

0 回答 0