@june24/expo-pdf-reader 0.1.19 → 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>>()
|
|
@@ -552,11 +552,13 @@ class ExpoPdfReaderView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
552
552
|
notifyAnnotationChange()
|
|
553
553
|
}
|
|
554
554
|
|
|
555
|
+
private fun marginBetweenPages(): Int = if (displayMode == "single") 0 else 16
|
|
556
|
+
|
|
555
557
|
private fun scrollToPage(pageIndex: Int) {
|
|
556
558
|
if (pageHeights.isEmpty()) return
|
|
557
559
|
var offset = 0
|
|
558
560
|
for (i in 0 until pageIndex.coerceIn(0, pageHeights.size - 1)) {
|
|
559
|
-
offset += pageHeights[i] +
|
|
561
|
+
offset += pageHeights[i] + marginBetweenPages()
|
|
560
562
|
}
|
|
561
563
|
scrollView.post { scrollView.smoothScrollTo(0, offset) }
|
|
562
564
|
}
|
|
@@ -630,15 +632,23 @@ class ExpoPdfReaderView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
630
632
|
updateVisiblePages()
|
|
631
633
|
return
|
|
632
634
|
}
|
|
635
|
+
val viewHeight = height.coerceAtLeast(1)
|
|
636
|
+
val viewWidth = width.coerceAtLeast(1)
|
|
637
|
+
val isSingle = displayMode == "single"
|
|
633
638
|
scope.launch {
|
|
634
|
-
val w =
|
|
639
|
+
val w = viewWidth
|
|
635
640
|
val result = withContext(Dispatchers.Default) {
|
|
636
641
|
(0 until renderer.pageCount).map { i ->
|
|
637
642
|
val page = renderer.openPage(i)
|
|
638
643
|
try {
|
|
644
|
+
val pageH = if (isSingle) {
|
|
645
|
+
viewHeight
|
|
646
|
+
} else {
|
|
647
|
+
(w.toFloat() * page.height / page.width).toInt()
|
|
648
|
+
}
|
|
639
649
|
Triple(
|
|
640
650
|
i,
|
|
641
|
-
|
|
651
|
+
pageH,
|
|
642
652
|
Pair(page.width.toFloat(), page.height.toFloat())
|
|
643
653
|
)
|
|
644
654
|
} finally {
|
|
@@ -666,6 +676,7 @@ class ExpoPdfReaderView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
666
676
|
private fun ensurePlaceholders(renderer: PdfRenderer) {
|
|
667
677
|
container.removeAllViews()
|
|
668
678
|
val pageCount = renderer.pageCount
|
|
679
|
+
val marginBetween = marginBetweenPages()
|
|
669
680
|
pageViews = MutableList(pageCount) { null }
|
|
670
681
|
overlayViews = MutableList(pageCount) { null }
|
|
671
682
|
while (pageAnnotations.size < pageCount) {
|
|
@@ -676,7 +687,7 @@ class ExpoPdfReaderView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
676
687
|
layoutParams = LinearLayout.LayoutParams(
|
|
677
688
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
|
678
689
|
pageHeights[i]
|
|
679
|
-
).apply { setMargins(0, 0, 0,
|
|
690
|
+
).apply { setMargins(0, 0, 0, marginBetween) }
|
|
680
691
|
setBackgroundColor(Color.LTGRAY)
|
|
681
692
|
}
|
|
682
693
|
val overlay = AnnotationOverlayView(context, i).apply {
|
|
@@ -695,9 +706,10 @@ class ExpoPdfReaderView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
695
706
|
if (pageHeights.isEmpty()) return 0
|
|
696
707
|
val scrollY = scrollView.scrollY
|
|
697
708
|
var offset = 0
|
|
709
|
+
val gap = marginBetweenPages()
|
|
698
710
|
for (i in pageHeights.indices) {
|
|
699
711
|
if (scrollY < offset + pageHeights[i] / 2) return i
|
|
700
|
-
offset += pageHeights[i] +
|
|
712
|
+
offset += pageHeights[i] + gap
|
|
701
713
|
}
|
|
702
714
|
return (pageHeights.size - 1).coerceAtLeast(0)
|
|
703
715
|
}
|
|
@@ -757,12 +769,13 @@ class ExpoPdfReaderView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
757
769
|
val scrollY = scrollView.scrollY
|
|
758
770
|
var offset = 0
|
|
759
771
|
var detectedPage = 0
|
|
772
|
+
val gap = marginBetweenPages()
|
|
760
773
|
for (i in pageHeights.indices) {
|
|
761
774
|
if (scrollY < offset + pageHeights[i] / 2) {
|
|
762
775
|
detectedPage = i
|
|
763
776
|
break
|
|
764
777
|
}
|
|
765
|
-
offset += pageHeights[i] +
|
|
778
|
+
offset += pageHeights[i] + gap
|
|
766
779
|
detectedPage = i
|
|
767
780
|
}
|
|
768
781
|
if (detectedPage != lastEmittedPageIndex) {
|
package/package.json
CHANGED