Skip to content

feat: add vertical scrolling mode for PDF viewer #511

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: main
Choose a base branch
from

Conversation

cameronaaron
Copy link

feat: add vertical scrolling mode for PDF viewer

  • Implemented vertical scrolling mode to display all PDF pages in a continuous scroll view.
  • Added styles for vertical layout and page number indicators in CSS.
  • Enhanced JavaScript logic for rendering all pages and tracking current page based on scroll position.
  • Introduced a toggle button in the toolbar for switching between vertical scroll mode and traditional page mode.
  • Updated Android integration to support vertical scroll mode and preserve state during mode switching.
  • Added new vector drawable for the vertical scroll toggle icon.

cameronaaron and others added 2 commits June 27, 2025 21:35
- Implemented vertical scrolling mode to display all PDF pages in a continuous scroll view.
- Added styles for vertical layout and page number indicators in CSS.
- Enhanced JavaScript logic for rendering all pages and tracking current page based on scroll position.
- Introduced a toggle button in the toolbar for switching between vertical scroll mode and traditional page mode.
- Updated Android integration to support vertical scroll mode and preserve state during mode switching.
- Added new vector drawable for the vertical scroll toggle icon.
@cameronaaron cameronaaron marked this pull request as ready for review June 29, 2025 20:58
@Copilot Copilot AI review requested due to automatic review settings June 29, 2025 20:58
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a vertical scrolling mode for the PDF viewer, expanding the display options and integrating the feature across the JavaScript viewer, CSS styling, and Android integration. Key changes include:

  • Implementing vertical scroll mode logic with new rendering functions and scroll handling in index.js.
  • Adding corresponding CSS styles and a toggle button in the toolbar.
  • Updating Android integration to preserve mode state and respond to vertical scroll events.

Reviewed Changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
viewer/js/index.js Added functions to render all pages vertically, including scroll listener setup and toggling logic.
viewer/css/pdf_viewer.css Introduced styles for the vertical scroll container and page indicators.
app/src/main/res/values/strings.xml Added new string resource for vertical scrolling toggle.
app/src/main/res/menu/pdf_viewer.xml Inserted a new menu item for toggling vertical scroll mode.
app/src/main/res/drawable/ic_view_agenda_24dp.xml Added vector drawable for the vertical scroll icon.
app/src/main/java/app/grapheneos/pdfviewer/PdfViewer.java Integrated vertical scroll mode logic into the Android activity, including state preservation and JS interaction.

// Calculate appropriate zoom for vertical layout
const firstPage = await pdfDoc.getPage(1);
const defaultZoom = getDefaultZoomRatio(firstPage, orientationDegrees);
const verticalZoom = Math.min(defaultZoom * 0.8, containerWidth / firstPage.getViewport({scale: 1}).width);
Copy link
Preview

Copilot AI Jun 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider extracting the magic constant 0.8 into a named constant (e.g., VERTICAL_ZOOM_FACTOR) to improve code clarity and maintainability.

Suggested change
const verticalZoom = Math.min(defaultZoom * 0.8, containerWidth / firstPage.getViewport({scale: 1}).width);
const verticalZoom = Math.min(defaultZoom * VERTICAL_ZOOM_FACTOR, containerWidth / firstPage.getViewport({scale: 1}).width);

Copilot uses AI. Check for mistakes.

padding: 20px;
width: 100%;
min-height: 100vh;
`;
Copy link
Preview

Copilot AI Jun 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The inline CSS styles for the all pages container duplicate styles defined in the CSS file; consider centralizing these styles in the stylesheet to avoid duplication and ease future updates.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant