Skip to content
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

Fix swipe gestures on android for book reader #5843

Merged
merged 4 commits into from
Aug 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/plugins/bookPlayer/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}
Expand All @@ -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() {
Expand All @@ -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();
}

Expand Down
Loading