Skip to content
This repository was archived by the owner on Nov 10, 2025. It is now read-only.

Commit 14880a7

Browse files
committed
Fix for Issue "Ugly rendering during scale DImuthuUpe#156"
- add option renderDuringScale to PdfView - conditionally call loadPageByOffset from DragPinchManager.onScroll
1 parent 997cdf3 commit 14880a7

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/DragPinchManager.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class DragPinchManager implements GestureDetector.OnGestureListener, GestureDete
4343
private boolean swipeVertical;
4444

4545
private boolean scrolling = false;
46+
private boolean scaling = false;
4647

4748
public DragPinchManager(PDFView pdfView, AnimationManager animationManager) {
4849
this.pdfView = pdfView;
@@ -131,8 +132,9 @@ public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float d
131132
if (isZooming() || isSwipeEnabled) {
132133
pdfView.moveRelativeTo(-distanceX, -distanceY);
133134
}
134-
pdfView.loadPageByOffset();
135-
135+
if (!scaling || pdfView.doRenderDuringScale()) {
136+
pdfView.loadPageByOffset();
137+
}
136138
return true;
137139
}
138140

@@ -174,13 +176,15 @@ public boolean onScale(ScaleGestureDetector detector) {
174176

175177
@Override
176178
public boolean onScaleBegin(ScaleGestureDetector detector) {
179+
scaling = true;
177180
return true;
178181
}
179182

180183
@Override
181184
public void onScaleEnd(ScaleGestureDetector detector) {
182185
pdfView.loadPages();
183186
hideHandle();
187+
scaling = false;
184188
}
185189

186190
@Override

android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/PDFView.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import com.shockwave.pdfium.PdfiumCore;
5252

5353
import java.io.File;
54-
import java.io.IOException;
5554
import java.io.InputStream;
5655
import java.util.ArrayList;
5756
import java.util.List;
@@ -262,6 +261,14 @@ ScrollHandle getScrollHandle() {
262261
*/
263262
private boolean annotationRendering = false;
264263

264+
/**
265+
* True if the view should render during scaling - default<br/>
266+
* Can not be forced on older API versions (< Build.VERSION_CODES.KITKAT) as the GestureDetector does
267+
* not detect scrolling while scaling.<br/>
268+
* False otherwise
269+
*/
270+
private boolean renderDuringScale = true;
271+
265272
/**
266273
* Construct the initial view
267274
*/
@@ -1095,6 +1102,14 @@ public boolean isAnnotationRendering() {
10951102
return annotationRendering;
10961103
}
10971104

1105+
public void enableRenderDuringScale(boolean renderDuringScale) {
1106+
this.renderDuringScale = renderDuringScale;
1107+
}
1108+
1109+
public boolean doRenderDuringScale() {
1110+
return renderDuringScale;
1111+
}
1112+
10981113
public PdfDocument.Meta getDocumentMeta() {
10991114
if (pdfDocument == null) {
11001115
return null;

0 commit comments

Comments
 (0)