How to change flatlist scroll animation duration in react native?
Asked Answered
R

0

6

I have a flatlist with a bunch of item in it now when I press the button the flatlist scrolls down using ref and scrollToIndex method. But the scroll animation is faster than what i need is there anyway to increase the scroll animation duration?

This is the code for scrollup (up swipe gesture) function

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

    }
}

This is jsx returned

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

Any help would be really appreciated, I have been working on the bug for past few day yet I did not manage to find any clear solution :(

Rufford answered 24/4, 2021 at 15:48 Comment(3)
I also tried to search on this a bit but seems there is no delay property or time property to control the animation speed.Mitch
yes thats the issue hereRufford
I am also not able to find any help for this issuePathe

© 2022 - 2024 — McMap. All rights reserved.