react-screen-wake-lock
react-screen-wake-lock copied to clipboard
Feature Request: Re-Aquire Wakelock When User Returns to Page
I tried to do a pull request but got hit with a bunch of errors so I'll just drop the updated files here.
There are some instances where you would want to release WakeLock without nullifying the sentinel entirely, for example a user requests WakeLock, then navigates to a different tab or application, then returns. The best UX is to automatically re-acquire the WakeLock rather than force the user to manually request it again.
I recommend adding a destroy() function that nullifies the WakeLock when manually called, and then release() simply sets the WakeLock sentinel's released parameter to true while keeping the sentinel active so it can be re-acquired if necessary.
I've also added a visibilitychange event listener on request() to listen for visibility being re-acquired and re-request WakeLock if the sentinel is active.
Thank you for submitting your feature request; I'll review it shortly :)
Hi! Thank you for your feedback, I've just taken the time to review your request. I understand your need, but this module is intended to adhere to the native functionality of the Screen WakeLock described here: https://w3c.github.io/screen-wake-lock/
You can fork this repo to add your features. Have a great day :)
No problem, thanks for looking! The 'watch/re-aquire' technique is recommended in the MDN docs but I understand it's not explicitly native functionality.
@jorisre just want to give another voice to this feature, so users don’t need to actively remember to activate wakelock every time they switch back and forth between apps.
thanks for putting together this highly useful lib!
@loa, thanks for your feedback.
@kmgdevelopment, thank you for your feedback as well. I hadn't noticed the re-acquire/watch section in the MDN link.
Following your feedback and after some consideration, I believe it's feasible to implement your feature request without interfering with the native behavior of the Screen Wake Lock. I've started testing locally, and I'm envisioning an option like reacquireOnPageVisible: boolean or something similar.
What do you think?
Making it an optional parameter is a great idea, as I could see possible use cases where someone wouldn't want that functionality by default
did this get merged/added?
:tada: This issue has been resolved in version 3.1.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket: