react-insta-stories icon indicating copy to clipboard operation
react-insta-stories copied to clipboard

Story timing speeds up

Open hannadrehman opened this issue 5 years ago • 1 comments

story timing is increasing randomly and sometimes skips the slide.

one way to reproduce it

let the slide complete. click previous and keep doing it . after some time you will notice the slide speed will increase.

while going into the sourcecode found the reason what is causing the speed up

const incrementCount = () => {
        setCount((count: number) => {
            if (count === 0) storyStartCallback()
            const interval = getCurrentInterval()
            if (count < 100) {
                animationFrameId.current = requestAnimationFrame(incrementCount)
            } else {
                storyEndCallback()
                if (currentId === stories.length - 1) {
                    allStoriesEndCallback()
                }
                next()
            }
            return count + (100 / ((interval / 1000) * 60))
        })
    }

i am not sure why but the incrementCount frequency increases drastically after you click on previous slide anchor.

for slides getting skipped

const updateNextStoryId = () => {
        if (currentId < stories.length - 1) {
            setCurrentId(currentId + 1) // you should use   setCurrentId(prevCurrentId=>prevCurrentId + 1)
            setCount(0)
        }
    }
   const previous = () => {
        if (currentId > 0) {
            setCurrentId(currentId - 1) // setCurrentId(prevCurrentId=>prevCurrentId - 1)
            setCount(0)
        }
    }

hannadrehman avatar Dec 18 '19 07:12 hannadrehman

Hey, thanks for reporting this. I have made relevant changes, it was the wrong placement of requestAnimationFrame causing the issue. I've also made the changes you mentioned, they surely are the right way to update previous values! requestAnimationFrame fix: https://github.com/mohitk05/react-insta-stories/pull/62/commits/5da79968af4bb5bbf230f0072f4e610c17bcdc69 https://github.com/mohitk05/react-insta-stories/pull/62/commits/2bec1b026ec48524c27846eb428e04046a7c668e

mohitk05 avatar Feb 16 '20 08:02 mohitk05

Fixed in #263.

mohitk05 avatar Mar 31 '23 06:03 mohitk05