@kishannareshpal/expo-pdf 0.1.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.
Files changed (52) hide show
  1. package/.editorconfig +12 -0
  2. package/.eslintrc.js +2 -0
  3. package/.node-version +1 -0
  4. package/.prettierignore +31 -0
  5. package/.prettierrc +8 -0
  6. package/CHANGELOG.md +14 -0
  7. package/CONTRIBUTING.md +271 -0
  8. package/LICENSE +21 -0
  9. package/README.md +243 -0
  10. package/android/build.gradle +55 -0
  11. package/android/src/main/AndroidManifest.xml +9 -0
  12. package/android/src/main/java/com/kishannareshpal/expopdf/.editorconfig +12 -0
  13. package/android/src/main/java/com/kishannareshpal/expopdf/KJExpoPdfModule.kt +60 -0
  14. package/android/src/main/java/com/kishannareshpal/expopdf/KJExpoPdfView.kt +222 -0
  15. package/android/src/main/java/com/kishannareshpal/expopdf/lib/ContentPadding.kt +23 -0
  16. package/android/src/main/java/com/kishannareshpal/expopdf/lib/FitMode.kt +18 -0
  17. package/build/index.d.ts +4 -0
  18. package/build/index.d.ts.map +1 -0
  19. package/build/index.js +5 -0
  20. package/build/index.js.map +1 -0
  21. package/build/pdf-module.d.ts +7 -0
  22. package/build/pdf-module.d.ts.map +1 -0
  23. package/build/pdf-module.js +4 -0
  24. package/build/pdf-module.js.map +1 -0
  25. package/build/pdf-view.d.ts +25 -0
  26. package/build/pdf-view.d.ts.map +1 -0
  27. package/build/pdf-view.js +14 -0
  28. package/build/pdf-view.js.map +1 -0
  29. package/build/types.d.ts +20 -0
  30. package/build/types.d.ts.map +1 -0
  31. package/build/types.js +2 -0
  32. package/build/types.js.map +1 -0
  33. package/build/utils.d.ts +3 -0
  34. package/build/utils.d.ts.map +1 -0
  35. package/build/utils.js +10 -0
  36. package/build/utils.js.map +1 -0
  37. package/bun.lock +2278 -0
  38. package/eslint.config.js +5 -0
  39. package/expo-module.config.json +16 -0
  40. package/ios/KJExpoPdf.podspec +29 -0
  41. package/ios/KJExpoPdfModule.swift +51 -0
  42. package/ios/KJExpoPdfView.swift +242 -0
  43. package/ios/extensions/PdfViewExtensions.swift +94 -0
  44. package/ios/lib/ContentPadding.swift +26 -0
  45. package/ios/lib/FitMode.swift +14 -0
  46. package/package.json +60 -0
  47. package/src/index.ts +4 -0
  48. package/src/pdf-module.ts +8 -0
  49. package/src/pdf-view.tsx +68 -0
  50. package/src/types.ts +16 -0
  51. package/src/utils.ts +12 -0
  52. package/tsconfig.json +9 -0
