@tobyt/expo-pdf-markup 0.6.1 โ 1.0.0
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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @tobyt/expo-pdf-markup
|
|
2
2
|
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- ea50181: Stable 1.0.0 release โ production-ready API for displaying and annotating PDFs on iOS, Android, and Web.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 906ce89: Fix Android blank PDF and scroll position loss when navigating back to a screen containing the PDF view
|
|
12
|
+
|
|
3
13
|
## 0.6.1
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -9,8 +9,6 @@ An Expo module for displaying and annotating PDFs, with support for iOS, Android
|
|
|
9
9
|
|
|
10
10
|
**[๐ API Reference](https://tobyt42.github.io/expo-pdf-markup/api/)** ยท **[๐ Example App](https://tobyt42.github.io/expo-pdf-markup/example/)**
|
|
11
11
|
|
|
12
|
-
> **Status:** Early development โ actively tested in the [Choir](https://www.thechoirapp.com) app.
|
|
13
|
-
|
|
14
12
|
## Platform support
|
|
15
13
|
|
|
16
14
|
| Platform | PDF rendering | Annotations |
|
|
@@ -152,6 +150,10 @@ npx expo start
|
|
|
152
150
|
</tr>
|
|
153
151
|
</table>
|
|
154
152
|
|
|
153
|
+
## Used by
|
|
154
|
+
|
|
155
|
+
- [Choir](https://www.thechoirapp.com) โ a choir practice app for iOS, Android and Web
|
|
156
|
+
|
|
155
157
|
## License
|
|
156
158
|
|
|
157
159
|
MIT
|
|
@@ -16,6 +16,14 @@ import android.widget.OverScroller
|
|
|
16
16
|
import java.util.UUID
|
|
17
17
|
|
|
18
18
|
class ContinuousPdfView(context: Context) : View(context) {
|
|
19
|
+
data class ScrollState(val panX: Float, val panY: Float, val scale: Float)
|
|
20
|
+
|
|
21
|
+
var pendingScrollRestore: ScrollState? = null
|
|
22
|
+
|
|
23
|
+
fun captureScrollState(): ScrollState? {
|
|
24
|
+
if (pageBitmaps.isEmpty()) return null
|
|
25
|
+
return ScrollState(panX, panY, currentScale)
|
|
26
|
+
}
|
|
19
27
|
private val pageBitmaps = mutableListOf<Bitmap>()
|
|
20
28
|
private val pageYOffsets = mutableListOf<Float>()
|
|
21
29
|
private val pageWidths = mutableListOf<Int>()
|
|
@@ -131,6 +139,15 @@ class ContinuousPdfView(context: Context) : View(context) {
|
|
|
131
139
|
panX = 0f
|
|
132
140
|
panY = 0f
|
|
133
141
|
lastNotifiedPage = -1
|
|
142
|
+
|
|
143
|
+
pendingScrollRestore?.let { state ->
|
|
144
|
+
currentScale = state.scale.coerceIn(minScale, maxScale)
|
|
145
|
+
panX = state.panX
|
|
146
|
+
panY = state.panY
|
|
147
|
+
constrainPan()
|
|
148
|
+
pendingScrollRestore = null
|
|
149
|
+
}
|
|
150
|
+
|
|
134
151
|
invalidate()
|
|
135
152
|
notifyPageChange()
|
|
136
153
|
}
|
|
@@ -24,7 +24,10 @@ class ExpoPdfMarkupView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
24
24
|
private var renderer: PdfRenderer? = null
|
|
25
25
|
private var fileDescriptor: ParcelFileDescriptor? = null
|
|
26
26
|
private var currentSource: String? = null
|
|
27
|
+
private var lastLoadedSource: String? = null
|
|
27
28
|
private var pendingAnnotationsJson: String? = null
|
|
29
|
+
private var sourceToReloadOnAttach: String? = null
|
|
30
|
+
private var savedScrollState: ContinuousPdfView.ScrollState? = null
|
|
28
31
|
var useJsTextDialog: Boolean = false
|
|
29
32
|
|
|
30
33
|
private var pendingTextPage: Int = -1
|
|
@@ -65,6 +68,7 @@ class ExpoPdfMarkupView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
65
68
|
}
|
|
66
69
|
|
|
67
70
|
fun loadPdf(source: String) {
|
|
71
|
+
sourceToReloadOnAttach = null // Explicit load supersedes any pending reload-on-attach
|
|
68
72
|
if (source == currentSource) return
|
|
69
73
|
currentSource = source
|
|
70
74
|
|
|
@@ -79,6 +83,7 @@ class ExpoPdfMarkupView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
79
83
|
fileDescriptor = fd
|
|
80
84
|
val r = PdfRenderer(fd)
|
|
81
85
|
renderer = r
|
|
86
|
+
lastLoadedSource = source
|
|
82
87
|
onLoadComplete(mapOf("pageCount" to r.pageCount))
|
|
83
88
|
if (width > 0) {
|
|
84
89
|
pdfView.loadPages(r, width)
|
|
@@ -188,9 +193,24 @@ class ExpoPdfMarkupView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
188
193
|
|
|
189
194
|
override fun onDetachedFromWindow() {
|
|
190
195
|
super.onDetachedFromWindow()
|
|
196
|
+
// Save the successfully-loaded source before close() so we can reload on re-attach.
|
|
197
|
+
// (currentSource is always null after loadPdf() because close() resets it there.)
|
|
198
|
+
sourceToReloadOnAttach = lastLoadedSource
|
|
199
|
+
lastLoadedSource = null
|
|
200
|
+
savedScrollState = pdfView.captureScrollState()
|
|
191
201
|
close()
|
|
192
202
|
}
|
|
193
203
|
|
|
204
|
+
override fun onAttachedToWindow() {
|
|
205
|
+
super.onAttachedToWindow()
|
|
206
|
+
sourceToReloadOnAttach?.let { source ->
|
|
207
|
+
sourceToReloadOnAttach = null
|
|
208
|
+
pdfView.pendingScrollRestore = savedScrollState
|
|
209
|
+
savedScrollState = null
|
|
210
|
+
loadPdf(source)
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
194
214
|
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
|
195
215
|
super.onSizeChanged(w, h, oldw, oldh)
|
|
196
216
|
if (w > 0 && w != oldw) {
|