@thatkid02/react-native-pdf-viewer 0.0.2 → 0.0.3
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.
- package/README.md +2 -0
- package/ios/PdfViewer.swift +33 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
High-performance PDF viewer for React Native, built with [Nitro Modules](https://nitro.margelo.com/) for native rendering performance.
|
|
7
7
|
|
|
8
|
+
<video src="docs/pdf.mp4" controls></video>
|
|
9
|
+
|
|
8
10
|
## Features
|
|
9
11
|
|
|
10
12
|
✅ **High-performance PDF rendering** with native APIs (PDFKit on iOS, PdfRenderer on Android)
|
package/ios/PdfViewer.swift
CHANGED
|
@@ -347,7 +347,13 @@ class HybridPdfViewer: HybridPdfViewerSpec {
|
|
|
347
347
|
|
|
348
348
|
// Observe bounds changes to update scale factor when view is resized
|
|
349
349
|
boundsObservation = pdfView.observe(\.bounds, options: [.new]) { [weak self] _, _ in
|
|
350
|
-
self
|
|
350
|
+
guard let self = self else { return }
|
|
351
|
+
// Only re-enable autoScales during bounds change if we're at default scale
|
|
352
|
+
// This allows manual zoom to persist through view lifecycle changes
|
|
353
|
+
if self.pdfView.displayMode == .singlePageContinuous && self.pdfView.scaleFactor == 1.0 {
|
|
354
|
+
self.pdfView.autoScales = true
|
|
355
|
+
}
|
|
356
|
+
self.updateScaleToFitWidthIfNeeded()
|
|
351
357
|
}
|
|
352
358
|
}
|
|
353
359
|
|
|
@@ -494,9 +500,19 @@ class HybridPdfViewer: HybridPdfViewerSpec {
|
|
|
494
500
|
pdfView.document = document
|
|
495
501
|
thumbnailCache.removeAllObjects()
|
|
496
502
|
|
|
503
|
+
// Ensure autoScales is enabled for proper width fitting
|
|
504
|
+
pdfView.autoScales = true
|
|
505
|
+
|
|
497
506
|
// Update scale after document is loaded
|
|
498
507
|
updateScaleToFitWidthIfNeeded()
|
|
499
508
|
|
|
509
|
+
// If bounds were zero, schedule a delayed update
|
|
510
|
+
if pdfView.bounds.width == 0 {
|
|
511
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [weak self] in
|
|
512
|
+
self?.updateScaleToFitWidthIfNeeded()
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
500
516
|
if let firstPage = document.page(at: 0) {
|
|
501
517
|
let pageRect = firstPage.bounds(for: .mediaBox)
|
|
502
518
|
onLoadComplete?(LoadCompleteEvent(
|
|
@@ -517,10 +533,18 @@ class HybridPdfViewer: HybridPdfViewerSpec {
|
|
|
517
533
|
// Only update scale if view has been laid out (width > 0)
|
|
518
534
|
guard viewWidth > 0 && pageRect.width > 0 else { return }
|
|
519
535
|
|
|
520
|
-
// In continuous scroll mode
|
|
521
|
-
// We just need to ensure autoScales is enabled
|
|
536
|
+
// In continuous scroll mode, check if we should enable autoScales
|
|
522
537
|
if pdfView.displayMode == .singlePageContinuous {
|
|
523
|
-
|
|
538
|
+
// Only enable autoScales if at default scale (hasn't been manually zoomed)
|
|
539
|
+
// This preserves user's manual zoom level through view lifecycle
|
|
540
|
+
let currentScale = pdfView.scaleFactor
|
|
541
|
+
let isDefaultScale = abs(currentScale - 1.0) < 0.01
|
|
542
|
+
|
|
543
|
+
if isDefaultScale {
|
|
544
|
+
pdfView.autoScales = true
|
|
545
|
+
// Force PDFView to recalculate scale if needed
|
|
546
|
+
pdfView.layoutDocumentView()
|
|
547
|
+
}
|
|
524
548
|
} else {
|
|
525
549
|
// For paging mode, calculate and set the scale to fit width
|
|
526
550
|
let scale = viewWidth / pageRect.width
|
|
@@ -599,13 +623,11 @@ class HybridPdfViewer: HybridPdfViewerSpec {
|
|
|
599
623
|
let maxScale = CGFloat(self.maxScale ?? 4.0)
|
|
600
624
|
let clampedScale = max(minScale, min(maxScale, CGFloat(scale)))
|
|
601
625
|
|
|
602
|
-
//
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
self?.pdfView.scaleFactor = clampedScale
|
|
608
|
-
}
|
|
626
|
+
// Disable autoScales when manually setting scale
|
|
627
|
+
// This allows programmatic zoom control to work
|
|
628
|
+
ensureMainThread {
|
|
629
|
+
self.pdfView.autoScales = false
|
|
630
|
+
self.pdfView.scaleFactor = clampedScale
|
|
609
631
|
}
|
|
610
632
|
}
|
|
611
633
|
|