Skip to content

Scroll fixes #148

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion navigator-html-injectables/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@readium/navigator-html-injectables",
"version": "2.0.0-beta.4",
"version": "2.0.0-beta.5",
"type": "module",
"description": "An embeddable solution for connecting frames of HTML publications with a Readium Navigator",
"author": "readium",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export class ColumnSnapper extends Snapper {
}

reportProgress() {
// Contrary to ScrollTop, Android slightly adds to scrollX
// So we do not need to round it up
const scrollX = this.wnd.scrollX;
const scrollWidth = this.cachedScrollWidth;
const progress = Math.max(0, Math.min(1, scrollX / scrollWidth));
Expand Down
16 changes: 13 additions & 3 deletions navigator-html-injectables/src/modules/snapper/ScrollSnapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ export class ScrollSnapper extends Snapper {
}

private reportProgress() {
const scrollTop = this.doc().scrollTop;
// We have to round up the scroll position because
// Android may never reach 100% of the scroll height
// due to the way it rounds scrollTop…
const scrollTop = Math.ceil(this.doc().scrollTop);
const scrollHeight = this.doc().scrollHeight;
const viewportHeight = this.wnd.innerHeight;
const progress = Math.max(0, Math.min(1, scrollTop / scrollHeight));
const viewportEnd = Math.max(0, Math.min(1, (scrollTop + this.wnd.innerHeight) / scrollHeight));
const viewportEnd = Math.max(0, Math.min(1, (scrollTop + viewportHeight) / scrollHeight));

this.comms.send("progress", {
start: progress,
end: viewportEnd
Expand Down Expand Up @@ -78,8 +83,13 @@ export class ScrollSnapper extends Snapper {
// Only the content at the start of the document,
// whose height is the viewport height, will be rendered.
const currentScroll = this.doc().scrollTop;
this.doc().scrollTop = currentScroll + 1;
if (currentScroll > 1) {
this.doc().scrollTop = currentScroll - 1;
} else {
this.doc().scrollTop = currentScroll + 1;
}
this.doc().scrollTop = currentScroll;

});

comms.register("go_progression", ScrollSnapper.moduleName, (data, ack) => {
Expand Down
2 changes: 1 addition & 1 deletion navigator/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@readium/navigator",
"version": "2.0.0-beta.11",
"version": "2.0.0-beta.12",
"type": "module",
"description": "Next generation SDK for publications in Web Apps",
"author": "readium",
Expand Down