-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
feat: add support for arrow key navigation #182
Conversation
Hello 👋 Thanks for your contribution! I think for #182 your changes will have to be moved to/adjusted for the EpubJsReader. All image-based readers actually already have keyboard interactions for navigation. Since the few different media types have to be consumed in very different ways (largely a different between EPUB vs image-based media), the I sort of (strongly) dislike working with epub.js, so wanted to look into this a little to help. A quick glance at some examples on their repository suggests you would need to use the (Also if you're wanting to participate in Hacktoberfest let me know and I'll apply the appropriate label to this PR) |
Thanks for the info, I'll look into how to make these changes to EpubJSReader and update accordingly. |
Okay this is what I've got so far. This allows arrow navigation of epubs but it has a problem I haven't yet been able to solve: when the epub is navigated to a new "location" (e.g. going from the main text to the cover), the epub renderer loses focus and the arrow navigation won't work until the user clicks on the screen to focus on it. I tried to traverse this by adding an additional listener to the window, since that will fire on keydowns when the epub is not in focus, but this doesn't work. Although the event does fire, the |
Honestly I am not entirely sure. I did try out your changes locally, though:
I've tried a few different browsers and this additional work around you added seems to resolve the issue for me in all of them, strangely. And then removing your line: window.addEventListener('keydown', keydown_callback) presents the issue I believe you are describing, where it loses focus after a seemingly random number of page changes. You're welcome to continue debugging, but I'm satisfied with the functionality I am seeing 😄 In the future, once epub chapter streaming is properly implemented, I have a dream of removing epub.js entirely anyways |
Hmm maybe I just forgot to hit F5 when testing it 😅, because I just rebuilt and it works fine for me as well. I'm going to push a cleaned up commit without all the fixme comments. |
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.
Thank you! (Also note that I approved the CI run, but I know that the Docker workflow will fail. Nothing on your end, CI just needs some tweaking)
This pull request is a response to issue #123, which requested the left/right arrow keys be usable for previous/next page navigation when reading books.
I implemented this with a new effect in BookReaderScene.tsx which adds a keydown listener and navigates on
ArrowLeft
andArrowLeft
if the current page isn't the first/last page.Happy to make any changes needed, I'm less familiar with React so I may not have done this the ideal way.