@june24/expo-pdf-reader 0.1.21 → 0.1.22
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) {
|
|
@@ -660,27 +661,36 @@ class ExpoPdfReaderView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
660
661
|
return
|
|
661
662
|
}
|
|
662
663
|
val viewWidth = width.coerceAtLeast(1)
|
|
664
|
+
val viewHeight = height.coerceAtLeast(1)
|
|
663
665
|
val isTwoUp = displayMode == "twoUp" || displayMode == "twoUpContinuous"
|
|
666
|
+
val isSingle = displayMode == "single"
|
|
664
667
|
val effectiveWidth = if (isTwoUp) viewWidth / 2 else viewWidth
|
|
665
668
|
scope.launch {
|
|
666
669
|
val w = effectiveWidth
|
|
670
|
+
val minSlotHeight = if (isSingle) viewHeight else 0
|
|
667
671
|
val result = withContext(Dispatchers.Default) {
|
|
668
672
|
(0 until renderer.pageCount).map { i ->
|
|
669
673
|
val page = renderer.openPage(i)
|
|
670
674
|
try {
|
|
671
|
-
val
|
|
675
|
+
val naturalH = (w.toFloat() * page.height / page.width).toInt()
|
|
676
|
+
val pageH = if (isSingle) maxOf(naturalH, minSlotHeight) else naturalH
|
|
672
677
|
Triple(
|
|
673
678
|
i,
|
|
674
679
|
pageH,
|
|
675
680
|
Pair(page.width.toFloat(), page.height.toFloat())
|
|
676
681
|
)
|
|
677
682
|
} finally {
|
|
678
|
-
|
|
683
|
+
try {
|
|
684
|
+
page.close()
|
|
685
|
+
} catch (e: Exception) {
|
|
686
|
+
// Renderer may have been closed on main thread (e.g. resetRenderer)
|
|
687
|
+
}
|
|
679
688
|
}
|
|
680
689
|
}
|
|
681
690
|
}
|
|
682
691
|
if (!isActive) return@launch
|
|
683
692
|
withContext(Dispatchers.Main) {
|
|
693
|
+
if (pdfRenderer == null) return@launch
|
|
684
694
|
pageHeights.clear()
|
|
685
695
|
rowHeights.clear()
|
|
686
696
|
pageWidthsPdf.clear()
|
|
@@ -783,10 +793,12 @@ class ExpoPdfReaderView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
783
793
|
}
|
|
784
794
|
return (pageHeights.size - 1).coerceAtLeast(0)
|
|
785
795
|
}
|
|
796
|
+
val viewportCenter = scrollY + scrollView.height / 2
|
|
786
797
|
var offset = 0
|
|
787
798
|
for (i in pageHeights.indices) {
|
|
788
|
-
|
|
789
|
-
|
|
799
|
+
val pageEnd = offset + pageHeights[i]
|
|
800
|
+
if (viewportCenter < pageEnd) return i
|
|
801
|
+
offset = pageEnd + gap
|
|
790
802
|
}
|
|
791
803
|
return (pageHeights.size - 1).coerceAtLeast(0)
|
|
792
804
|
}
|
|
@@ -794,8 +806,12 @@ class ExpoPdfReaderView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
794
806
|
private fun updateVisiblePages() {
|
|
795
807
|
val renderer = pdfRenderer ?: return
|
|
796
808
|
val currentPage = currentPageFromScroll()
|
|
797
|
-
val from = (
|
|
798
|
-
|
|
809
|
+
val (from, to) = if (displayMode == "single") {
|
|
810
|
+
currentPage to currentPage
|
|
811
|
+
} else {
|
|
812
|
+
(currentPage - renderWindowBefore).coerceAtLeast(0) to
|
|
813
|
+
(currentPage + renderWindowAfter).coerceAtMost(renderer.pageCount - 1)
|
|
814
|
+
}
|
|
799
815
|
|
|
800
816
|
for (i in pageViews.indices) {
|
|
801
817
|
if (i in from..to) continue
|
package/package.json
CHANGED