react-native-pdfrender 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.
- package/README.md +306 -0
- package/android/build.gradle +76 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/pdfrender/ComposeRenderer.kt +85 -0
- package/android/src/main/java/com/pdfrender/PdfCacheManager.kt +150 -0
- package/android/src/main/java/com/pdfrender/PdfConstants.kt +63 -0
- package/android/src/main/java/com/pdfrender/PdfIconComponents.kt +275 -0
- package/android/src/main/java/com/pdfrender/PdfRenderingLogic.kt +325 -0
- package/android/src/main/java/com/pdfrender/PdfUIComponents.kt +335 -0
- package/android/src/main/java/com/pdfrender/PdfViewPackage.kt +32 -0
- package/android/src/main/java/com/pdfrender/PdfViewerActivity.kt +3467 -0
- package/android/src/main/java/com/pdfrender/PdfViewerFabricManager.kt +244 -0
- package/android/src/main/java/com/pdfrender/PdfViewerFragment.kt +129 -0
- package/android/src/main/java/com/pdfrender/PdfViewerTurboModule.kt +158 -0
- package/android/src/main/java/com/pdfrender/events/FullScreenChangeEvent.kt +26 -0
- package/android/src/main/java/com/pdfrender/events/LeftScreenChangeEvent.kt +22 -0
- package/android/src/main/java/com/pdfrender/events/RightScreenChangeEvent.kt +22 -0
- package/android/src/main/java/com/pdfrender/events/ZoomChangeEvent.kt +22 -0
- package/ios/PdfCacheManager.swift +44 -0
- package/ios/PdfConstants.swift +38 -0
- package/ios/PdfPageView.swift +121 -0
- package/ios/PdfRenderingLogic.swift +107 -0
- package/ios/PdfToolbarView.swift +158 -0
- package/ios/PdfViewerComponentView.mm +194 -0
- package/ios/PdfViewerTurboModule.mm +186 -0
- package/ios/PdfViewerTurboModuleImpl.swift +141 -0
- package/ios/PdfViewerView.swift +268 -0
- package/ios/PdfViewerViewController.swift +109 -0
- package/lib/commonjs/PdfViewerView.js +105 -0
- package/lib/commonjs/PdfViewerView.js.map +1 -0
- package/lib/commonjs/index.js +28 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/specs/NativePdfViewerComponent.js +27 -0
- package/lib/commonjs/specs/NativePdfViewerComponent.js.map +1 -0
- package/lib/commonjs/specs/NativePdfViewerModule.js +21 -0
- package/lib/commonjs/specs/NativePdfViewerModule.js.map +1 -0
- package/lib/commonjs/usePdfViewer.js +65 -0
- package/lib/commonjs/usePdfViewer.js.map +1 -0
- package/lib/module/PdfViewerView.js +99 -0
- package/lib/module/PdfViewerView.js.map +1 -0
- package/lib/module/index.js +8 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/specs/NativePdfViewerComponent.js +26 -0
- package/lib/module/specs/NativePdfViewerComponent.js.map +1 -0
- package/lib/module/specs/NativePdfViewerModule.js +18 -0
- package/lib/module/specs/NativePdfViewerModule.js.map +1 -0
- package/lib/module/usePdfViewer.js +60 -0
- package/lib/module/usePdfViewer.js.map +1 -0
- package/lib/typescript/PdfViewerView.d.ts +58 -0
- package/lib/typescript/PdfViewerView.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +7 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/specs/NativePdfViewerComponent.d.ts +59 -0
- package/lib/typescript/specs/NativePdfViewerComponent.d.ts.map +1 -0
- package/lib/typescript/specs/NativePdfViewerModule.d.ts +47 -0
- package/lib/typescript/specs/NativePdfViewerModule.d.ts.map +1 -0
- package/lib/typescript/usePdfViewer.d.ts +45 -0
- package/lib/typescript/usePdfViewer.d.ts.map +1 -0
- package/package.json +109 -0
- package/react-native-pdfrender.podspec +35 -0
- package/react-native.config.js +11 -0
- package/src/PdfViewerView.tsx +159 -0
- package/src/index.tsx +10 -0
- package/src/specs/NativePdfViewerComponent.ts +94 -0
- package/src/specs/NativePdfViewerModule.ts +58 -0
- package/src/usePdfViewer.ts +102 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import UIKit
|
|
2
|
+
|
|
3
|
+
/// UIViewController host for PdfViewerView.
|
|
4
|
+
///
|
|
5
|
+
/// Equivalent to PdfViewerFragment on Android — Activity-independent.
|
|
6
|
+
/// Can be presented modally (full-screen or sheet) or pushed onto a
|
|
7
|
+
/// UINavigationController stack. The caller receives callbacks via
|
|
8
|
+
/// the @objc closure properties.
|
|
9
|
+
///
|
|
10
|
+
/// Usage:
|
|
11
|
+
/// let vc = PdfViewerViewController.make(
|
|
12
|
+
/// uri: "file:///path/to/book.pdf",
|
|
13
|
+
/// pageIndex: 0,
|
|
14
|
+
/// defaultZoom: 1.5
|
|
15
|
+
/// )
|
|
16
|
+
/// vc.onDismiss = { print("closed") }
|
|
17
|
+
/// present(vc, animated: true)
|
|
18
|
+
@objc(PdfViewerViewController)
|
|
19
|
+
final class PdfViewerViewController: UIViewController {
|
|
20
|
+
|
|
21
|
+
// MARK: - Factory
|
|
22
|
+
|
|
23
|
+
@objc static func make(
|
|
24
|
+
uri: String,
|
|
25
|
+
pageIndex: Int,
|
|
26
|
+
defaultZoom: Float,
|
|
27
|
+
isFullScreen: Bool = false
|
|
28
|
+
) -> PdfViewerViewController {
|
|
29
|
+
let vc = PdfViewerViewController()
|
|
30
|
+
vc.initialURI = uri
|
|
31
|
+
vc.initialPageIndex = pageIndex
|
|
32
|
+
vc.initialZoom = CGFloat(defaultZoom)
|
|
33
|
+
vc.startFullScreen = isFullScreen
|
|
34
|
+
return vc
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// MARK: - @objc callbacks (set by TurboModule)
|
|
38
|
+
|
|
39
|
+
@objc var onFullScreenChange: ((Bool) -> Void)?
|
|
40
|
+
@objc var onZoomChange: ((Float) -> Void)?
|
|
41
|
+
@objc var onDismiss: (() -> Void)?
|
|
42
|
+
|
|
43
|
+
// MARK: - Private config
|
|
44
|
+
|
|
45
|
+
private var initialURI: String = ""
|
|
46
|
+
private var initialPageIndex: Int = 0
|
|
47
|
+
private var initialZoom: CGFloat = PdfConstants.defaultZoom
|
|
48
|
+
private var startFullScreen: Bool = false
|
|
49
|
+
private var pdfView: PdfViewerView!
|
|
50
|
+
|
|
51
|
+
// MARK: - Status bar
|
|
52
|
+
|
|
53
|
+
override var preferredStatusBarStyle: UIStatusBarStyle {
|
|
54
|
+
pdfView?.isFullScreen == true ? .lightContent : .darkContent
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// MARK: - Lifecycle
|
|
58
|
+
|
|
59
|
+
override func viewDidLoad() {
|
|
60
|
+
super.viewDidLoad()
|
|
61
|
+
view.backgroundColor = .black
|
|
62
|
+
setupPdfView()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
override func viewWillDisappear(_ animated: Bool) {
|
|
66
|
+
super.viewWillDisappear(animated)
|
|
67
|
+
if isMovingFromParent || isBeingDismissed {
|
|
68
|
+
onDismiss?()
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// MARK: - Setup
|
|
73
|
+
|
|
74
|
+
private func setupPdfView() {
|
|
75
|
+
pdfView = PdfViewerView(frame: view.bounds)
|
|
76
|
+
pdfView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
77
|
+
pdfView.delegate = self
|
|
78
|
+
pdfView.defaultZoom = initialZoom
|
|
79
|
+
pdfView.initialPageIndex = initialPageIndex
|
|
80
|
+
pdfView.isFullScreen = startFullScreen
|
|
81
|
+
// Setting pdfUri LAST triggers the document load
|
|
82
|
+
pdfView.pdfUri = initialURI
|
|
83
|
+
view.addSubview(pdfView)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// MARK: - PdfViewerViewDelegate
|
|
88
|
+
|
|
89
|
+
extension PdfViewerViewController: PdfViewerViewDelegate {
|
|
90
|
+
|
|
91
|
+
func pdfViewerView(_ view: PdfViewerView, didChangeFullScreen isFullScreen: Bool) {
|
|
92
|
+
setNeedsStatusBarAppearanceUpdate()
|
|
93
|
+
onFullScreenChange?(isFullScreen)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
func pdfViewerView(_ view: PdfViewerView, didChangeZoom zoomPercentage: Float) {
|
|
97
|
+
onZoomChange?(zoomPercentage)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
func pdfViewerViewDidRequestDismiss(_ view: PdfViewerView) {
|
|
101
|
+
dismiss(animated: true) { [weak self] in
|
|
102
|
+
self?.onDismiss?()
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
func pdfViewerView(_ view: PdfViewerView, didChangeToRightScreen isRight: Bool) {
|
|
107
|
+
// Reserved for split-view use
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.PdfViewerView = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
var _NativePdfViewerComponent = _interopRequireDefault(require("./specs/NativePdfViewerComponent"));
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
13
|
+
/**
|
|
14
|
+
* PdfViewerView — public React component for the embedded PDF viewer.
|
|
15
|
+
*
|
|
16
|
+
* Usage:
|
|
17
|
+
* import { PdfViewerView } from './PdfViewerView';
|
|
18
|
+
*
|
|
19
|
+
* <PdfViewerView
|
|
20
|
+
* uri="file:///path/to/book.pdf"
|
|
21
|
+
* initialPage={0}
|
|
22
|
+
* defaultZoom={1.5}
|
|
23
|
+
* style={{ flex: 1 }}
|
|
24
|
+
* onZoomChange={(pct) => console.log('zoom', pct)}
|
|
25
|
+
* onFullScreenChange={(fs) => setFullScreen(fs)}
|
|
26
|
+
* />
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
// ── Public handle (imperative API via ref) ────────────────────────────────────
|
|
30
|
+
|
|
31
|
+
// ── Public props ──────────────────────────────────────────────────────────────
|
|
32
|
+
|
|
33
|
+
// ── Component ─────────────────────────────────────────────────────────────────
|
|
34
|
+
|
|
35
|
+
const PdfViewerView = exports.PdfViewerView = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
36
|
+
uri,
|
|
37
|
+
initialPage = -1,
|
|
38
|
+
defaultZoom = 1,
|
|
39
|
+
isFullScreen = false,
|
|
40
|
+
rightLayout = false,
|
|
41
|
+
maxWidth,
|
|
42
|
+
screenWidthPercentage = 100,
|
|
43
|
+
icons,
|
|
44
|
+
iconSize = 40,
|
|
45
|
+
backButtonText,
|
|
46
|
+
headerText,
|
|
47
|
+
style,
|
|
48
|
+
onFullScreenChange,
|
|
49
|
+
onLeftScreenChange,
|
|
50
|
+
onRightScreenChange,
|
|
51
|
+
onZoomChange
|
|
52
|
+
}, ref) => {
|
|
53
|
+
(0, _react.useImperativeHandle)(ref, () => ({}));
|
|
54
|
+
|
|
55
|
+
// Resolve icon assets to URI strings the native layer can load.
|
|
56
|
+
// Image.resolveAssetSource handles both require() numbers and plain strings.
|
|
57
|
+
const resolvedIcons = (0, _react.useMemo)(() => {
|
|
58
|
+
const resolve = src => {
|
|
59
|
+
if (src == null) return undefined;
|
|
60
|
+
if (typeof src === 'string') return src;
|
|
61
|
+
try {
|
|
62
|
+
return _reactNative.Image.resolveAssetSource(src).uri;
|
|
63
|
+
} catch {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
zoomIn: resolve(icons?.zoomIn),
|
|
69
|
+
zoomOut: resolve(icons?.zoomOut),
|
|
70
|
+
fullScreen: resolve(icons?.fullScreen),
|
|
71
|
+
minimizeScreen: resolve(icons?.minimizeScreen),
|
|
72
|
+
leftLayout: resolve(icons?.leftLayout),
|
|
73
|
+
rightLayout: resolve(icons?.rightLayout)
|
|
74
|
+
};
|
|
75
|
+
}, [icons]);
|
|
76
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_NativePdfViewerComponent.default, {
|
|
77
|
+
style: [styles.fill, style],
|
|
78
|
+
pdfUri: uri,
|
|
79
|
+
initialPageIndex: initialPage,
|
|
80
|
+
defaultZoom: defaultZoom,
|
|
81
|
+
isFullScreen: isFullScreen,
|
|
82
|
+
rightLayout: rightLayout,
|
|
83
|
+
maxWidth: maxWidth,
|
|
84
|
+
screenWidthPercentage: screenWidthPercentage,
|
|
85
|
+
iconZoomIn: resolvedIcons.zoomIn,
|
|
86
|
+
iconZoomOut: resolvedIcons.zoomOut,
|
|
87
|
+
iconFullScreen: resolvedIcons.fullScreen,
|
|
88
|
+
iconMinimizeScreen: resolvedIcons.minimizeScreen,
|
|
89
|
+
iconLeftLayout: resolvedIcons.leftLayout,
|
|
90
|
+
iconRightLayout: resolvedIcons.rightLayout,
|
|
91
|
+
iconSize: iconSize,
|
|
92
|
+
backButtonText: backButtonText,
|
|
93
|
+
headerText: headerText,
|
|
94
|
+
onFullScreenChange: e => onFullScreenChange?.(e.nativeEvent.isFullScreen),
|
|
95
|
+
onLeftScreenChange: e => onLeftScreenChange?.(e.nativeEvent.isLeftScreen),
|
|
96
|
+
onRightScreenChange: e => onRightScreenChange?.(e.nativeEvent.isRightScreen),
|
|
97
|
+
onZoomChange: e => onZoomChange?.(e.nativeEvent.zoomPercentage)
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
const styles = _reactNative.StyleSheet.create({
|
|
101
|
+
fill: {
|
|
102
|
+
flex: 1
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
//# sourceMappingURL=PdfViewerView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_NativePdfViewerComponent","_interopRequireDefault","_jsxRuntime","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","PdfViewerView","exports","forwardRef","uri","initialPage","defaultZoom","isFullScreen","rightLayout","maxWidth","screenWidthPercentage","icons","iconSize","backButtonText","headerText","style","onFullScreenChange","onLeftScreenChange","onRightScreenChange","onZoomChange","ref","useImperativeHandle","resolvedIcons","useMemo","resolve","src","undefined","Image","resolveAssetSource","zoomIn","zoomOut","fullScreen","minimizeScreen","leftLayout","jsx","styles","fill","pdfUri","initialPageIndex","iconZoomIn","iconZoomOut","iconFullScreen","iconMinimizeScreen","iconLeftLayout","iconRightLayout","nativeEvent","isLeftScreen","isRightScreen","zoomPercentage","StyleSheet","create","flex"],"sourceRoot":"../../src","sources":["PdfViewerView.tsx"],"mappings":";;;;;;AAgBA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,yBAAA,GAAAC,sBAAA,CAAAH,OAAA;AAAwE,IAAAI,WAAA,GAAAJ,OAAA;AAAA,SAAAG,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAN,wBAAAM,CAAA,EAAAG,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAV,uBAAA,YAAAA,CAAAM,CAAA,EAAAG,CAAA,SAAAA,CAAA,IAAAH,CAAA,IAAAA,CAAA,CAAAC,UAAA,S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AAa,CAACQ,OAAQ;IACnCW,cAAc,EAAEnB,aAAa,CAACS,UAAW;IACzCW,kBAAkB,EAAEpB,aAAa,CAACU,cAAe;IACjDW,cAAc,EAAErB,aAAa,CAACW,UAAW;IACzCW,eAAe,EAAEtB,aAAa,CAACd,WAAY;IAC3CI,QAAQ,EAAEA,QAAS;IACnBC,cAAc,EAAEA,cAAe;IAC/BC,UAAU,EAAEA,UAAW;IACvBE,kBAAkB,EAAGlC,CAAC,IAAKkC,kBAAkB,GAAGlC,CAAC,CAAC+D,WAAW,CAACtC,YAAY,CAAE;IAC5EU,kBAAkB,EAAGnC,CAAC,IAAKmC,kBAAkB,GAAGnC,CAAC,CAAC+D,WAAW,CAACC,YAAY,CAAE;IAC5E5B,mBAAmB,EAAGpC,CAAC,IAAKoC,mBAAmB,GAAGpC,CAAC,CAAC+D,WAAW,CAACE,aAAa,CAAE;IAC/E5B,YAAY,EAAGrC,CAAC,IAAKqC,YAAY,GAAGrC,CAAC,CAAC+D,WAAW,CAACG,cAAc;EAAE,CACnE,CAAC;AAEN,CACF,CAAC;AAED,MAAMb,MAAM,GAAGc,uBAAU,CAACC,MAAM,CAAC;EAC/Bd,IAAI,EAAE;IAAEe,IAAI,EAAE;EAAE;AAClB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "NativePdfViewerModule", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _NativePdfViewerModule.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "PdfViewerView", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _PdfViewerView.PdfViewerView;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "usePdfViewer", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _usePdfViewer.usePdfViewer;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
var _PdfViewerView = require("./PdfViewerView");
|
|
25
|
+
var _usePdfViewer = require("./usePdfViewer");
|
|
26
|
+
var _NativePdfViewerModule = _interopRequireDefault(require("./specs/NativePdfViewerModule"));
|
|
27
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_PdfViewerView","require","_usePdfViewer","_NativePdfViewerModule","_interopRequireDefault","e","__esModule","default"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAAA,cAAA,GAAAC,OAAA;AAGA,IAAAC,aAAA,GAAAD,OAAA;AAGA,IAAAE,sBAAA,GAAAC,sBAAA,CAAAH,OAAA;AAAiF,SAAAG,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _codegenNativeComponent = _interopRequireDefault(require("react-native/Libraries/Utilities/codegenNativeComponent"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
/**
|
|
10
|
+
* Codegen spec for the embedded PDF viewer Fabric component.
|
|
11
|
+
*
|
|
12
|
+
* Codegen reads this file and generates the native component registration
|
|
13
|
+
* that allows <PdfViewerView /> to map to PdfViewerFabricManager on Android.
|
|
14
|
+
*
|
|
15
|
+
* Use DirectEventHandler (not BubblingEventHandler) for custom events — they
|
|
16
|
+
* are dispatched directly to the component's onXxx prop without bubbling.
|
|
17
|
+
*/
|
|
18
|
+
// The deep import below is intentional. Metro codegen identifies Fabric component
|
|
19
|
+
// specs by statically analysing this exact import path — switching to a public
|
|
20
|
+
// re-export or require() breaks spec detection. The runtime deprecation warning
|
|
21
|
+
// this produces is a known false positive for *spec* files and can be ignored.
|
|
22
|
+
// eslint-disable-next-line import/no-deprecated
|
|
23
|
+
// ── Event payload types ───────────────────────────────────────────────────────
|
|
24
|
+
// ── Component props ───────────────────────────────────────────────────────────
|
|
25
|
+
// The string 'PdfViewerView' must match PdfViewerFabricManager.VIEW_NAME in Kotlin.
|
|
26
|
+
var _default = exports.default = (0, _codegenNativeComponent.default)('PdfViewerView');
|
|
27
|
+
//# sourceMappingURL=NativePdfViewerComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_codegenNativeComponent","_interopRequireDefault","require","e","__esModule","default","_default","exports","codegenNativeComponent"],"sourceRoot":"../../../src","sources":["specs/NativePdfViewerComponent.ts"],"mappings":";;;;;;AAsBA,IAAAA,uBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA6F,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAtB7F;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AASA;AACA;AACA;AACA;AACA;AAGA;AAkBA;AAgDA;AAAA,IAAAG,QAAA,GAAAC,OAAA,CAAAF,OAAA,GACe,IAAAG,+BAAsB,EACnC,eACF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _reactNative = require("react-native");
|
|
8
|
+
/**
|
|
9
|
+
* Codegen spec for PdfViewerTurboModule.
|
|
10
|
+
*
|
|
11
|
+
* Codegen reads this file at build time and generates:
|
|
12
|
+
* Android: abstract Kotlin class `NativePdfViewerModuleSpec`
|
|
13
|
+
*
|
|
14
|
+
* The name passed to TurboModuleRegistry.getEnforcing() MUST match the
|
|
15
|
+
* string returned by PdfViewerTurboModule.getName() in Kotlin.
|
|
16
|
+
*
|
|
17
|
+
* Method signatures here are the source of truth — if the Kotlin
|
|
18
|
+
* implementation diverges, the build fails at compile time.
|
|
19
|
+
*/
|
|
20
|
+
var _default = exports.default = _reactNative.TurboModuleRegistry.getEnforcing('NativePdfViewerModule');
|
|
21
|
+
//# sourceMappingURL=NativePdfViewerModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../../src","sources":["specs/NativePdfViewerModule.ts"],"mappings":";;;;;;AAcA,IAAAA,YAAA,GAAAC,OAAA;AAdA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAXA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAyDeC,gCAAmB,CAACC,YAAY,CAAO,uBAAuB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.usePdfViewer = usePdfViewer;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
var _NativePdfViewerModule = _interopRequireDefault(require("./specs/NativePdfViewerModule"));
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
/**
|
|
12
|
+
* usePdfViewer — programmatic (Fragment-based) PDF viewer hook.
|
|
13
|
+
*
|
|
14
|
+
* Use this when you want to open the PDF viewer imperatively (like a modal),
|
|
15
|
+
* without embedding a <PdfViewerView /> in the render tree.
|
|
16
|
+
*
|
|
17
|
+
* Under the hood it calls PdfViewerTurboModule.openPdfViewer(), which shows
|
|
18
|
+
* PdfViewerFragment inside the host Activity — no new Activity is started.
|
|
19
|
+
*
|
|
20
|
+
* Usage:
|
|
21
|
+
* const { open, dismiss, getPageCount } = usePdfViewer({
|
|
22
|
+
* onZoomChanged: (pct) => console.log('zoom', pct),
|
|
23
|
+
* onDismiss: () => console.log('closed'),
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* // Open the viewer
|
|
27
|
+
* open('file:///path/to/book.pdf', 0, 1.5);
|
|
28
|
+
*
|
|
29
|
+
* // Dismiss it programmatically
|
|
30
|
+
* dismiss();
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
function usePdfViewer(options = {}) {
|
|
34
|
+
// Keep options in a ref so event handlers always see the latest callbacks
|
|
35
|
+
// without needing to re-subscribe to native events on every render.
|
|
36
|
+
const optionsRef = (0, _react.useRef)(options);
|
|
37
|
+
optionsRef.current = options;
|
|
38
|
+
(0, _react.useEffect)(() => {
|
|
39
|
+
const emitter = new _reactNative.NativeEventEmitter(_reactNative.NativeModules.NativePdfViewerModule);
|
|
40
|
+
const subs = [emitter.addListener('PdfFullScreenChanged', ({
|
|
41
|
+
isFullScreen
|
|
42
|
+
}) => optionsRef.current.onFullScreenChanged?.(isFullScreen)), emitter.addListener('PdfZoomChanged', ({
|
|
43
|
+
zoomPercentage
|
|
44
|
+
}) => optionsRef.current.onZoomChanged?.(zoomPercentage)), emitter.addListener('PdfViewerDismissed', () => optionsRef.current.onDismiss?.()), emitter.addListener('PdfViewerError', ({
|
|
45
|
+
error
|
|
46
|
+
}) => optionsRef.current.onError?.(error))];
|
|
47
|
+
return () => subs.forEach(s => s.remove());
|
|
48
|
+
}, []); // Empty deps: subscribe once, use ref for callbacks
|
|
49
|
+
|
|
50
|
+
const open = (0, _react.useCallback)((uri, pageIndex = -1, defaultZoom = 1.5) => {
|
|
51
|
+
_NativePdfViewerModule.default.openPdfViewer(uri, pageIndex, defaultZoom);
|
|
52
|
+
}, []);
|
|
53
|
+
const dismiss = (0, _react.useCallback)(() => {
|
|
54
|
+
_NativePdfViewerModule.default.dismissPdfViewer();
|
|
55
|
+
}, []);
|
|
56
|
+
const getPageCount = (0, _react.useCallback)(uri => _NativePdfViewerModule.default.getPdfPageCount(uri), []);
|
|
57
|
+
const createPdf = (0, _react.useCallback)((pages, widthPx, heightPx) => _NativePdfViewerModule.default.createMultiPagePdfBase64(pages, widthPx, heightPx), []);
|
|
58
|
+
return {
|
|
59
|
+
open,
|
|
60
|
+
dismiss,
|
|
61
|
+
getPageCount,
|
|
62
|
+
createPdf
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=usePdfViewer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","require","_reactNative","_NativePdfViewerModule","_interopRequireDefault","e","__esModule","default","usePdfViewer","options","optionsRef","useRef","current","useEffect","emitter","NativeEventEmitter","NativeModules","NativePdfViewerModule","subs","addListener","isFullScreen","onFullScreenChanged","zoomPercentage","onZoomChanged","onDismiss","error","onError","forEach","s","remove","open","useCallback","uri","pageIndex","defaultZoom","openPdfViewer","dismiss","dismissPdfViewer","getPageCount","getPdfPageCount","createPdf","pages","widthPx","heightPx","createMultiPagePdfBase64"],"sourceRoot":"../../src","sources":["usePdfViewer.ts"],"mappings":";;;;;;AAsBA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,sBAAA,GAAAC,sBAAA,CAAAH,OAAA;AAAkE,SAAAG,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAxBlE;AACA;AACA;AACA;AACA;AACA;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,CAAC;EAED,MAAME,OAAO,GAAG,IAAAL,kBAAW,EAAC,MAAM;IAChCd,8BAAqB,CAACoB,gBAAgB,CAAC,CAAC;EAC1C,CAAC,EAAE,EAAE,CAAC;EAEN,MAAMC,YAAY,GAAG,IAAAP,kBAAW,EAC7BC,GAAW,IAAsBf,8BAAqB,CAACsB,eAAe,CAACP,GAAG,CAAC,EAC5E,EACF,CAAC;EAED,MAAMQ,SAAS,GAAG,IAAAT,kBAAW,EAC3B,CACEU,KAA6C,EAC7CC,OAAe,EACfC,QAAgB,KACb1B,8BAAqB,CAAC2B,wBAAwB,CAACH,KAAK,EAAEC,OAAO,EAAEC,QAAQ,CAAC,EAC7E,EACF,CAAC;EAED,OAAO;IAAEb,IAAI;IAAEM,OAAO;IAAEE,YAAY;IAAEE;EAAU,CAAC;AACnD","ignoreList":[]}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* PdfViewerView — public React component for the embedded PDF viewer.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* import { PdfViewerView } from './PdfViewerView';
|
|
8
|
+
*
|
|
9
|
+
* <PdfViewerView
|
|
10
|
+
* uri="file:///path/to/book.pdf"
|
|
11
|
+
* initialPage={0}
|
|
12
|
+
* defaultZoom={1.5}
|
|
13
|
+
* style={{ flex: 1 }}
|
|
14
|
+
* onZoomChange={(pct) => console.log('zoom', pct)}
|
|
15
|
+
* onFullScreenChange={(fs) => setFullScreen(fs)}
|
|
16
|
+
* />
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import React, { forwardRef, useImperativeHandle, useMemo } from 'react';
|
|
20
|
+
import { Image, StyleSheet } from 'react-native';
|
|
21
|
+
import NativePdfViewerComponent from './specs/NativePdfViewerComponent';
|
|
22
|
+
|
|
23
|
+
// ── Public handle (imperative API via ref) ────────────────────────────────────
|
|
24
|
+
|
|
25
|
+
// ── Public props ──────────────────────────────────────────────────────────────
|
|
26
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
27
|
+
// ── Component ─────────────────────────────────────────────────────────────────
|
|
28
|
+
|
|
29
|
+
export const PdfViewerView = /*#__PURE__*/forwardRef(({
|
|
30
|
+
uri,
|
|
31
|
+
initialPage = -1,
|
|
32
|
+
defaultZoom = 1,
|
|
33
|
+
isFullScreen = false,
|
|
34
|
+
rightLayout = false,
|
|
35
|
+
maxWidth,
|
|
36
|
+
screenWidthPercentage = 100,
|
|
37
|
+
icons,
|
|
38
|
+
iconSize = 40,
|
|
39
|
+
backButtonText,
|
|
40
|
+
headerText,
|
|
41
|
+
style,
|
|
42
|
+
onFullScreenChange,
|
|
43
|
+
onLeftScreenChange,
|
|
44
|
+
onRightScreenChange,
|
|
45
|
+
onZoomChange
|
|
46
|
+
}, ref) => {
|
|
47
|
+
useImperativeHandle(ref, () => ({}));
|
|
48
|
+
|
|
49
|
+
// Resolve icon assets to URI strings the native layer can load.
|
|
50
|
+
// Image.resolveAssetSource handles both require() numbers and plain strings.
|
|
51
|
+
const resolvedIcons = useMemo(() => {
|
|
52
|
+
const resolve = src => {
|
|
53
|
+
if (src == null) return undefined;
|
|
54
|
+
if (typeof src === 'string') return src;
|
|
55
|
+
try {
|
|
56
|
+
return Image.resolveAssetSource(src).uri;
|
|
57
|
+
} catch {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
zoomIn: resolve(icons?.zoomIn),
|
|
63
|
+
zoomOut: resolve(icons?.zoomOut),
|
|
64
|
+
fullScreen: resolve(icons?.fullScreen),
|
|
65
|
+
minimizeScreen: resolve(icons?.minimizeScreen),
|
|
66
|
+
leftLayout: resolve(icons?.leftLayout),
|
|
67
|
+
rightLayout: resolve(icons?.rightLayout)
|
|
68
|
+
};
|
|
69
|
+
}, [icons]);
|
|
70
|
+
return /*#__PURE__*/_jsx(NativePdfViewerComponent, {
|
|
71
|
+
style: [styles.fill, style],
|
|
72
|
+
pdfUri: uri,
|
|
73
|
+
initialPageIndex: initialPage,
|
|
74
|
+
defaultZoom: defaultZoom,
|
|
75
|
+
isFullScreen: isFullScreen,
|
|
76
|
+
rightLayout: rightLayout,
|
|
77
|
+
maxWidth: maxWidth,
|
|
78
|
+
screenWidthPercentage: screenWidthPercentage,
|
|
79
|
+
iconZoomIn: resolvedIcons.zoomIn,
|
|
80
|
+
iconZoomOut: resolvedIcons.zoomOut,
|
|
81
|
+
iconFullScreen: resolvedIcons.fullScreen,
|
|
82
|
+
iconMinimizeScreen: resolvedIcons.minimizeScreen,
|
|
83
|
+
iconLeftLayout: resolvedIcons.leftLayout,
|
|
84
|
+
iconRightLayout: resolvedIcons.rightLayout,
|
|
85
|
+
iconSize: iconSize,
|
|
86
|
+
backButtonText: backButtonText,
|
|
87
|
+
headerText: headerText,
|
|
88
|
+
onFullScreenChange: e => onFullScreenChange?.(e.nativeEvent.isFullScreen),
|
|
89
|
+
onLeftScreenChange: e => onLeftScreenChange?.(e.nativeEvent.isLeftScreen),
|
|
90
|
+
onRightScreenChange: e => onRightScreenChange?.(e.nativeEvent.isRightScreen),
|
|
91
|
+
onZoomChange: e => onZoomChange?.(e.nativeEvent.zoomPercentage)
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
const styles = StyleSheet.create({
|
|
95
|
+
fill: {
|
|
96
|
+
flex: 1
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
//# sourceMappingURL=PdfViewerView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","forwardRef","useImperativeHandle","useMemo","Image","StyleSheet","NativePdfViewerComponent","jsx","_jsx","PdfViewerView","uri","initialPage","defaultZoom","isFullScreen","rightLayout","maxWidth","screenWidthPercentage","icons","iconSize","backButtonText","headerText","style","onFullScreenChange","onLeftScreenChange","onRightScreenChange","onZoomChange","ref","resolvedIcons","resolve","src","undefined","resolveAssetSource","zoomIn","zoomOut","fullScreen","minimizeScreen","leftLayout","styles","fill","pdfUri","initialPageIndex","iconZoomIn","iconZoomOut","iconFullScreen","iconMinimizeScreen","iconLeftLayout","iconRightLayout","e","nativeEvent","isLeftScreen","isRightScreen","zoomPercentage","create","flex"],"sourceRoot":"../../src","sources":["PdfViewerView.tsx"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,mBAAmB,EAAEC,OAAO,QAAQ,OAAO;AACvE,SAASC,KAAK,EAAEC,UAAU,QAAwB,cAAc;AAChE,OAAOC,wBAAwB,MAAM,kCAAkC;;AAEvE;;AAOA;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAqDA;;AAEA,OAAO,MAAMC,aAAa,gBAAGR,UAAU,CACrC,CACE;EACES,GAAG;EACHC,WAAW,GAAG,CAAC,CAAC;EAChBC,WAAW,GAAG,CAAC;EACfC,YAAY,GAAG,KAAK;EACpBC,WAAW,GAAG,KAAK;EACnBC,QAAQ;EACRC,qBAAqB,GAAG,GAAG;EAC3BC,KAAK;EACLC,QAAQ,GAAG,EAAE;EACbC,cAAc;EACdC,UAAU;EACVC,KAAK;EACLC,kBAAkB;EAClBC,kBAAkB;EAClBC,mBAAmB;EACnBC;AACF,CAAC,EACDC,GAAG,KACA;EACHxB,mBAAmB,CAACwB,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;;EAEpC;EACA;EACA,MAAMC,aAAa,GAAGxB,OAAO,CAAC,MAAM;IAClC,MAAMyB,OAAO,GAAIC,GAAqB,IAAyB;MAC7D,IAAIA,GAAG,IAAI,IAAI,EAAE,OAAOC,SAAS;MACjC,IAAI,OAAOD,GAAG,KAAK,QAAQ,EAAE,OAAOA,GAAG;MACvC,IAAI;QACF,OAAOzB,KAAK,CAAC2B,kBAAkB,CAACF,GAAG,CAAC,CAACnB,GAAG;MAC1C,CAAC,CAAC,MAAM;QACN,OAAOoB,SAAS;M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,CAAE;IAC5EzB,mBAAmB,EAAGuB,CAAC,IAAKvB,mBAAmB,GAAGuB,CAAC,CAACC,WAAW,CAACE,aAAa,CAAE;IAC/EzB,YAAY,EAAGsB,CAAC,IAAKtB,YAAY,GAAGsB,CAAC,CAACC,WAAW,CAACG,cAAc;EAAE,CACnE,CAAC;AAEN,CACF,CAAC;AAED,MAAMd,MAAM,GAAGhC,UAAU,CAAC+C,MAAM,CAAC;EAC/Bd,IAAI,EAAE;IAAEe,IAAI,EAAE;EAAE;AAClB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// ── Public API ────────────────────────────────────────────────────────────────
|
|
4
|
+
|
|
5
|
+
export { PdfViewerView } from './PdfViewerView';
|
|
6
|
+
export { usePdfViewer } from './usePdfViewer';
|
|
7
|
+
export { default as NativePdfViewerModule } from './specs/NativePdfViewerModule';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["PdfViewerView","usePdfViewer","default","NativePdfViewerModule"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA;;AAEA,SAASA,aAAa,QAAQ,iBAAiB;AAG/C,SAASC,YAAY,QAAQ,gBAAgB;AAG7C,SAASC,OAAO,IAAIC,qBAAqB,QAAQ,+BAA+B","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Codegen spec for the embedded PDF viewer Fabric component.
|
|
5
|
+
*
|
|
6
|
+
* Codegen reads this file and generates the native component registration
|
|
7
|
+
* that allows <PdfViewerView /> to map to PdfViewerFabricManager on Android.
|
|
8
|
+
*
|
|
9
|
+
* Use DirectEventHandler (not BubblingEventHandler) for custom events — they
|
|
10
|
+
* are dispatched directly to the component's onXxx prop without bubbling.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// The deep import below is intentional. Metro codegen identifies Fabric component
|
|
14
|
+
// specs by statically analysing this exact import path — switching to a public
|
|
15
|
+
// re-export or require() breaks spec detection. The runtime deprecation warning
|
|
16
|
+
// this produces is a known false positive for *spec* files and can be ignored.
|
|
17
|
+
// eslint-disable-next-line import/no-deprecated
|
|
18
|
+
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
19
|
+
|
|
20
|
+
// ── Event payload types ───────────────────────────────────────────────────────
|
|
21
|
+
|
|
22
|
+
// ── Component props ───────────────────────────────────────────────────────────
|
|
23
|
+
|
|
24
|
+
// The string 'PdfViewerView' must match PdfViewerFabricManager.VIEW_NAME in Kotlin.
|
|
25
|
+
export default codegenNativeComponent('PdfViewerView');
|
|
26
|
+
//# sourceMappingURL=NativePdfViewerComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["codegenNativeComponent"],"sourceRoot":"../../../src","sources":["specs/NativePdfViewerComponent.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;AACA,OAAOA,sBAAsB,MAAM,yDAAyD;;AAE5F;;AAkBA;;AAgDA;AACA,eAAeA,sBAAsB,CACnC,eACF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Codegen spec for PdfViewerTurboModule.
|
|
5
|
+
*
|
|
6
|
+
* Codegen reads this file at build time and generates:
|
|
7
|
+
* Android: abstract Kotlin class `NativePdfViewerModuleSpec`
|
|
8
|
+
*
|
|
9
|
+
* The name passed to TurboModuleRegistry.getEnforcing() MUST match the
|
|
10
|
+
* string returned by PdfViewerTurboModule.getName() in Kotlin.
|
|
11
|
+
*
|
|
12
|
+
* Method signatures here are the source of truth — if the Kotlin
|
|
13
|
+
* implementation diverges, the build fails at compile time.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
17
|
+
export default TurboModuleRegistry.getEnforcing('NativePdfViewerModule');
|
|
18
|
+
//# sourceMappingURL=NativePdfViewerModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../../src","sources":["specs/NativePdfViewerModule.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,mBAAmB,QAAQ,cAAc;AA2ClD,eAAeA,mBAAmB,CAACC,YAAY,CAAO,uBAAuB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* usePdfViewer — programmatic (Fragment-based) PDF viewer hook.
|
|
5
|
+
*
|
|
6
|
+
* Use this when you want to open the PDF viewer imperatively (like a modal),
|
|
7
|
+
* without embedding a <PdfViewerView /> in the render tree.
|
|
8
|
+
*
|
|
9
|
+
* Under the hood it calls PdfViewerTurboModule.openPdfViewer(), which shows
|
|
10
|
+
* PdfViewerFragment inside the host Activity — no new Activity is started.
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* const { open, dismiss, getPageCount } = usePdfViewer({
|
|
14
|
+
* onZoomChanged: (pct) => console.log('zoom', pct),
|
|
15
|
+
* onDismiss: () => console.log('closed'),
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* // Open the viewer
|
|
19
|
+
* open('file:///path/to/book.pdf', 0, 1.5);
|
|
20
|
+
*
|
|
21
|
+
* // Dismiss it programmatically
|
|
22
|
+
* dismiss();
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { useCallback, useEffect, useRef } from 'react';
|
|
26
|
+
import { NativeEventEmitter, NativeModules } from 'react-native';
|
|
27
|
+
import NativePdfViewerModule from './specs/NativePdfViewerModule';
|
|
28
|
+
export function usePdfViewer(options = {}) {
|
|
29
|
+
// Keep options in a ref so event handlers always see the latest callbacks
|
|
30
|
+
// without needing to re-subscribe to native events on every render.
|
|
31
|
+
const optionsRef = useRef(options);
|
|
32
|
+
optionsRef.current = options;
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
const emitter = new NativeEventEmitter(NativeModules.NativePdfViewerModule);
|
|
35
|
+
const subs = [emitter.addListener('PdfFullScreenChanged', ({
|
|
36
|
+
isFullScreen
|
|
37
|
+
}) => optionsRef.current.onFullScreenChanged?.(isFullScreen)), emitter.addListener('PdfZoomChanged', ({
|
|
38
|
+
zoomPercentage
|
|
39
|
+
}) => optionsRef.current.onZoomChanged?.(zoomPercentage)), emitter.addListener('PdfViewerDismissed', () => optionsRef.current.onDismiss?.()), emitter.addListener('PdfViewerError', ({
|
|
40
|
+
error
|
|
41
|
+
}) => optionsRef.current.onError?.(error))];
|
|
42
|
+
return () => subs.forEach(s => s.remove());
|
|
43
|
+
}, []); // Empty deps: subscribe once, use ref for callbacks
|
|
44
|
+
|
|
45
|
+
const open = useCallback((uri, pageIndex = -1, defaultZoom = 1.5) => {
|
|
46
|
+
NativePdfViewerModule.openPdfViewer(uri, pageIndex, defaultZoom);
|
|
47
|
+
}, []);
|
|
48
|
+
const dismiss = useCallback(() => {
|
|
49
|
+
NativePdfViewerModule.dismissPdfViewer();
|
|
50
|
+
}, []);
|
|
51
|
+
const getPageCount = useCallback(uri => NativePdfViewerModule.getPdfPageCount(uri), []);
|
|
52
|
+
const createPdf = useCallback((pages, widthPx, heightPx) => NativePdfViewerModule.createMultiPagePdfBase64(pages, widthPx, heightPx), []);
|
|
53
|
+
return {
|
|
54
|
+
open,
|
|
55
|
+
dismiss,
|
|
56
|
+
getPageCount,
|
|
57
|
+
createPdf
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=usePdfViewer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useCallback","useEffect","useRef","NativeEventEmitter","NativeModules","NativePdfViewerModule","usePdfViewer","options","optionsRef","current","emitter","subs","addListener","isFullScreen","onFullScreenChanged","zoomPercentage","onZoomChanged","onDismiss","error","onError","forEach","s","remove","open","uri","pageIndex","defaultZoom","openPdfViewer","dismiss","dismissPdfViewer","getPageCount","getPdfPageCount","createPdf","pages","widthPx","heightPx","createMultiPagePdfBase64"],"sourceRoot":"../../src","sources":["usePdfViewer.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,WAAW,EAAEC,SAAS,EAAEC,MAAM,QAAQ,OAAO;AACtD,SAASC,kBAAkB,EAAEC,aAAa,QAAQ,cAAc;AAChE,OAAOC,qBAAqB,MAAM,+BAA+B;AAwBjE,OAAO,SAASC,YAAYA,CAACC,OAA4B,GAAG,CAAC,CAAC,EAAsB;EAClF;EACA;EACA,MAAMC,UAAU,GAAGN,MAAM,CAACK,OAAO,CAAC;EAClCC,UAAU,CAACC,OAAO,GAAGF,OAAO;EAE5BN,SAAS,CAAC,MAAM;IACd,MAAMS,OAAO,GAAG,IAAIP,kBAAkB,CAACC,aAAa,CAACC,qBAAqB,CAAC;IAE3E,MAAMM,IAAI,GAAG,CACXD,OAAO,CAACE,WAAW,CAAC,sBAAsB,EAAE,CAAC;MAAEC;IAAwC,CAAC,KACtFL,UAAU,CAACC,OAAO,CAACK,mBAAmB,GAAGD,YAAY,CACvD,CAAC,EACDH,OAAO,CAACE,WAAW,CAAC,gBAAgB,EAAE,CAAC;MAAEG;IAA2C,CAAC,KACnFP,UAAU,CAACC,OAAO,CAACO,aAAa,GAAGD,cAAc,CACnD,CAAC,EACDL,OAAO,CAACE,WAAW,CAAC,oBAAoB,EAAE,MACxCJ,UAAU,CAACC,OAAO,CAACQ,SAAS,GAAG,CACjC,CAA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