goncy / react-swipy

A simple Tinder-like swipeable React component
MIT License
27 stars 19 forks source link

Automatic swiping not possible when the page containing react-swipy is not the current Active Tab #4

Closed sharad-s closed 5 years ago

sharad-s commented 5 years ago

My implementation of react-swipy requires that the song will swipe on its own after a set interval of time.

This works great when the tab is active in the browser, however when the tab is inactive the Swipe will fail.

I have replicated this behavior in the following codepen fork: https://codesandbox.io/s/react-swipe-cards-wplqd

You will notice that the Cards will swipe every 1s while the tab is active, however will pause swiping when the tab is inactive - and resume once the tab is active again.

Any thoughts on how to fix this within the source?

goncy commented 5 years ago

This is related to how browsers handle javascript code execution in inactive tabs, probably you can use requestAnimationFrame, you can see more on this issue https://stackoverflow.com/questions/5927284/how-can-i-make-setinterval-also-work-when-a-tab-is-inactive-in-chrome