From 75d78a96b8553c60947d866a8bb72ae5f068d141 Mon Sep 17 00:00:00 2001 From: viown <48097677+viown@users.noreply.github.com> Date: Tue, 13 Aug 2024 11:53:21 -0400 Subject: [PATCH] Backport pull request #5843 from jellyfin-web/release-10.9.z Fix swipe gestures on android for book reader Original-merge: 44afbc2357df70613b56a2d397a6fa41457250ef Merged-by: thornbill Backported-by: thornbill --- src/plugins/bookPlayer/plugin.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/plugins/bookPlayer/plugin.js b/src/plugins/bookPlayer/plugin.js index ef8fef28b5..17fec59285 100644 --- a/src/plugins/bookPlayer/plugin.js +++ b/src/plugins/bookPlayer/plugin.js @@ -7,6 +7,7 @@ import ServerConnections from '../../components/ServerConnections'; import Screenfull from 'screenfull'; import TableOfContents from './tableOfContents'; import { translateHtml } from '../../scripts/globalize'; +import browser from 'scripts/browser'; import * as userSettings from '../../scripts/settings/userSettings'; import TouchHelper from 'scripts/touchHelper'; import { PluginType } from '../../types/plugin.ts'; @@ -45,6 +46,7 @@ export class BookPlayer { this.previous = this.previous.bind(this); this.next = this.next.bind(this); this.onWindowKeyUp = this.onWindowKeyUp.bind(this); + this.addSwipeGestures = this.addSwipeGestures.bind(this); } play(options) { @@ -155,6 +157,12 @@ export class BookPlayer { } } + addSwipeGestures(element) { + this.touchHelper = new TouchHelper(element); + Events.on(this.touchHelper, 'swipeleft', () => this.next()); + Events.on(this.touchHelper, 'swiperight', () => this.previous()); + } + onDialogClosed() { this.stop(); } @@ -179,10 +187,12 @@ export class BookPlayer { document.addEventListener('keyup', this.onWindowKeyUp); this.rendition?.on('keyup', this.onWindowKeyUp); - const player = document.getElementById('bookPlayerContainer'); - this.touchHelper = new TouchHelper(player); - Events.on(this.touchHelper, 'swipeleft', () => this.next()); - Events.on(this.touchHelper, 'swiperight', () => this.previous()); + if (browser.safari) { + const player = document.getElementById('bookPlayerContainer'); + this.addSwipeGestures(player); + } else { + this.rendition?.on('rendered', (e, i) => this.addSwipeGestures(i.document.documentElement)); + } } unbindMediaElementEvents() { @@ -207,6 +217,10 @@ export class BookPlayer { document.removeEventListener('keyup', this.onWindowKeyUp); this.rendition?.off('keyup', this.onWindowKeyUp); + if (!browser.safari) { + this.rendition?.off('rendered', (e, i) => this.addSwipeGestures(i.document.documentElement)); + } + this.touchHelper?.destroy(); }