@@ -0,0 +1,60 @@
1
+ package com.kishannareshpal.expopdf
2
+
3
+ import android.net.Uri
4
+ import androidx.core.net.toUri
5
+ import com.kishannareshpal.expopdf.lib.ContentPadding
6
+ import com.kishannareshpal.expopdf.lib.FitMode
7
+ import expo.modules.kotlin.modules.Module
8
+ import expo.modules.kotlin.modules.ModuleDefinition
9
+ import java.net.URL
10
+ import kotlin.math.roundToInt
11
+
12
+ class KJExpoPdfModule : Module() {
13
+ // Each module class must implement the definition function. The definition consists of components
14
+ // that describes the module's functionality and behavior.
15
+ // See https://docs.expo.dev/modules/module-api for more details about available components.
16
+ override fun definition() = ModuleDefinition {
17
+ // Sets the name of the module that JavaScript code will use to refer to the module. Takes a string as an argument.
18
+ // Can be inferred from module's class name, but it's recommended to set it explicitly for clarity.
19
+ // The module will be accessible from `requireNativeModule('ExpoPdf')` in JavaScript.
20
+ Name("KJExpoPdf")
21
+
22
+ // Enables the module to be used as a native view. Definition components that are accepted as part of
23
+ // the view definition: Prop, Events.
24
+ View(KJExpoPdfView::class) {
25
+ Events("onLoadComplete", "onPageChanged", "onError")
26
+
27
+ Prop("uri") { view: KJExpoPdfView, uri: String? ->
28
+ view.setUri(uri)
29
+ }
30
+
31
+ Prop("password") { view: KJExpoPdfView, password: String? ->
32
+ view.setPassword(password)
33
+ }
34
+
35
+ Prop("pagingEnabled") { view: KJExpoPdfView, enabled: Boolean? ->
36
+ view.setPagingEnabled(enabled)
37
+ }
38
+
39
+ Prop("disableDoubleTapToZoom") { view: KJExpoPdfView, disabled: Boolean? ->
40
+ view.setDoubleTapZoomEnabled(disabled != true)
41
+ }
42
+
43
+ Prop("horizontal") { view: KJExpoPdfView, enabled: Boolean? ->
44
+ view.setHorizontalModeEnabled(enabled)
45
+ }
46
+
47
+ Prop("pageGap") { view: KJExpoPdfView, gap: Float? ->
48
+ view.setPageGap(gap?.roundToInt())
49
+ }
50
+
51
+ Prop("contentPadding") { view: KJExpoPdfView, contentPadding: ContentPadding? ->
52
+ view.setContentPadding(contentPadding?.toRect())
53
+ }
54
+
55
+ Prop("fitMode") { view: KJExpoPdfView, mode: FitMode? ->
56
+ view.setFitMode(mode)
57
+ }
58
+ }
59
+ }
60
+ }
@@ -0,0 +1,222 @@
1
+ package com.kishannareshpal.expopdf
2
+
3
+ import android.content.Context
4
+ import android.graphics.Color
5
+ import android.graphics.Rect
6
+ import android.net.Uri
7
+ import expo.modules.kotlin.AppContext
8
+ import expo.modules.kotlin.views.ExpoView
9
+ import com.github.barteksc.pdfviewer.PDFView
10
+ import expo.modules.kotlin.viewevent.EventDispatcher
11
+ import java.io.FileNotFoundException
12
+ import androidx.core.net.toUri
13
+ import com.github.barteksc.pdfviewer.util.FitPolicy
14
+ import com.kishannareshpal.expopdf.lib.FitMode
15
+
16
+ // TODO: Refresh the content on prop change
17
+
18
+ class KJExpoPdfView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
19
+ companion object {
20
+ internal val DEFAULT_PAGING_ENABLED = false
21
+ internal val DEFAULT_DOUBLE_TAP_ZOOM_ENABLED = true
22
+ internal val DEFAULT_HORIZONTAL_MODE_ENABLED = false
23
+ internal val DEFAULT_PAGE_GAP = 0
24
+ internal val DEFAULT_CONTENT_PADDING = Rect(0, 0, 0, 0)
25
+ internal val DEFAULT_FIT_MODE = FitMode.both
26
+ }
27
+
28
+ private val onLoadComplete by EventDispatcher()
29
+ private val onPageChanged by EventDispatcher()
30
+ private val onError by EventDispatcher()
31
+
32
+ internal enum class ErrorCode(val code: String) {
33
+ invalidUri("invalid_uri"),
34
+ invalidDocument("invalid_document"),
35
+ passwordRequired("password_required"),
36
+ passwordIncorrect("password_incorrect")
37
+ }
38
+
39
+ private var uri: Uri? = null
40
+ private var password: String? = null
41
+ private var isPagingEnabled: Boolean = DEFAULT_PAGING_ENABLED
42
+ private var isDoubleTapZoomEnabled: Boolean = DEFAULT_DOUBLE_TAP_ZOOM_ENABLED
43
+ private var isHorizontalModeEnabled: Boolean = DEFAULT_HORIZONTAL_MODE_ENABLED
44
+ private var pageGap: Int = DEFAULT_PAGE_GAP
45
+ private var contentPadding: Rect = DEFAULT_CONTENT_PADDING
46
+ private var fitMode: FitMode = DEFAULT_FIT_MODE
47
+
48
+ internal val pdfView = PDFView(context, null).apply {
49
+ layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
50
+ }
51
+
52
+ init {
53
+ // Set the primitive PdfView's content background to transparent so that it inherits
54
+ // the color from the React Native view (ExpoView), as defined by the
55
+ // style prop in the component (`style={{ backgroundColor: '#eee' }}`).
56
+ this.pdfView.setBackgroundColor(Color.TRANSPARENT)
57
+
58
+ addView(this.pdfView)
59
+ }
60
+
61
+ override fun onDetachedFromWindow() {
62
+ super.onDetachedFromWindow()
63
+ this.pdfView.recycle()
64
+ }
65
+
66
+ fun setUri(uri: String?) {
67
+ if (uri == null) {
68
+ this.reportError(ErrorCode.invalidUri, "No URI provided")
69
+ return
70
+ }
71
+
72
+ try {
73
+ this.uri = uri.toUri()
74
+ } catch (_: Exception) {
75
+ this.reportError(ErrorCode.invalidUri, "The provided URI is invalid")
76
+ }
77
+
78
+ this.reloadPdf()
79
+ }
80
+
81
+ fun setPassword(password: String?) {
82
+ this.password = password;
83
+ this.reloadPdf()
84
+ }
85
+
86
+ fun setPagingEnabled(enabled: Boolean?) {
87
+ this.isPagingEnabled = enabled ?: DEFAULT_PAGING_ENABLED
88
+ this.reloadPdf()
89
+ }
90
+
91
+ fun setDoubleTapZoomEnabled(enabled: Boolean?) {
92
+ this.isDoubleTapZoomEnabled = enabled ?: DEFAULT_DOUBLE_TAP_ZOOM_ENABLED
93
+ this.pdfView.enableDoubletap(this.isDoubleTapZoomEnabled)
94
+ }
95
+
96
+ fun setHorizontalModeEnabled(enabled: Boolean?) {
97
+ this.isHorizontalModeEnabled = enabled ?: DEFAULT_HORIZONTAL_MODE_ENABLED
98
+ this.reloadPdf()
99
+ }
100
+
101
+ fun setPageGap(pageGap: Int?) {
102
+ this.pageGap = pageGap ?: DEFAULT_PAGE_GAP
103
+ this.reloadPdf()
104
+ }
105
+
106
+ fun setContentPadding(rect: Rect?) {
107
+ this.contentPadding = if (rect != null) {
108
+ Rect(rect.left, rect.top, rect.right, rect.bottom)
109
+ } else {
110
+ DEFAULT_CONTENT_PADDING
111
+ }
112
+
113
+ this.reloadPdf()
114
+ }
115
+
116
+ fun setFitMode(mode: FitMode?) {
117
+ this.fitMode = mode ?: DEFAULT_FIT_MODE
118
+ this.reloadPdf()
119
+ }
120
+
121
+ private fun reloadPdf() {
122
+ if (!this.pdfView.isRecycled) {
123
+ this.pdfView.recycle()
124
+ }
125
+
126
+ val currentUri = this.uri ?: return
127
+
128
+ val pdfBuilder = try {
129
+ if (currentUri.scheme == "content") {
130
+ val contentResolver = context.contentResolver
131
+ val inputStream = contentResolver.openInputStream(currentUri)
132
+ ?: throw FileNotFoundException("Could not open input stream for the provided URI: $currentUri")
133
+ this.pdfView.fromStream(inputStream)
134
+ } else {
135
+ this.pdfView.fromUri(currentUri)
136
+ }
137
+ } catch (e: Exception) {
138
+ this.reportError(ErrorCode.invalidDocument, e.message.toString())
139
+ return
140
+ }
141
+
142
+ pdfBuilder
143
+ .pageFitPolicy(this.fitMode.toFitPolicy())
144
+ .enableDoubletap(this.isDoubleTapZoomEnabled)
145
+ .swipeHorizontal(this.isHorizontalModeEnabled)
146
+ .spacing(this.pageGap)
147
+ .contentPadding(
148
+ this.contentPadding.left,
149
+ this.contentPadding.top,
150
+ this.contentPadding.right,
151
+ this.contentPadding.bottom
152
+ )
153
+ .onLoad { pageCount ->
154
+ this.onLoadComplete(
155
+ mapOf(
156
+ "pageCount" to pageCount
157
+ )
158
+ )
159
+ }
160
+ .onLoad {
161
+ this.onLoadComplete(
162
+ mapOf(
163
+ "pageCount" to this.pdfView.pageCount
164
+ )
165
+ );
166
+ }
167
+ .onPageChange { pageIndex, pageCount ->
168
+ this.onPageChanged(
169
+ mapOf(
170
+ "pageIndex" to pageIndex,
171
+ "pageCount" to pageCount
172
+ )
173
+ )
174
+ }
175
+
176
+ post {
177
+ pdfBuilder
178
+ .onError { e ->
179
+ // PDF fails to load if it's NOT pw protected AND a password is provided.
180
+ // - For this reason, the first time we load the pdf, we check if we have received the pw
181
+ // required error and retry loading the PDF with password provided
182
+ if (e.message.toString().lowercase().contains("password required")) {
183
+ if (this.password == null) {
184
+ this.reportError(
185
+ ErrorCode.passwordRequired,
186
+ "PDF requires a password, but no password was provided"
187
+ )
188
+ } else {
189
+ // Password has been provided, so re-attempt a load
190
+ pdfBuilder
191
+ .password(this.password)
192
+ .onError {
193
+ this.reportError(
194
+ ErrorCode.passwordIncorrect,
195
+ "The provided password was incorrect"
196
+ )
197
+ }
198
+ .load()
199
+ }
200
+ }
201
+ }
202
+ .load()
203
+ }
204
+ }
205
+
206
+ override fun onAttachedToWindow() {
207
+ super.onAttachedToWindow()
208
+
209
+ this.pdfView.isRecycled.let {
210
+ this.reloadPdf()
211
+ }
212
+ }
213
+
214
+ private fun reportError(error: ErrorCode, message: String) {
215
+ this.onError(
216
+ mapOf(
217
+ "code" to error.code,
218
+ "message" to message
219
+ )
220
+ )
221
+ }
222
+ }
@@ -0,0 +1,23 @@
1
+ package com.kishannareshpal.expopdf.lib
2
+
3
+ import android.graphics.Rect
4
+ import expo.modules.kotlin.records.Field
5
+ import expo.modules.kotlin.records.Record
6
+
7
+ class ContentPadding: Record {
8
+ @Field
9
+ val left: Int = 0
10
+
11
+ @Field
12
+ val top: Int = 0
13
+
14
+ @Field
15
+ val right: Int = 0
16
+
17
+ @Field
18
+ val bottom: Int = 0
19
+
20
+ fun toRect(): Rect {
21
+ return Rect(this.left, this.top, this.right, this.bottom)
22
+ }
23
+ }
@@ -0,0 +1,18 @@
1
+ package com.kishannareshpal.expopdf.lib
2
+
3
+ import com.github.barteksc.pdfviewer.util.FitPolicy
4
+ import expo.modules.kotlin.types.Enumerable
5
+
6
+ enum class FitMode(val value: String) : Enumerable {
7
+ width("width"),
8
+ height("height"),
9
+ both("both");
10
+
11
+ fun toFitPolicy(): FitPolicy {
12
+ return when (this) {
13
+ width -> FitPolicy.WIDTH
14
+ height -> FitPolicy.HEIGHT
15
+ both -> FitPolicy.BOTH
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,4 @@
1
+ export { default } from './pdf-module';
2
+ export { PdfView } from './pdf-view';
3
+ export * from './types';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,cAAc,SAAS,CAAC"}
package/build/index.js ADDED
@@ -0,0 +1,5 @@
1
+ // Reexport the native module
2
+ export { default } from './pdf-module';
3
+ export { PdfView } from './pdf-view';
4
+ export * from './types';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,cAAc,SAAS,CAAC","sourcesContent":["// Reexport the native module\nexport { default } from './pdf-module';\nexport { PdfView } from './pdf-view';\nexport * from './types';\n"]}
@@ -0,0 +1,7 @@
1
+ import { NativeModule } from 'expo';
2
+ type PdfModuleEvents = {};
3
+ declare class PdfModule extends NativeModule<PdfModuleEvents> {
4
+ }
5
+ declare const _default: PdfModule;
6
+ export default _default;
7
+ //# sourceMappingURL=pdf-module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdf-module.d.ts","sourceRoot":"","sources":["../src/pdf-module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAuB,MAAM,MAAM,CAAC;AAEzD,KAAK,eAAe,GAAG,EAAE,CAAA;AAEzB,OAAO,OAAO,SAAU,SAAQ,YAAY,CAAC,eAAe,CAAC;CAAI;;AAGjE,wBAA2D"}
@@ -0,0 +1,4 @@
1
+ import { requireNativeModule } from 'expo';
2
+ // This call loads the native module object from the JSI.
3
+ export default requireNativeModule('KJExpoPdf');
4
+ //# sourceMappingURL=pdf-module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdf-module.js","sourceRoot":"","sources":["../src/pdf-module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,mBAAmB,EAAE,MAAM,MAAM,CAAC;AAMzD,yDAAyD;AACzD,eAAe,mBAAmB,CAAY,WAAW,CAAC,CAAC","sourcesContent":["import { NativeModule, requireNativeModule } from 'expo';\n\ntype PdfModuleEvents = {}\n\ndeclare class PdfModule extends NativeModule<PdfModuleEvents> { }\n\n// This call loads the native module object from the JSI.\nexport default requireNativeModule<PdfModule>('KJExpoPdf');\n"]}
@@ -0,0 +1,25 @@
1
+ import * as React from 'react';
2
+ import { ContentPadding, FitMode, OnErrorEventPayload, OnLoadCompleteEventPayload, OnPageChangedEventPayload } from './types';
3
+ import { StyleProp, ViewStyle } from 'react-native';
4
+ type BaseProps = {
5
+ style?: StyleProp<ViewStyle>;
6
+ /**
7
+ * The file URI. Accepts a remote resource (e.g. via HTTPs) or a local file path (e.g. file:///)
8
+ */
9
+ uri: string;
10
+ password?: string;
11
+ pagingEnabled?: boolean;
12
+ disableDoubleTapToZoom?: boolean;
13
+ horizontal?: boolean;
14
+ pageGap?: number;
15
+ contentPadding?: ContentPadding;
16
+ fitMode?: FitMode;
17
+ };
18
+ export type PdfViewProps = BaseProps & {
19
+ onLoadComplete?: (params: OnLoadCompleteEventPayload) => void;
20
+ onPageChanged?: (params: OnPageChangedEventPayload) => void;
21
+ onError?: (params: OnErrorEventPayload) => void;
22
+ };
23
+ export declare const PdfView: ({ style, onLoadComplete, onError, onPageChanged, ...props }: PdfViewProps) => React.JSX.Element;
24
+ export {};
25
+ //# sourceMappingURL=pdf-view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdf-view.d.ts","sourceRoot":"","sources":["../src/pdf-view.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAC9H,OAAO,EAAwB,SAAS,EAAc,SAAS,EAAE,MAAM,cAAc,CAAC;AAGtF,KAAK,SAAS,GAAG;IACf,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,cAAc,CAAC,EAAE,cAAc,CAAA;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAYD,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG;IACrC,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,0BAA0B,KAAK,IAAI,CAAC;IAC9D,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,yBAAyB,KAAK,IAAI,CAAC;IAC5D,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,CAAA;CAChD,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,6DAMrB,YAAY,sBAiBd,CAAA"}
@@ -0,0 +1,14 @@
1
+ import { requireNativeView } from 'expo';
2
+ import * as React from 'react';
3
+ import { StyleSheet } from 'react-native';
4
+ import { forwardNativeEventTo } from './utils';
5
+ const NativePdfView = requireNativeView('KJExpoPdf');
6
+ export const PdfView = ({ style, onLoadComplete, onError, onPageChanged, ...props }) => {
7
+ return (<NativePdfView style={[styles.container, style]} uri={props.uri} disableDoubleTapToZoom={props.disableDoubleTapToZoom} horizontal={props.horizontal} pageGap={props.pageGap} pagingEnabled={props.pagingEnabled} password={props.password} contentPadding={props.contentPadding} fitMode={props.fitMode} onLoadComplete={forwardNativeEventTo(onLoadComplete)} onPageChanged={forwardNativeEventTo(onPageChanged)} onError={forwardNativeEventTo(onError)}/>);
8
+ };
9
+ const styles = StyleSheet.create({
10
+ container: {
11
+ backgroundColor: '#eeeeee'
12
+ }
13
+ });
14
+ //# sourceMappingURL=pdf-view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdf-view.js","sourceRoot":"","sources":["../src/pdf-view.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AACzC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAmC,UAAU,EAAa,MAAM,cAAc,CAAC;AACtF,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAuB/C,MAAM,aAAa,GAA4C,iBAAiB,CAAC,WAAW,CAAC,CAAC;AAU9F,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,EACtB,KAAK,EACL,cAAc,EACd,OAAO,EACP,aAAa,EACb,GAAG,KAAK,EACK,EAAE,EAAE;IACjB,OAAO,CACL,CAAC,aAAa,CACZ,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CACjC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CACf,sBAAsB,CAAC,CAAC,KAAK,CAAC,sBAAsB,CAAC,CACrD,UAAU,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAC7B,OAAO,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CACvB,aAAa,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CACnC,QAAQ,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CACzB,cAAc,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CACrC,OAAO,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CACvB,cAAc,CAAC,CAAC,oBAAoB,CAAC,cAAc,CAAC,CAAC,CACrD,aAAa,CAAC,CAAC,oBAAoB,CAAC,aAAa,CAAC,CAAC,CACnD,OAAO,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,EACvC,CACH,CAAA;AACH,CAAC,CAAA;AAED,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IAC/B,SAAS,EAAE;QACT,eAAe,EAAE,SAAS;KAC3B;CACF,CAAC,CAAA","sourcesContent":["import { requireNativeView } from 'expo';\nimport * as React from 'react';\n\nimport { ContentPadding, FitMode, OnErrorEventPayload, OnLoadCompleteEventPayload, OnPageChangedEventPayload } from './types';\nimport { NativeSyntheticEvent, StyleProp, StyleSheet, ViewStyle } from 'react-native';\nimport { forwardNativeEventTo } from './utils';\n\ntype BaseProps = {\n style?: StyleProp<ViewStyle>;\n /**\n * The file URI. Accepts a remote resource (e.g. via HTTPs) or a local file path (e.g. file:///)\n */\n uri: string;\n password?: string;\n pagingEnabled?: boolean\n disableDoubleTapToZoom?: boolean\n horizontal?: boolean\n pageGap?: number\n contentPadding?: ContentPadding\n fitMode?: FitMode\n}\n\ntype NativePdfViewProps = BaseProps & {\n onLoadComplete?: (event: NativeSyntheticEvent<OnLoadCompleteEventPayload>) => void;\n onPageChanged?: (event: NativeSyntheticEvent<OnPageChangedEventPayload>) => void;\n onError?: (event: NativeSyntheticEvent<OnErrorEventPayload>) => void;\n};\n\nconst NativePdfView: React.ComponentType<NativePdfViewProps> = requireNativeView('KJExpoPdf');\n\n// -----------\n\nexport type PdfViewProps = BaseProps & {\n onLoadComplete?: (params: OnLoadCompleteEventPayload) => void,\n onPageChanged?: (params: OnPageChangedEventPayload) => void,\n onError?: (params: OnErrorEventPayload) => void\n};\n\nexport const PdfView = ({\n style,\n onLoadComplete,\n onError,\n onPageChanged,\n ...props\n}: PdfViewProps) => {\n return (\n <NativePdfView\n style={[styles.container, style]}\n uri={props.uri}\n disableDoubleTapToZoom={props.disableDoubleTapToZoom}\n horizontal={props.horizontal}\n pageGap={props.pageGap}\n pagingEnabled={props.pagingEnabled}\n password={props.password}\n contentPadding={props.contentPadding}\n fitMode={props.fitMode}\n onLoadComplete={forwardNativeEventTo(onLoadComplete)}\n onPageChanged={forwardNativeEventTo(onPageChanged)}\n onError={forwardNativeEventTo(onError)}\n />\n )\n}\n\nconst styles = StyleSheet.create({\n container: {\n backgroundColor: '#eeeeee'\n }\n})\n"]}
@@ -0,0 +1,20 @@
1
+ export type OnLoadCompleteEventPayload = {
2
+ pageCount: number;
3
+ };
4
+ export type OnPageChangedEventPayload = {
5
+ pageIndex: number;
6
+ pageCount: number;
7
+ };
8
+ export type ErrorCode = 'no_url' | 'invalid_url' | 'invalid_document';
9
+ export type OnErrorEventPayload = {
10
+ code: ErrorCode;
11
+ message: string;
12
+ };
13
+ export type ContentPadding = {
14
+ top?: number;
15
+ right?: number;
16
+ bottom?: number;
17
+ left?: number;
18
+ };
19
+ export type FitMode = 'width' | 'height' | 'both';
20
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,0BAA0B,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAAA;AAE9D,MAAM,MAAM,yBAAyB,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAA;AAEhF,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,aAAa,GAAG,kBAAkB,CAAA;AAErE,MAAM,MAAM,mBAAmB,GAAG;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAA;AAEtE,MAAM,MAAM,cAAc,GAAG;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAA;AAED,MAAM,MAAM,OAAO,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC"}
package/build/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export type OnLoadCompleteEventPayload = { pageCount: number }\n\nexport type OnPageChangedEventPayload = { pageIndex: number, pageCount: number }\n\nexport type ErrorCode = 'no_url' | 'invalid_url' | 'invalid_document'\n\nexport type OnErrorEventPayload = { code: ErrorCode, message: string }\n\nexport type ContentPadding = {\n top?: number;\n right?: number;\n bottom?: number;\n left?: number;\n}\n\nexport type FitMode = 'width' | 'height' | 'both';\n"]}
@@ -0,0 +1,3 @@
1
+ import { NativeSyntheticEvent } from 'react-native';
2
+ export declare const forwardNativeEventTo: <T>(handler?: (payload: T) => void) => ((event: NativeSyntheticEvent<T>) => void) | undefined;
3
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpD,eAAO,MAAM,oBAAoB,GAAI,CAAC,EAAG,UAAU,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI,cAGpD,oBAAoB,CAAC,CAAC,CAAC,sBAMzC,CAAA"}
package/build/utils.js ADDED
@@ -0,0 +1,10 @@
1
+ export const forwardNativeEventTo = (handler) => {
2
+ if (!handler)
3
+ return undefined;
4
+ return (event) => {
5
+ // Native event includes a "target" property that I think corresponds to the view tag, but this is not needed in my lib
6
+ delete event.nativeEvent.target;
7
+ handler(event.nativeEvent);
8
+ };
9
+ };
10
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAK,OAA8B,EAAE,EAAE;IACvE,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IAE/B,OAAO,CAAC,KAA8B,EAAE,EAAE;QACtC,uHAAuH;QACvH,OAAQ,KAAK,CAAC,WAAmB,CAAC,MAAM,CAAC;QAEzC,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAC/B,CAAC,CAAC;AACN,CAAC,CAAA","sourcesContent":["import { NativeSyntheticEvent } from 'react-native';\n\nexport const forwardNativeEventTo = <T,>(handler?: (payload: T) => void) => {\n if (!handler) return undefined;\n\n return (event: NativeSyntheticEvent<T>) => {\n // Native event includes a \"target\" property that I think corresponds to the view tag, but this is not needed in my lib\n delete (event.nativeEvent as any).target;\n\n handler(event.nativeEvent);\n };\n}"]}