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

Single page scrolling #514

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Single page scrolling #514

wants to merge 3 commits into from

Conversation

starnaus
Copy link

Added "PageViewType" with two available values: SINGLE or CONTINUOUS. Continuous behaves as it did before. Single will swipe one page at a time, centered in the viewer. Zooming will behave like Continuous in order to view the whole page (so it won't keep snapping to leading edge of page), until zoomed to min where it will re-center.

…ll snap current page to center. Zoom > min will use continuous scroll until zoom returns back to min, then it will snap to current page.
Copy link
Collaborator

@barteksc barteksc left a comment

Choose a reason for hiding this comment

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

I have added few notes to adjust your code with coding style used in this project

@@ -1,3 +1,4 @@
//apply plugin: 'java'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove comment

@@ -26,7 +27,7 @@ ext {

android {
compileSdkVersion 25
buildToolsVersion '25.0.3'
//buildToolsVersion '25.0.3'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove comment

@@ -171,6 +173,8 @@ public void onAnimationCancel(Animator animation) {

@Override
public void onAnimationEnd(Animator animation) {
if (pdfView.getPageViewType() == PageViewType.SINGLE && pdfView.getZoom() == pdfView.getMinZoom())
pdfView.jumpTo(pdfView.getCurrentPage(), true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add braces to if block

@@ -178,6 +179,8 @@ public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float d
}

private void onScrollEnd(MotionEvent event) {
if (pdfView.getPageViewType() == PageViewType.SINGLE && !pdfView.isZooming())
pdfView.jumpTo(pdfView.getCurrentPage(), true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add braces to if block

@@ -275,6 +279,8 @@ public void jumpTo(int page, boolean withAnimation) {

page = pdfFile.determineValidPageNumberFrom(page);
float offset = -pdfFile.getPageOffset(page, zoom);
if (getPageViewType() == PageViewType.SINGLE)
offset = page == 0 ? 0 : -pdfFile.getPageOffset(page, zoom) + spacingPx;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add braces to if block

@@ -13,11 +13,11 @@ repositories {
}

apply plugin: 'com.android.application'
apply plugin: 'android-apt'
//apply plugin: 'android-apt'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove comment


android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
//buildToolsVersion "25.0.3"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove comment

@@ -102,7 +105,7 @@ void launchPicker() {

@AfterViews
void afterViews() {
pdfView.setBackgroundColor(Color.LTGRAY);
pdfView.setBackgroundColor(Color.BLACK);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please do not modify sample when it isn't needed

.load();
.load();*/

PDFView.Configurator configurator = pdfView.fromAsset(SAMPLE_FILE);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please revert it to chained style

@@ -114,7 +117,7 @@ void afterViews() {
private void displayFromAsset(String assetFileName) {
pdfFileName = assetFileName;

pdfView.fromAsset(SAMPLE_FILE)
/*pdfView.fromAsset(SAMPLE_FILE)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove comment

@barteksc
Copy link
Collaborator

I have found a problem - when page is not filling width or height of view (depending whether swiping horizontally or vertically) it is aligned to top/left and next page is visible. Sometimes you cannot say which page is active. You can see what I mean on screenshot attached below
screenshot_1516040159

@barteksc
Copy link
Collaborator

And of course thank you for contribution

@XCarbone
Copy link

XCarbone commented Oct 8, 2019

This doesn't work, I get blocked on the first page on portait.
And it scroll to the last page on landscape.
Because spacingPx is never set so is = 0.

@XCarbone
Copy link

XCarbone commented Oct 9, 2019

update for those who are struggling with a view page per page, just add to the constructor
.swipeHorizontal(true)
.pageSnap(true)
.autoSpacing(true)
.pageFling(true)

And you will get a page per page view, allowing you to swipe to the next page

@sulman15
Copy link

how can show curl or flip animation on page change or on page scroll ?

@shani74
Copy link

shani74 commented Jun 17, 2023

how to solve this problem? please guide us with code snippet.

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.

5 participants