react-native-rectangle-doc-scanner 3.139.0 → 3.142.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.
@@ -6,6 +6,7 @@ import org.opencv.android.Utils
6
6
  import org.opencv.core.*
7
7
  import org.opencv.imgproc.Imgproc
8
8
  import kotlin.math.abs
9
+ import kotlin.math.max
9
10
  import kotlin.math.sqrt
10
11
 
11
12
  data class Rectangle(
@@ -249,14 +250,34 @@ class DocumentDetector {
249
250
  viewWidth: Int,
250
251
  viewHeight: Int
251
252
  ): Rectangle {
252
- val scaleX = viewWidth.toDouble() / imageWidth
253
- val scaleY = viewHeight.toDouble() / imageHeight
253
+ if (imageWidth == 0 || imageHeight == 0 || viewWidth == 0 || viewHeight == 0) {
254
+ return rectangle
255
+ }
256
+
257
+ val scale = max(
258
+ viewWidth.toDouble() / imageWidth.toDouble(),
259
+ viewHeight.toDouble() / imageHeight.toDouble()
260
+ )
261
+
262
+ val scaledImageWidth = imageWidth * scale
263
+ val scaledImageHeight = imageHeight * scale
264
+ val offsetX = (scaledImageWidth - viewWidth) / 2.0
265
+ val offsetY = (scaledImageHeight - viewHeight) / 2.0
266
+
267
+ fun mapPoint(point: Point): Point {
268
+ val x = (point.x * scale) - offsetX
269
+ val y = (point.y * scale) - offsetY
270
+ return Point(
271
+ x.coerceIn(0.0, viewWidth.toDouble()),
272
+ y.coerceIn(0.0, viewHeight.toDouble())
273
+ )
274
+ }
254
275
 
255
276
  return Rectangle(
256
- Point(rectangle.topLeft.x * scaleX, rectangle.topLeft.y * scaleY),
257
- Point(rectangle.topRight.x * scaleX, rectangle.topRight.y * scaleY),
258
- Point(rectangle.bottomLeft.x * scaleX, rectangle.bottomLeft.y * scaleY),
259
- Point(rectangle.bottomRight.x * scaleX, rectangle.bottomRight.y * scaleY)
277
+ mapPoint(rectangle.topLeft),
278
+ mapPoint(rectangle.topRight),
279
+ mapPoint(rectangle.bottomLeft),
280
+ mapPoint(rectangle.bottomRight)
260
281
  )
261
282
  }
262
283
  }
@@ -596,7 +596,7 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
596
596
  react_1.default.createElement(react_native_1.TouchableOpacity, { style: [styles.confirmButton, styles.retakeButton], onPress: handleRetake, accessibilityLabel: mergedStrings.retake, accessibilityRole: "button" },
597
597
  react_1.default.createElement(react_native_1.Text, { style: styles.confirmButtonText }, mergedStrings.retake)),
598
598
  react_1.default.createElement(react_native_1.TouchableOpacity, { style: [styles.confirmButton, styles.confirmButtonPrimary], onPress: handleConfirm, accessibilityLabel: mergedStrings.confirm, accessibilityRole: "button" },
599
- react_1.default.createElement(react_native_1.Text, { style: styles.confirmButtonText }, mergedStrings.confirm))))) : react_native_1.Platform.OS === 'ios' ? (react_1.default.createElement(react_native_1.View, { style: styles.flex },
599
+ react_1.default.createElement(react_native_1.Text, { style: styles.confirmButtonText }, mergedStrings.confirm))))) : (react_1.default.createElement(react_native_1.View, { style: styles.flex },
600
600
  react_1.default.createElement(DocScanner_1.DocScanner, { key: scannerSession, ref: docScannerRef, autoCapture: false, overlayColor: overlayColor, showGrid: showGrid, gridColor: resolvedGridColor, gridLineWidth: gridLineWidth, minStableFrames: minStableFrames ?? 6, detectionConfig: detectionConfig, onCapture: handleCapture, onRectangleDetect: handleRectangleDetect, showManualCaptureButton: false, enableTorch: flashEnabled },
601
601
  react_1.default.createElement(react_native_1.View, { style: styles.overlayTop, pointerEvents: "box-none" },
602
602
  react_1.default.createElement(react_native_1.TouchableOpacity, { style: [
@@ -624,10 +624,7 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
624
624
  styles.shutterInner,
625
625
  rectangleHint && { backgroundColor: overlayColor }
626
626
  ] })),
627
- react_1.default.createElement(react_native_1.View, { style: styles.rightButtonsPlaceholder }))))) : (react_1.default.createElement(react_native_1.View, { style: styles.flex },
628
- react_1.default.createElement(react_native_1.View, { style: styles.processingOverlay },
629
- react_1.default.createElement(react_native_1.ActivityIndicator, { size: "large", color: overlayColor }),
630
- react_1.default.createElement(react_native_1.Text, { style: styles.processingText }, "\uAC24\uB7EC\uB9AC\uC5D0\uC11C \uC774\uBBF8\uC9C0\uB97C \uC120\uD0DD\uD574\uC8FC\uC138\uC694...")))),
627
+ react_1.default.createElement(react_native_1.View, { style: styles.rightButtonsPlaceholder }))))),
631
628
  processing && (react_1.default.createElement(react_native_1.View, { style: styles.processingOverlay },
632
629
  react_1.default.createElement(react_native_1.ActivityIndicator, { size: "large", color: overlayColor }),
633
630
  mergedStrings.processing && (react_1.default.createElement(react_native_1.Text, { style: styles.processingText }, mergedStrings.processing))))));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "3.139.0",
3
+ "version": "3.142.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -5,7 +5,6 @@ import {
5
5
  Image,
6
6
  InteractionManager,
7
7
  NativeModules,
8
- Platform,
9
8
  StyleSheet,
10
9
  Text,
11
10
  TouchableOpacity,
@@ -891,7 +890,7 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
891
890
  </TouchableOpacity>
892
891
  </View>
893
892
  </View>
894
- ) : Platform.OS === 'ios' ? (
893
+ ) : (
895
894
  <View style={styles.flex}>
896
895
  <DocScanner
897
896
  key={scannerSession}
@@ -989,13 +988,6 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
989
988
  </View>
990
989
  </DocScanner>
991
990
  </View>
992
- ) : (
993
- <View style={styles.flex}>
994
- <View style={styles.processingOverlay}>
995
- <ActivityIndicator size="large" color={overlayColor} />
996
- <Text style={styles.processingText}>갤러리에서 이미지를 선택해주세요...</Text>
997
- </View>
998
- </View>
999
991
  )}
1000
992
 
1001
993
  {processing && (