@amafil/react-native-pdf-toolkit 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -99,6 +99,7 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
|
|
|
99
99
|
private float autoScrollPixels = 15f; // pixels per second
|
|
100
100
|
private long autoScrollResumeDelay = 3000L;
|
|
101
101
|
private long lastFrameTimeNanos = 0;
|
|
102
|
+
private float accumulatedScrollOffset = 0f; // float accumulator – avoids re-reading the rendering-quantised offset
|
|
102
103
|
|
|
103
104
|
public PdfView(Context context, AttributeSet set){
|
|
104
105
|
super(context, set);
|
|
@@ -578,6 +579,9 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
|
|
|
578
579
|
this.autoScrollResumeDelay = resumeDelayMs;
|
|
579
580
|
this.isAutoScrolling = true;
|
|
580
581
|
this.lastFrameTimeNanos = 0;
|
|
582
|
+
// Capture current position into float accumulator so doFrame never reads back
|
|
583
|
+
// the rendering-quantised offset from getCurrentYOffset().
|
|
584
|
+
this.accumulatedScrollOffset = -getCurrentYOffset(); // getCurrentYOffset() is negative
|
|
581
585
|
|
|
582
586
|
if (autoScrollFrameCallback == null) {
|
|
583
587
|
autoScrollFrameCallback = new Choreographer.FrameCallback() {
|
|
@@ -597,9 +601,13 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
|
|
|
597
601
|
|
|
598
602
|
float elapsedSeconds = (frameTimeNanos - lastFrameTimeNanos) / 1_000_000_000f;
|
|
599
603
|
lastFrameTimeNanos = frameTimeNanos;
|
|
600
|
-
float scrollAmount = autoScrollPixels * elapsedSeconds;
|
|
601
604
|
|
|
602
|
-
float
|
|
605
|
+
// Accumulate into our own float – do NOT read getCurrentYOffset() back.
|
|
606
|
+
// barteksc may snap the rendered position to pixel boundaries; re-reading
|
|
607
|
+
// that snapped value each frame loses the fractional part and makes low
|
|
608
|
+
// speeds (< ~20 px/s) invisible.
|
|
609
|
+
accumulatedScrollOffset += autoScrollPixels * elapsedSeconds;
|
|
610
|
+
|
|
603
611
|
float totalHeight = 0;
|
|
604
612
|
int pageCount = getPageCount();
|
|
605
613
|
for (int i = 0; i < pageCount; i++) {
|
|
@@ -614,18 +622,14 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
|
|
|
614
622
|
return;
|
|
615
623
|
}
|
|
616
624
|
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
float minY = -maxScroll;
|
|
620
|
-
|
|
621
|
-
if (newY <= minY) {
|
|
622
|
-
moveTo(0, minY);
|
|
625
|
+
if (accumulatedScrollOffset >= maxScroll) {
|
|
626
|
+
moveTo(0, -maxScroll);
|
|
623
627
|
stopAutoScroll();
|
|
624
628
|
dispatchAutoScrollEndEvent();
|
|
625
629
|
return;
|
|
626
630
|
}
|
|
627
631
|
|
|
628
|
-
moveTo(0,
|
|
632
|
+
moveTo(0, -accumulatedScrollOffset);
|
|
629
633
|
Choreographer.getInstance().postFrameCallback(this);
|
|
630
634
|
}
|
|
631
635
|
};
|
|
@@ -637,6 +641,8 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
|
|
|
637
641
|
public void run() {
|
|
638
642
|
if (isAutoScrolling && !isUserTouching) {
|
|
639
643
|
lastFrameTimeNanos = 0;
|
|
644
|
+
// Re-sync accumulator after user may have scrolled manually during pause.
|
|
645
|
+
accumulatedScrollOffset = -getCurrentYOffset();
|
|
640
646
|
Choreographer.getInstance().postFrameCallback(autoScrollFrameCallback);
|
|
641
647
|
}
|
|
642
648
|
}
|
|
@@ -85,6 +85,7 @@ const float MIN_SCALE = 1.0f;
|
|
|
85
85
|
BOOL _isUserDragging;
|
|
86
86
|
UIScrollView *_pdfScrollView;
|
|
87
87
|
__weak id<UIScrollViewDelegate> _originalScrollDelegate;
|
|
88
|
+
CGFloat _autoScrollCurrentOffset; // float accumulator – avoids re-reading UIKit's quantized contentOffset
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
@@ -308,6 +309,7 @@ using namespace facebook::react;
|
|
|
308
309
|
_isUserDragging = NO;
|
|
309
310
|
_pdfScrollView = nil;
|
|
310
311
|
_originalScrollDelegate = nil;
|
|
312
|
+
_autoScrollCurrentOffset = 0.0;
|
|
311
313
|
|
|
312
314
|
[self addSubview:_pdfView];
|
|
313
315
|
|
|
@@ -972,7 +974,12 @@ using namespace facebook::react;
|
|
|
972
974
|
_autoScrollResumeDelay = resumeDelay;
|
|
973
975
|
_isAutoScrolling = YES;
|
|
974
976
|
|
|
975
|
-
[self findPdfScrollView];
|
|
977
|
+
UIScrollView *sv = [self findPdfScrollView];
|
|
978
|
+
// Capture the current scroll position into our float accumulator so that
|
|
979
|
+
// displayLinkTick never reads back UIKit's pixel-quantized contentOffset.
|
|
980
|
+
if (sv) {
|
|
981
|
+
_autoScrollCurrentOffset = sv.contentOffset.y;
|
|
982
|
+
}
|
|
976
983
|
[self startDisplayLink];
|
|
977
984
|
}
|
|
978
985
|
|
|
@@ -1004,7 +1011,12 @@ using namespace facebook::react;
|
|
|
1004
1011
|
|
|
1005
1012
|
// Frame-rate-independent: use actual elapsed frame time (e.g. 1/60 or 1/120 on ProMotion)
|
|
1006
1013
|
CGFloat frameDuration = (CGFloat)(link.targetTimestamp - link.timestamp);
|
|
1007
|
-
|
|
1014
|
+
|
|
1015
|
+
// Accumulate into our own float – do NOT read contentOffset back from UIKit.
|
|
1016
|
+
// UIKit / PDFKit quantises contentOffset to physical pixel boundaries (1/scale pts
|
|
1017
|
+
// on Retina displays). If we re-read that quantised value every frame we lose the
|
|
1018
|
+
// fractional part, making scrollSpeeds below ~20 px/s invisible on @3x devices.
|
|
1019
|
+
_autoScrollCurrentOffset += _autoScrollPixels * frameDuration;
|
|
1008
1020
|
|
|
1009
1021
|
CGFloat maxOffsetY = scrollView.contentSize.height - scrollView.bounds.size.height;
|
|
1010
1022
|
if (maxOffsetY <= 0) {
|
|
@@ -1013,17 +1025,14 @@ using namespace facebook::react;
|
|
|
1013
1025
|
return;
|
|
1014
1026
|
}
|
|
1015
1027
|
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
if (newY >= maxOffsetY) {
|
|
1020
|
-
[scrollView setContentOffset:CGPointMake(offset.x, maxOffsetY) animated:NO];
|
|
1028
|
+
if (_autoScrollCurrentOffset >= maxOffsetY) {
|
|
1029
|
+
[scrollView setContentOffset:CGPointMake(scrollView.contentOffset.x, maxOffsetY) animated:NO];
|
|
1021
1030
|
[self stopAutoScroll];
|
|
1022
1031
|
[self notifyOnChangeWithMessage:@"autoScrollEnd"];
|
|
1023
1032
|
return;
|
|
1024
1033
|
}
|
|
1025
1034
|
|
|
1026
|
-
[scrollView setContentOffset:CGPointMake(
|
|
1035
|
+
[scrollView setContentOffset:CGPointMake(scrollView.contentOffset.x, _autoScrollCurrentOffset) animated:NO];
|
|
1027
1036
|
}
|
|
1028
1037
|
|
|
1029
1038
|
- (void)scheduleAutoScrollResume
|
|
@@ -1039,6 +1048,11 @@ using namespace facebook::react;
|
|
|
1039
1048
|
- (void)autoScrollResumeFromTimer:(NSTimer *)timer
|
|
1040
1049
|
{
|
|
1041
1050
|
if (_isAutoScrolling && !_isUserDragging) {
|
|
1051
|
+
// Re-sync the float accumulator with the actual scroll position after
|
|
1052
|
+
// the user may have scrolled manually during the pause.
|
|
1053
|
+
if (_pdfScrollView) {
|
|
1054
|
+
_autoScrollCurrentOffset = _pdfScrollView.contentOffset.y;
|
|
1055
|
+
}
|
|
1042
1056
|
[self startDisplayLink];
|
|
1043
1057
|
}
|
|
1044
1058
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amafil/react-native-pdf-toolkit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"summary": "A react native PDF view component",
|
|
5
5
|
"description": "A react native PDF view component, support ios and android platform",
|
|
6
6
|
"main": "index.js",
|
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
"PdfViewFlatList.js",
|
|
56
56
|
"PinchZoomView.js",
|
|
57
57
|
"react-native-pdf-toolkit.podspec",
|
|
58
|
+
"react-native.config.js",
|
|
58
59
|
"fabric/"
|
|
59
60
|
],
|
|
60
61
|
"codegenConfig": {
|