react-native-rectangle-doc-scanner 3.76.0 → 3.77.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.
@@ -43,6 +43,7 @@ const react_native_document_scanner_1 = __importDefault(require("react-native-do
43
43
  const coordinate_1 = require("./utils/coordinate");
44
44
  const overlay_1 = require("./utils/overlay");
45
45
  const isFiniteNumber = (value) => typeof value === 'number' && Number.isFinite(value);
46
+ const { RNPdfScannerManager } = react_native_1.NativeModules;
46
47
  const normalizePoint = (point) => {
47
48
  if (!point || !isFiniteNumber(point.x) || !isFiniteNumber(point.y)) {
48
49
  return null;
@@ -155,7 +156,7 @@ exports.DocScanner = (0, react_1.forwardRef)(({ onCapture, overlayColor = DEFAUL
155
156
  console.log('[DocScanner] capture() called');
156
157
  captureOriginRef.current = 'manual';
157
158
  const instance = scannerRef.current;
158
- if (!instance || typeof instance.capture !== 'function') {
159
+ if (!instance || (typeof instance.capture !== 'function' && react_native_1.Platform.OS !== 'ios')) {
159
160
  console.error('[DocScanner] Native instance not ready:', {
160
161
  hasInstance: !!instance,
161
162
  hasCaptureMethod: instance ? typeof instance.capture : 'no instance',
@@ -168,7 +169,47 @@ exports.DocScanner = (0, react_1.forwardRef)(({ onCapture, overlayColor = DEFAUL
168
169
  captureOriginRef.current = 'auto';
169
170
  return Promise.reject(new Error('capture_in_progress'));
170
171
  }
171
- console.log('[DocScanner] Calling native capture method (now returns Promise)...');
172
+ const attemptNativeManagerCapture = () => {
173
+ if (react_native_1.Platform.OS !== 'ios') {
174
+ return null;
175
+ }
176
+ if (!RNPdfScannerManager || typeof RNPdfScannerManager.capture !== 'function') {
177
+ console.warn('[DocScanner] RNPdfScannerManager.capture not available, falling back to instance method');
178
+ return null;
179
+ }
180
+ const nodeHandle = (0, react_native_1.findNodeHandle)(instance);
181
+ if (!nodeHandle) {
182
+ console.error('[DocScanner] Unable to resolve native tag for scanner view');
183
+ return Promise.reject(new Error('scanner_view_not_ready'));
184
+ }
185
+ console.log('[DocScanner] Calling RNPdfScannerManager.capture with tag:', nodeHandle);
186
+ const managerResult = RNPdfScannerManager.capture(nodeHandle);
187
+ if (!managerResult || typeof managerResult.then !== 'function') {
188
+ console.warn('[DocScanner] RNPdfScannerManager.capture did not return a promise, falling back to instance method');
189
+ return null;
190
+ }
191
+ return managerResult
192
+ .then((payload) => {
193
+ console.log('[DocScanner] RNPdfScannerManager promise resolved');
194
+ handlePictureTaken(payload);
195
+ return payload;
196
+ })
197
+ .catch((error) => {
198
+ console.error('[DocScanner] RNPdfScannerManager promise rejected:', error);
199
+ captureOriginRef.current = 'auto';
200
+ throw error;
201
+ });
202
+ };
203
+ const managerPromise = attemptNativeManagerCapture();
204
+ if (managerPromise) {
205
+ return managerPromise;
206
+ }
207
+ if (!instance || typeof instance.capture !== 'function') {
208
+ console.error('[DocScanner] capture() fallback not available on instance');
209
+ captureOriginRef.current = 'auto';
210
+ return Promise.reject(new Error('capture_not_supported'));
211
+ }
212
+ console.log('[DocScanner] Calling native capture method (legacy/event-based)...');
172
213
  try {
173
214
  const result = instance.capture();
174
215
  console.log('[DocScanner] Native capture method called, result type:', typeof result, 'isPromise:', !!(result && typeof result.then === 'function'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "3.76.0",
3
+ "version": "3.77.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -8,7 +8,14 @@ import React, {
8
8
  useRef,
9
9
  useState,
10
10
  } from 'react';
11
- import { Platform, StyleSheet, TouchableOpacity, View } from 'react-native';
11
+ import {
12
+ Platform,
13
+ StyleSheet,
14
+ TouchableOpacity,
15
+ View,
16
+ NativeModules,
17
+ findNodeHandle,
18
+ } from 'react-native';
12
19
  import DocumentScanner from 'react-native-document-scanner';
13
20
  import type { Rectangle as NativeRectangle, RectangleEventPayload } from 'react-native-document-scanner';
14
21
  import { rectangleToQuad } from './utils/coordinate';
@@ -42,6 +49,8 @@ export type DocScannerCapture = {
42
49
  const isFiniteNumber = (value: unknown): value is number =>
43
50
  typeof value === 'number' && Number.isFinite(value);
44
51
 
52
+ const { RNPdfScannerManager } = NativeModules;
53
+
45
54
  const normalizePoint = (point?: { x?: number; y?: number } | null): Point | null => {
46
55
  if (!point || !isFiniteNumber(point.x) || !isFiniteNumber(point.y)) {
47
56
  return null;
@@ -232,10 +241,10 @@ export const DocScanner = forwardRef<DocScannerHandle, Props>(
232
241
  captureOriginRef.current = 'manual';
233
242
  const instance = scannerRef.current;
234
243
 
235
- if (!instance || typeof instance.capture !== 'function') {
244
+ if (!instance || (typeof instance.capture !== 'function' && Platform.OS !== 'ios')) {
236
245
  console.error('[DocScanner] Native instance not ready:', {
237
246
  hasInstance: !!instance,
238
- hasCaptureMethod: instance ? typeof instance.capture : 'no instance',
247
+ hasCaptureMethod: instance ? typeof (instance as any).capture : 'no instance',
239
248
  });
240
249
  captureOriginRef.current = 'auto';
241
250
  return Promise.reject(new Error('DocumentScanner native instance is not ready'));
@@ -247,7 +256,57 @@ export const DocScanner = forwardRef<DocScannerHandle, Props>(
247
256
  return Promise.reject(new Error('capture_in_progress'));
248
257
  }
249
258
 
250
- console.log('[DocScanner] Calling native capture method (now returns Promise)...');
259
+ const attemptNativeManagerCapture = () => {
260
+ if (Platform.OS !== 'ios') {
261
+ return null;
262
+ }
263
+
264
+ if (!RNPdfScannerManager || typeof RNPdfScannerManager.capture !== 'function') {
265
+ console.warn('[DocScanner] RNPdfScannerManager.capture not available, falling back to instance method');
266
+ return null;
267
+ }
268
+
269
+ const nodeHandle = findNodeHandle(instance);
270
+
271
+ if (!nodeHandle) {
272
+ console.error('[DocScanner] Unable to resolve native tag for scanner view');
273
+ return Promise.reject(new Error('scanner_view_not_ready'));
274
+ }
275
+
276
+ console.log('[DocScanner] Calling RNPdfScannerManager.capture with tag:', nodeHandle);
277
+
278
+ const managerResult = RNPdfScannerManager.capture(nodeHandle);
279
+
280
+ if (!managerResult || typeof managerResult.then !== 'function') {
281
+ console.warn('[DocScanner] RNPdfScannerManager.capture did not return a promise, falling back to instance method');
282
+ return null;
283
+ }
284
+
285
+ return managerResult
286
+ .then((payload: PictureEvent) => {
287
+ console.log('[DocScanner] RNPdfScannerManager promise resolved');
288
+ handlePictureTaken(payload);
289
+ return payload;
290
+ })
291
+ .catch((error: unknown) => {
292
+ console.error('[DocScanner] RNPdfScannerManager promise rejected:', error);
293
+ captureOriginRef.current = 'auto';
294
+ throw error;
295
+ });
296
+ };
297
+
298
+ const managerPromise = attemptNativeManagerCapture();
299
+ if (managerPromise) {
300
+ return managerPromise;
301
+ }
302
+
303
+ if (!instance || typeof instance.capture !== 'function') {
304
+ console.error('[DocScanner] capture() fallback not available on instance');
305
+ captureOriginRef.current = 'auto';
306
+ return Promise.reject(new Error('capture_not_supported'));
307
+ }
308
+
309
+ console.log('[DocScanner] Calling native capture method (legacy/event-based)...');
251
310
  try {
252
311
  const result = instance.capture();
253
312
  console.log('[DocScanner] Native capture method called, result type:', typeof result, 'isPromise:', !!(result && typeof result.then === 'function'));