@june24/expo-pdf-reader 0.1.18 → 0.1.20
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.
|
@@ -96,8 +96,8 @@ class ExpoPdfReaderView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
96
96
|
private var lastEmittedPageIndex = -1
|
|
97
97
|
private var totalPageCount = 0
|
|
98
98
|
|
|
99
|
-
private val renderWindowBefore =
|
|
100
|
-
private val renderWindowAfter =
|
|
99
|
+
private val renderWindowBefore = 20
|
|
100
|
+
private val renderWindowAfter = 25
|
|
101
101
|
|
|
102
102
|
// Annotation state
|
|
103
103
|
private val pageAnnotations = mutableListOf<MutableList<Annotation>>()
|
|
@@ -405,13 +405,8 @@ class ExpoPdfReaderView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
405
405
|
|
|
406
406
|
override fun onSizeChanged(w: Int, h: Int, oldW: Int, oldH: Int) {
|
|
407
407
|
super.onSizeChanged(w, h, oldW, oldH)
|
|
408
|
-
if (w > 0 && pdfRenderer != null) {
|
|
409
|
-
|
|
410
|
-
pageHeights.clear()
|
|
411
|
-
}
|
|
412
|
-
if (pageHeights.isEmpty()) {
|
|
413
|
-
renderPdf()
|
|
414
|
-
}
|
|
408
|
+
if (w > 0 && pdfRenderer != null && pageHeights.isEmpty()) {
|
|
409
|
+
renderPdf()
|
|
415
410
|
}
|
|
416
411
|
}
|
|
417
412
|
|
|
@@ -557,11 +552,13 @@ class ExpoPdfReaderView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
557
552
|
notifyAnnotationChange()
|
|
558
553
|
}
|
|
559
554
|
|
|
555
|
+
private fun marginBetweenPages(): Int = if (displayMode == "single") 0 else 16
|
|
556
|
+
|
|
560
557
|
private fun scrollToPage(pageIndex: Int) {
|
|
561
558
|
if (pageHeights.isEmpty()) return
|
|
562
559
|
var offset = 0
|
|
563
560
|
for (i in 0 until pageIndex.coerceIn(0, pageHeights.size - 1)) {
|
|
564
|
-
offset += pageHeights[i] +
|
|
561
|
+
offset += pageHeights[i] + marginBetweenPages()
|
|
565
562
|
}
|
|
566
563
|
scrollView.post { scrollView.smoothScrollTo(0, offset) }
|
|
567
564
|
}
|
|
@@ -619,7 +616,6 @@ class ExpoPdfReaderView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
619
616
|
draggingPageIndex = -1
|
|
620
617
|
dragStartBounds = null
|
|
621
618
|
dragStartTouch = null
|
|
622
|
-
renderJob?.cancel()
|
|
623
619
|
}
|
|
624
620
|
|
|
625
621
|
private fun renderPdf() {
|
|
@@ -636,16 +632,23 @@ class ExpoPdfReaderView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
636
632
|
updateVisiblePages()
|
|
637
633
|
return
|
|
638
634
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
635
|
+
val viewHeight = height.coerceAtLeast(1)
|
|
636
|
+
val viewWidth = width.coerceAtLeast(1)
|
|
637
|
+
val isSingle = displayMode == "single"
|
|
638
|
+
scope.launch {
|
|
639
|
+
val w = viewWidth
|
|
642
640
|
val result = withContext(Dispatchers.Default) {
|
|
643
641
|
(0 until renderer.pageCount).map { i ->
|
|
644
642
|
val page = renderer.openPage(i)
|
|
645
643
|
try {
|
|
644
|
+
val pageH = if (isSingle) {
|
|
645
|
+
viewHeight
|
|
646
|
+
} else {
|
|
647
|
+
(w.toFloat() * page.height / page.width).toInt()
|
|
648
|
+
}
|
|
646
649
|
Triple(
|
|
647
650
|
i,
|
|
648
|
-
|
|
651
|
+
pageH,
|
|
649
652
|
Pair(page.width.toFloat(), page.height.toFloat())
|
|
650
653
|
)
|
|
651
654
|
} finally {
|
|
@@ -673,6 +676,7 @@ class ExpoPdfReaderView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
673
676
|
private fun ensurePlaceholders(renderer: PdfRenderer) {
|
|
674
677
|
container.removeAllViews()
|
|
675
678
|
val pageCount = renderer.pageCount
|
|
679
|
+
val marginBetween = marginBetweenPages()
|
|
676
680
|
pageViews = MutableList(pageCount) { null }
|
|
677
681
|
overlayViews = MutableList(pageCount) { null }
|
|
678
682
|
while (pageAnnotations.size < pageCount) {
|
|
@@ -683,7 +687,7 @@ class ExpoPdfReaderView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
683
687
|
layoutParams = LinearLayout.LayoutParams(
|
|
684
688
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
|
685
689
|
pageHeights[i]
|
|
686
|
-
).apply { setMargins(0, 0, 0,
|
|
690
|
+
).apply { setMargins(0, 0, 0, marginBetween) }
|
|
687
691
|
setBackgroundColor(Color.LTGRAY)
|
|
688
692
|
}
|
|
689
693
|
val overlay = AnnotationOverlayView(context, i).apply {
|
|
@@ -702,9 +706,10 @@ class ExpoPdfReaderView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
702
706
|
if (pageHeights.isEmpty()) return 0
|
|
703
707
|
val scrollY = scrollView.scrollY
|
|
704
708
|
var offset = 0
|
|
709
|
+
val gap = marginBetweenPages()
|
|
705
710
|
for (i in pageHeights.indices) {
|
|
706
711
|
if (scrollY < offset + pageHeights[i] / 2) return i
|
|
707
|
-
offset += pageHeights[i] +
|
|
712
|
+
offset += pageHeights[i] + gap
|
|
708
713
|
}
|
|
709
714
|
return (pageHeights.size - 1).coerceAtLeast(0)
|
|
710
715
|
}
|
|
@@ -764,12 +769,13 @@ class ExpoPdfReaderView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
764
769
|
val scrollY = scrollView.scrollY
|
|
765
770
|
var offset = 0
|
|
766
771
|
var detectedPage = 0
|
|
772
|
+
val gap = marginBetweenPages()
|
|
767
773
|
for (i in pageHeights.indices) {
|
|
768
774
|
if (scrollY < offset + pageHeights[i] / 2) {
|
|
769
775
|
detectedPage = i
|
|
770
776
|
break
|
|
771
777
|
}
|
|
772
|
-
offset += pageHeights[i] +
|
|
778
|
+
offset += pageHeights[i] + gap
|
|
773
779
|
detectedPage = i
|
|
774
780
|
}
|
|
775
781
|
if (detectedPage != lastEmittedPageIndex) {
|
package/package.json
CHANGED