react-native-rectangle-doc-scanner 0.25.0 → 0.26.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.
@@ -52,16 +52,40 @@ const Overlay = ({ quad, color = '#e7a649', frameSize }) => {
52
52
  console.log('[Overlay] screen dimensions:', screenWidth, 'x', screenHeight);
53
53
  console.log('[Overlay] frame dimensions:', frameSize.width, 'x', frameSize.height);
54
54
  }
55
- // Transform coordinates from camera frame space to screen space
56
- const scaleX = screenWidth / frameSize.width;
57
- const scaleY = screenHeight / frameSize.height;
55
+ // Check if camera is in landscape mode (width > height) but screen is portrait (height > width)
56
+ const isFrameLandscape = frameSize.width > frameSize.height;
57
+ const isScreenPortrait = screenHeight > screenWidth;
58
+ const needsRotation = isFrameLandscape && isScreenPortrait;
58
59
  if (__DEV__) {
59
- console.log('[Overlay] scale factors:', scaleX, 'x', scaleY);
60
+ console.log('[Overlay] needs rotation:', needsRotation);
61
+ }
62
+ let transformedQuad;
63
+ if (needsRotation) {
64
+ // Camera is landscape, screen is portrait - need to rotate 90 degrees
65
+ // Transform: rotate 90° clockwise and scale
66
+ // New coordinates: x' = y * (screenWidth / frameHeight), y' = (frameWidth - x) * (screenHeight / frameWidth)
67
+ const scaleX = screenWidth / frameSize.height;
68
+ const scaleY = screenHeight / frameSize.width;
69
+ if (__DEV__) {
70
+ console.log('[Overlay] rotation scale factors:', scaleX, 'x', scaleY);
71
+ }
72
+ transformedQuad = quad.map((p) => ({
73
+ x: p.y * scaleX,
74
+ y: (frameSize.width - p.x) * scaleY,
75
+ }));
76
+ }
77
+ else {
78
+ // Same orientation - just scale
79
+ const scaleX = screenWidth / frameSize.width;
80
+ const scaleY = screenHeight / frameSize.height;
81
+ if (__DEV__) {
82
+ console.log('[Overlay] scale factors:', scaleX, 'x', scaleY);
83
+ }
84
+ transformedQuad = quad.map((p) => ({
85
+ x: p.x * scaleX,
86
+ y: p.y * scaleY,
87
+ }));
60
88
  }
61
- const transformedQuad = quad.map((p) => ({
62
- x: p.x * scaleX,
63
- y: p.y * scaleY,
64
- }));
65
89
  if (__DEV__) {
66
90
  console.log('[Overlay] transformed quad:', transformedQuad);
67
91
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "0.25.0",
3
+ "version": "0.26.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {
@@ -27,18 +27,46 @@ export const Overlay: React.FC<OverlayProps> = ({ quad, color = '#e7a649', frame
27
27
  console.log('[Overlay] frame dimensions:', frameSize.width, 'x', frameSize.height);
28
28
  }
29
29
 
30
- // Transform coordinates from camera frame space to screen space
31
- const scaleX = screenWidth / frameSize.width;
32
- const scaleY = screenHeight / frameSize.height;
30
+ // Check if camera is in landscape mode (width > height) but screen is portrait (height > width)
31
+ const isFrameLandscape = frameSize.width > frameSize.height;
32
+ const isScreenPortrait = screenHeight > screenWidth;
33
+ const needsRotation = isFrameLandscape && isScreenPortrait;
33
34
 
34
35
  if (__DEV__) {
35
- console.log('[Overlay] scale factors:', scaleX, 'x', scaleY);
36
+ console.log('[Overlay] needs rotation:', needsRotation);
36
37
  }
37
38
 
38
- const transformedQuad = quad.map((p) => ({
39
- x: p.x * scaleX,
40
- y: p.y * scaleY,
41
- }));
39
+ let transformedQuad: Point[];
40
+
41
+ if (needsRotation) {
42
+ // Camera is landscape, screen is portrait - need to rotate 90 degrees
43
+ // Transform: rotate 90° clockwise and scale
44
+ // New coordinates: x' = y * (screenWidth / frameHeight), y' = (frameWidth - x) * (screenHeight / frameWidth)
45
+ const scaleX = screenWidth / frameSize.height;
46
+ const scaleY = screenHeight / frameSize.width;
47
+
48
+ if (__DEV__) {
49
+ console.log('[Overlay] rotation scale factors:', scaleX, 'x', scaleY);
50
+ }
51
+
52
+ transformedQuad = quad.map((p) => ({
53
+ x: p.y * scaleX,
54
+ y: (frameSize.width - p.x) * scaleY,
55
+ }));
56
+ } else {
57
+ // Same orientation - just scale
58
+ const scaleX = screenWidth / frameSize.width;
59
+ const scaleY = screenHeight / frameSize.height;
60
+
61
+ if (__DEV__) {
62
+ console.log('[Overlay] scale factors:', scaleX, 'x', scaleY);
63
+ }
64
+
65
+ transformedQuad = quad.map((p) => ({
66
+ x: p.x * scaleX,
67
+ y: p.y * scaleY,
68
+ }));
69
+ }
42
70
 
43
71
  if (__DEV__) {
44
72
  console.log('[Overlay] transformed quad:', transformedQuad);