react-native-rectangle-doc-scanner 0.50.0 → 0.51.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.
@@ -60,6 +60,7 @@ const CropEditor = ({ document, overlayColor = 'rgba(0,0,0,0.5)', overlayStrokeC
60
60
  width: react_native_1.Dimensions.get('window').width,
61
61
  height: react_native_1.Dimensions.get('window').height,
62
62
  });
63
+ const [isImageLoading, setIsImageLoading] = (0, react_1.useState)(true);
63
64
  // Get initial rectangle from detected quad or use default
64
65
  const getInitialRectangle = (0, react_1.useCallback)(() => {
65
66
  if (!document.quad || !imageSize) {
@@ -75,7 +76,9 @@ const CropEditor = ({ document, overlayColor = 'rgba(0,0,0,0.5)', overlayStrokeC
75
76
  }, [document.quad, document.width, document.height, imageSize]);
76
77
  const handleImageLoad = (0, react_1.useCallback)((event) => {
77
78
  const { width, height } = event.nativeEvent.source;
79
+ console.log('Image loaded with size:', { width, height });
78
80
  setImageSize({ width, height });
81
+ setIsImageLoading(false);
79
82
  }, []);
80
83
  const handleLayout = (0, react_1.useCallback)((event) => {
81
84
  const { width, height } = event.nativeEvent.layout;
@@ -95,9 +98,13 @@ const CropEditor = ({ document, overlayColor = 'rgba(0,0,0,0.5)', overlayStrokeC
95
98
  onCropChange?.(rect);
96
99
  }, [imageSize, onCropChange]);
97
100
  // Wait for image to load to get dimensions
98
- if (!imageSize) {
99
- return (react_1.default.createElement(react_native_1.View, { style: styles.container, onLayout: handleLayout },
100
- react_1.default.createElement(react_native_1.Image, { source: { uri: `file://${document.path}` }, style: styles.hiddenImage, onLoad: handleImageLoad, resizeMode: "contain" })));
101
+ if (!imageSize || isImageLoading) {
102
+ return (react_1.default.createElement(react_native_1.View, { style: [styles.container, styles.loadingContainer], onLayout: handleLayout },
103
+ react_1.default.createElement(react_native_1.Image, { source: { uri: `file://${document.path}` }, style: styles.hiddenImage, onLoad: handleImageLoad, onError: (error) => {
104
+ console.error('Image load error:', error);
105
+ setIsImageLoading(false);
106
+ }, resizeMode: "contain" }),
107
+ react_1.default.createElement(react_native_1.ActivityIndicator, { size: "large", color: handlerColor })));
101
108
  }
102
109
  return (react_1.default.createElement(react_native_1.View, { style: styles.container, onLayout: handleLayout },
103
110
  react_1.default.createElement(react_native_perspective_image_cropper_1.default, { height: displaySize.height, width: displaySize.width, image: `file://${document.path}`, rectangleCoordinates: getInitialRectangle(), overlayColor: overlayColor, overlayStrokeColor: overlayStrokeColor, handlerColor: handlerColor, enablePanStrict: enablePanStrict, onDragEnd: handleDragEnd })));
@@ -108,9 +115,14 @@ const styles = react_native_1.StyleSheet.create({
108
115
  flex: 1,
109
116
  backgroundColor: '#000',
110
117
  },
118
+ loadingContainer: {
119
+ justifyContent: 'center',
120
+ alignItems: 'center',
121
+ },
111
122
  hiddenImage: {
112
123
  width: 1,
113
124
  height: 1,
114
125
  opacity: 0,
126
+ position: 'absolute',
115
127
  },
116
128
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "0.50.0",
3
+ "version": "0.51.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {
@@ -1,5 +1,5 @@
1
1
  import React, { useState, useCallback } from 'react';
2
- import { View, StyleSheet, Image, Dimensions } from 'react-native';
2
+ import { View, StyleSheet, Image, Dimensions, ActivityIndicator } from 'react-native';
3
3
  import CustomImageCropper from 'react-native-perspective-image-cropper';
4
4
  import type { Rectangle as CropperRectangle } from 'react-native-perspective-image-cropper';
5
5
  import type { Point, Rectangle, CapturedDocument } from './types';
@@ -40,6 +40,7 @@ export const CropEditor: React.FC<CropEditorProps> = ({
40
40
  width: Dimensions.get('window').width,
41
41
  height: Dimensions.get('window').height,
42
42
  });
43
+ const [isImageLoading, setIsImageLoading] = useState(true);
43
44
 
44
45
  // Get initial rectangle from detected quad or use default
45
46
  const getInitialRectangle = useCallback((): CropperRectangle | undefined => {
@@ -66,7 +67,9 @@ export const CropEditor: React.FC<CropEditorProps> = ({
66
67
 
67
68
  const handleImageLoad = useCallback((event: any) => {
68
69
  const { width, height } = event.nativeEvent.source;
70
+ console.log('Image loaded with size:', { width, height });
69
71
  setImageSize({ width, height });
72
+ setIsImageLoading(false);
70
73
  }, []);
71
74
 
72
75
  const handleLayout = useCallback((event: any) => {
@@ -91,15 +94,20 @@ export const CropEditor: React.FC<CropEditorProps> = ({
91
94
  }, [imageSize, onCropChange]);
92
95
 
93
96
  // Wait for image to load to get dimensions
94
- if (!imageSize) {
97
+ if (!imageSize || isImageLoading) {
95
98
  return (
96
- <View style={styles.container} onLayout={handleLayout}>
99
+ <View style={[styles.container, styles.loadingContainer]} onLayout={handleLayout}>
97
100
  <Image
98
101
  source={{ uri: `file://${document.path}` }}
99
102
  style={styles.hiddenImage}
100
103
  onLoad={handleImageLoad}
104
+ onError={(error) => {
105
+ console.error('Image load error:', error);
106
+ setIsImageLoading(false);
107
+ }}
101
108
  resizeMode="contain"
102
109
  />
110
+ <ActivityIndicator size="large" color={handlerColor} />
103
111
  </View>
104
112
  );
105
113
  }
@@ -126,9 +134,14 @@ const styles = StyleSheet.create({
126
134
  flex: 1,
127
135
  backgroundColor: '#000',
128
136
  },
137
+ loadingContainer: {
138
+ justifyContent: 'center',
139
+ alignItems: 'center',
140
+ },
129
141
  hiddenImage: {
130
142
  width: 1,
131
143
  height: 1,
132
144
  opacity: 0,
145
+ position: 'absolute',
133
146
  },
134
147
  });