Skip to content
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
196 changes: 99 additions & 97 deletions packages/app-expo/assets/reader/reader.html

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions packages/app-expo/assets/reader/reader.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -1604,10 +1604,12 @@
const rendererPages = view && view.renderer && typeof view.renderer.pages === 'number'
? view.renderer.pages
: null;
const actualPage = rendererPage != null && rendererPages != null && rendererPages > 2
// renderer.page is 0-based and renderer.pages is the real page count:
// the renderer adds no padding pages around a section.
const actualPage = rendererPage != null && rendererPages != null && rendererPages > 0
? {
current: Math.max(1, Math.min(rendererPage, rendererPages - 2)),
total: Math.max(1, rendererPages - 2),
current: Math.min(Math.max(rendererPage + 1, 1), rendererPages),
total: rendererPages,
}
: null;
postToRN('relocate', {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { readFileSync } from "node:fs";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { describe, expect, it } from "vitest";

const repositoryRoot = resolve(dirname(fileURLToPath(import.meta.url)), "../../../../..");

function readSource(relativePath: string): string {
return readFileSync(resolve(repositoryRoot, relativePath), "utf8");
}

describe("chapter page numbering", () => {
it("maps the 0-based renderer page onto a 1-based page number on both platforms", () => {
const desktopViewer = readSource("packages/app/src/components/reader/FoliateViewer.tsx");
const template = readSource("packages/app-expo/assets/reader/reader.template.html");

for (const source of [desktopViewer, template]) {
expect(source).toMatch(
/current: Math\.min\(Math\.max\(rendererPage \+ 1, 1\), rendererPages\)/,
);
expect(source).toMatch(/total: rendererPages,/);
}
});

it("no longer assumes padding pages around a section", () => {
const desktopViewer = readSource("packages/app/src/components/reader/FoliateViewer.tsx");
const template = readSource("packages/app-expo/assets/reader/reader.template.html");

// renderer.pages is the real page count, so the old "minus one padding page on
// each side" conversion clamped the first and last page of every section.
for (const source of [desktopViewer, template]) {
expect(source).not.toContain("rendererPages - 2");
expect(source).toMatch(/rendererPages != null && rendererPages > 0/);
}
});

it("keeps the built reader in sync with the template", () => {
const builtReader = readSource("packages/app-expo/assets/reader/reader.html");

expect(builtReader).toMatch(
/current: Math\.min\(Math\.max\(rendererPage \+ 1, 1\), rendererPages\)/,
);
expect(builtReader).not.toContain("rendererPages - 2");
});
});
8 changes: 5 additions & 3 deletions packages/app/src/components/reader/FoliateViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2060,13 +2060,15 @@ export const FoliateViewer = forwardRef<FoliateViewerHandle, FoliateViewerProps>
viewRef.current?.renderer && typeof viewRef.current.renderer.pages === "number"
? viewRef.current.renderer.pages
: null;
// renderer.page is 0-based and renderer.pages is the real page count:
// the renderer adds no padding pages around a section.
const detail: RelocateDetail =
rendererPage != null && rendererPages != null && rendererPages > 2
rendererPage != null && rendererPages != null && rendererPages > 0
? {
...rawDetail,
page: {
current: Math.max(1, Math.min(rendererPage, rendererPages - 2)),
total: Math.max(1, rendererPages - 2),
current: Math.min(Math.max(rendererPage + 1, 1), rendererPages),
total: rendererPages,
},
}
: rawDetail;
Expand Down