@june24/expo-pdf-reader 0.1.21 → 0.1.23
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.
|
@@ -384,6 +384,7 @@ class ExpoPdfReaderView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
384
384
|
addView(scrollView)
|
|
385
385
|
scrollView.viewTreeObserver.addOnScrollChangedListener {
|
|
386
386
|
notifyPageChange()
|
|
387
|
+
scrollView.post { updateVisiblePages() }
|
|
387
388
|
}
|
|
388
389
|
viewTreeObserver.addOnGlobalLayoutListener {
|
|
389
390
|
if (width <= 0) {
|
|
@@ -606,7 +607,10 @@ class ExpoPdfReaderView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
606
607
|
pdfRenderer = PdfRenderer(fileDescriptor!!)
|
|
607
608
|
totalPageCount = pdfRenderer!!.pageCount
|
|
608
609
|
renderPdf()
|
|
609
|
-
post {
|
|
610
|
+
post {
|
|
611
|
+
requestLayout()
|
|
612
|
+
postDelayed({ renderPdf() }, 100)
|
|
613
|
+
}
|
|
610
614
|
pendingAnnotations?.let { ann ->
|
|
611
615
|
pendingAnnotations = null
|
|
612
616
|
setInitialAnnotations(ann)
|
|
@@ -650,7 +654,8 @@ class ExpoPdfReaderView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
650
654
|
if (width <= 0) {
|
|
651
655
|
if (renderPdfRetryCount < maxRenderPdfRetries) {
|
|
652
656
|
renderPdfRetryCount++
|
|
653
|
-
|
|
657
|
+
requestLayout()
|
|
658
|
+
postDelayed({ renderPdf() }, 50)
|
|
654
659
|
}
|
|
655
660
|
return
|
|
656
661
|
}
|
|
@@ -660,47 +665,57 @@ class ExpoPdfReaderView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
660
665
|
return
|
|
661
666
|
}
|
|
662
667
|
val viewWidth = width.coerceAtLeast(1)
|
|
668
|
+
val viewHeight = height.coerceAtLeast(1)
|
|
663
669
|
val isTwoUp = displayMode == "twoUp" || displayMode == "twoUpContinuous"
|
|
670
|
+
val isSingle = displayMode == "single"
|
|
664
671
|
val effectiveWidth = if (isTwoUp) viewWidth / 2 else viewWidth
|
|
665
672
|
scope.launch {
|
|
666
673
|
val w = effectiveWidth
|
|
674
|
+
val minSlotHeight = if (isSingle) viewHeight else 0
|
|
667
675
|
val result = withContext(Dispatchers.Default) {
|
|
668
676
|
(0 until renderer.pageCount).map { i ->
|
|
669
677
|
val page = renderer.openPage(i)
|
|
670
678
|
try {
|
|
671
|
-
val
|
|
679
|
+
val naturalH = (w.toFloat() * page.height / page.width).toInt()
|
|
680
|
+
val pageH = if (isSingle) maxOf(naturalH, minSlotHeight) else naturalH
|
|
672
681
|
Triple(
|
|
673
682
|
i,
|
|
674
683
|
pageH,
|
|
675
684
|
Pair(page.width.toFloat(), page.height.toFloat())
|
|
676
685
|
)
|
|
677
686
|
} finally {
|
|
678
|
-
|
|
687
|
+
try {
|
|
688
|
+
page.close()
|
|
689
|
+
} catch (e: Exception) {
|
|
690
|
+
// Renderer may have been closed on main thread (e.g. resetRenderer)
|
|
691
|
+
}
|
|
679
692
|
}
|
|
680
693
|
}
|
|
681
694
|
}
|
|
682
695
|
if (!isActive) return@launch
|
|
683
696
|
withContext(Dispatchers.Main) {
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
if (isTwoUp) {
|
|
694
|
-
val rowCount = (renderer.pageCount + 1) / 2
|
|
695
|
-
for (r in 0 until rowCount) {
|
|
696
|
-
val h0 = pageHeights.getOrElse(2 * r) { 0 }
|
|
697
|
-
val h1 = pageHeights.getOrElse(2 * r + 1) { 0 }
|
|
698
|
-
rowHeights.add(maxOf(h0, h1))
|
|
697
|
+
if (pdfRenderer != null) {
|
|
698
|
+
pageHeights.clear()
|
|
699
|
+
rowHeights.clear()
|
|
700
|
+
pageWidthsPdf.clear()
|
|
701
|
+
pageHeightsPdf.clear()
|
|
702
|
+
for ((_, h, pdfSize) in result) {
|
|
703
|
+
pageHeights.add(h)
|
|
704
|
+
pageWidthsPdf.add(pdfSize.first)
|
|
705
|
+
pageHeightsPdf.add(pdfSize.second)
|
|
699
706
|
}
|
|
707
|
+
if (isTwoUp) {
|
|
708
|
+
val rowCount = (renderer.pageCount + 1) / 2
|
|
709
|
+
for (r in 0 until rowCount) {
|
|
710
|
+
val h0 = pageHeights.getOrElse(2 * r) { 0 }
|
|
711
|
+
val h1 = pageHeights.getOrElse(2 * r + 1) { 0 }
|
|
712
|
+
rowHeights.add(maxOf(h0, h1))
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
ensurePlaceholders(renderer)
|
|
716
|
+
scrollToPage(initialPage.coerceIn(0, (renderer.pageCount - 1).coerceAtLeast(0)))
|
|
717
|
+
updateVisiblePages()
|
|
700
718
|
}
|
|
701
|
-
ensurePlaceholders(renderer)
|
|
702
|
-
scrollToPage(initialPage.coerceIn(0, (renderer.pageCount - 1).coerceAtLeast(0)))
|
|
703
|
-
updateVisiblePages()
|
|
704
719
|
}
|
|
705
720
|
}
|
|
706
721
|
}
|
|
@@ -783,10 +798,12 @@ class ExpoPdfReaderView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
783
798
|
}
|
|
784
799
|
return (pageHeights.size - 1).coerceAtLeast(0)
|
|
785
800
|
}
|
|
801
|
+
val viewportCenter = scrollY + scrollView.height / 2
|
|
786
802
|
var offset = 0
|
|
787
803
|
for (i in pageHeights.indices) {
|
|
788
|
-
|
|
789
|
-
|
|
804
|
+
val pageEnd = offset + pageHeights[i]
|
|
805
|
+
if (viewportCenter < pageEnd) return i
|
|
806
|
+
offset = pageEnd + gap
|
|
790
807
|
}
|
|
791
808
|
return (pageHeights.size - 1).coerceAtLeast(0)
|
|
792
809
|
}
|
|
@@ -794,8 +811,12 @@ class ExpoPdfReaderView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
794
811
|
private fun updateVisiblePages() {
|
|
795
812
|
val renderer = pdfRenderer ?: return
|
|
796
813
|
val currentPage = currentPageFromScroll()
|
|
797
|
-
val from = (
|
|
798
|
-
|
|
814
|
+
val (from, to) = if (displayMode == "single") {
|
|
815
|
+
currentPage to currentPage
|
|
816
|
+
} else {
|
|
817
|
+
(currentPage - renderWindowBefore).coerceAtLeast(0) to
|
|
818
|
+
(currentPage + renderWindowAfter).coerceAtMost(renderer.pageCount - 1)
|
|
819
|
+
}
|
|
799
820
|
|
|
800
821
|
for (i in pageViews.indices) {
|
|
801
822
|
if (i in from..to) continue
|
package/package.json
CHANGED