react-native-rectangle-doc-scanner 3.95.0 → 3.97.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.
@@ -330,35 +330,56 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
330
330
  const handleFlashToggle = (0, react_1.useCallback)(() => {
331
331
  setFlashEnabled(prev => !prev);
332
332
  }, []);
333
- const handleRotateImage = (0, react_1.useCallback)(async (degrees) => {
333
+ const handleRotateImage = (0, react_1.useCallback)((degrees) => {
334
334
  if (!croppedImageData)
335
335
  return;
336
- try {
337
- // UI 회전 상태 먼저 업데이트 (즉각 반응)
338
- setRotationDegrees(prev => {
339
- const newRotation = (prev + degrees + 360) % 360;
340
- return newRotation;
341
- });
342
- console.log('[FullDocScanner] Starting image rotation...');
343
- // ImageRotate를 사용해서 실제로 이미지 회전 (UI 없이)
344
- const rotatedImagePath = await react_native_image_rotate_1.default.rotateImage(croppedImageData.path, degrees);
345
- console.log('[FullDocScanner] Image rotated successfully:', rotatedImagePath);
346
- // 회전된 이미지로 교체
347
- setCroppedImageData({
348
- path: rotatedImagePath,
349
- base64: undefined, // base64는 다시 읽어야 함
350
- });
351
- // rotation degrees는 0으로 리셋 (이미 실제 파일에 적용되었으므로)
352
- setRotationDegrees(0);
353
- }
354
- catch (error) {
336
+ // UI 회전 상태 먼저 업데이트 (즉각 반응)
337
+ setRotationDegrees(prev => {
338
+ const newRotation = (prev + degrees + 360) % 360;
339
+ return newRotation;
340
+ });
341
+ console.log('[FullDocScanner] Starting image rotation...');
342
+ // ImageRotate를 사용해서 실제로 이미지 회전 (callback 기반)
343
+ react_native_image_rotate_1.default.rotateImage(croppedImageData.path, degrees, async (rotatedImageUri) => {
344
+ console.log('[FullDocScanner] Image rotated successfully:', rotatedImageUri);
345
+ try {
346
+ // rct-image-store:// URI를 base64로 변환
347
+ const response = await fetch(rotatedImageUri);
348
+ const blob = await response.blob();
349
+ // Blob to base64
350
+ const reader = new FileReader();
351
+ reader.onloadend = () => {
352
+ const base64String = reader.result;
353
+ // "data:image/jpeg;base64," 부분 제거
354
+ const base64Data = base64String.split(',')[1];
355
+ console.log('[FullDocScanner] Converted to base64, length:', base64Data?.length);
356
+ // 회전된 이미지로 교체 (base64 포함)
357
+ setCroppedImageData({
358
+ path: rotatedImageUri,
359
+ base64: base64Data,
360
+ });
361
+ // rotation degrees는 0으로 리셋
362
+ setRotationDegrees(0);
363
+ };
364
+ reader.readAsDataURL(blob);
365
+ }
366
+ catch (convertError) {
367
+ console.error('[FullDocScanner] Failed to convert to base64:', convertError);
368
+ // base64 변환 실패 시 URI만 저장
369
+ setCroppedImageData({
370
+ path: rotatedImageUri,
371
+ base64: undefined,
372
+ });
373
+ setRotationDegrees(0);
374
+ }
375
+ }, (error) => {
355
376
  console.error('[FullDocScanner] Image rotation error:', error);
356
377
  // 에러 발생 시 UI rotation 원복
357
378
  setRotationDegrees(prev => {
358
379
  const revertRotation = (prev - degrees + 360) % 360;
359
380
  return revertRotation;
360
381
  });
361
- }
382
+ });
362
383
  }, [croppedImageData]);
363
384
  const handleConfirm = (0, react_1.useCallback)(() => {
364
385
  if (!croppedImageData)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "3.95.0",
3
+ "version": "3.97.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -441,42 +441,67 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
441
441
  setFlashEnabled(prev => !prev);
442
442
  }, []);
443
443
 
444
- const handleRotateImage = useCallback(async (degrees: -90 | 90) => {
444
+ const handleRotateImage = useCallback((degrees: -90 | 90) => {
445
445
  if (!croppedImageData) return;
446
446
 
447
- try {
448
- // UI 회전 상태 먼저 업데이트 (즉각 반응)
449
- setRotationDegrees(prev => {
450
- const newRotation = (prev + degrees + 360) % 360;
451
- return newRotation;
452
- });
453
-
454
- console.log('[FullDocScanner] Starting image rotation...');
455
-
456
- // ImageRotate를 사용해서 실제로 이미지 회전 (UI 없이)
457
- const rotatedImagePath = await ImageRotate.rotateImage(
458
- croppedImageData.path,
459
- degrees,
460
- );
461
-
462
- console.log('[FullDocScanner] Image rotated successfully:', rotatedImagePath);
463
-
464
- // 회전된 이미지로 교체
465
- setCroppedImageData({
466
- path: rotatedImagePath,
467
- base64: undefined, // base64는 다시 읽어야 함
468
- });
447
+ // UI 회전 상태 먼저 업데이트 (즉각 반응)
448
+ setRotationDegrees(prev => {
449
+ const newRotation = (prev + degrees + 360) % 360;
450
+ return newRotation;
451
+ });
469
452
 
470
- // rotation degrees는 0으로 리셋 (이미 실제 파일에 적용되었으므로)
471
- setRotationDegrees(0);
472
- } catch (error) {
473
- console.error('[FullDocScanner] Image rotation error:', error);
474
- // 에러 발생 시 UI rotation 원복
475
- setRotationDegrees(prev => {
476
- const revertRotation = (prev - degrees + 360) % 360;
477
- return revertRotation;
478
- });
479
- }
453
+ console.log('[FullDocScanner] Starting image rotation...');
454
+
455
+ // ImageRotate를 사용해서 실제로 이미지 회전 (callback 기반)
456
+ ImageRotate.rotateImage(
457
+ croppedImageData.path,
458
+ degrees,
459
+ async (rotatedImageUri: string) => {
460
+ console.log('[FullDocScanner] Image rotated successfully:', rotatedImageUri);
461
+
462
+ try {
463
+ // rct-image-store:// URI를 base64로 변환
464
+ const response = await fetch(rotatedImageUri);
465
+ const blob = await response.blob();
466
+
467
+ // Blob to base64
468
+ const reader = new FileReader();
469
+ reader.onloadend = () => {
470
+ const base64String = reader.result as string;
471
+ // "data:image/jpeg;base64," 부분 제거
472
+ const base64Data = base64String.split(',')[1];
473
+
474
+ console.log('[FullDocScanner] Converted to base64, length:', base64Data?.length);
475
+
476
+ // 회전된 이미지로 교체 (base64 포함)
477
+ setCroppedImageData({
478
+ path: rotatedImageUri,
479
+ base64: base64Data,
480
+ });
481
+
482
+ // rotation degrees는 0으로 리셋
483
+ setRotationDegrees(0);
484
+ };
485
+ reader.readAsDataURL(blob);
486
+ } catch (convertError) {
487
+ console.error('[FullDocScanner] Failed to convert to base64:', convertError);
488
+ // base64 변환 실패 시 URI만 저장
489
+ setCroppedImageData({
490
+ path: rotatedImageUri,
491
+ base64: undefined,
492
+ });
493
+ setRotationDegrees(0);
494
+ }
495
+ },
496
+ (error: Error) => {
497
+ console.error('[FullDocScanner] Image rotation error:', error);
498
+ // 에러 발생 시 UI rotation 원복
499
+ setRotationDegrees(prev => {
500
+ const revertRotation = (prev - degrees + 360) % 360;
501
+ return revertRotation;
502
+ });
503
+ }
504
+ );
480
505
  }, [croppedImageData]);
481
506
 
482
507
  const handleConfirm = useCallback(() => {
@@ -3,6 +3,8 @@ declare module 'react-native-image-rotate' {
3
3
  static rotateImage(
4
4
  imagePath: string,
5
5
  degrees: number,
6
- ): Promise<string>;
6
+ successCallback: (rotatedImagePath: string) => void,
7
+ errorCallback: (error: Error) => void,
8
+ ): void;
7
9
  }
8
10
  }