-
-
Notifications
You must be signed in to change notification settings - Fork 6
Add reacquireOnPageVisible functionality #279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add reacquireOnPageVisible functionality #279
Conversation
- Implement `reacquireOnPageVisible` option in the hook - Add tests to verify `reacquireOnPageVisible` functionality - Solves issue jorisre#273
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Added documentation and updated the usage example
jorisre
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGMT! Thanks for the contribution!
|
🎉 This PR is included in version 3.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
| React.useEffect(() => { | ||
| if (reacquireOnPageVisible) { | ||
| const handleVisibilityChange = async () => { | ||
| if (wakeLock.current && document.visibilityState === 'visible') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Deftera186 @jorisre hey folks, I might be missing something here, but shouldn't this check for if (wakeLock.current === null && document.visibilityState === 'visible') instead?
Navigating away from the page triggers wakeLock.current.onrelease, which then sets wakeLock.current = null.
Returning to the page then should check for wakeLock.current === null, before attempting to reacquire the lock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch
reacquireOnPageVisibleoption in the hookreacquireOnPageVisiblefunctionality