react-native-expo-cropper 1.2.37 → 1.2.39
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.
- package/dist/CustomCamera.js +72 -32
- package/dist/ImageCropper.js +952 -954
- package/dist/ImageCropperStyles.js +31 -5
- package/package.json +1 -1
- package/src/CustomCamera.js +76 -27
- package/src/ImageCropper.js +874 -887
- package/src/ImageCropperStyles.js +27 -4
package/dist/CustomCamera.js
CHANGED
|
@@ -97,6 +97,9 @@ function CustomCamera(_ref) {
|
|
|
97
97
|
// ✅ CRITICAL FIX: Calculate green frame coordinates relative to camera preview
|
|
98
98
|
// The green frame should be calculated on the wrapper (as it's visually drawn there)
|
|
99
99
|
// But we store it with wrapper dimensions so ImageCropper can map it correctly
|
|
100
|
+
//
|
|
101
|
+
// NOTE: Camera capture aspect ratio (typically 4:3) may differ from wrapper aspect ratio (9:16)
|
|
102
|
+
// This is handled in ImageCropper by using "cover" mode to match preview content
|
|
100
103
|
var calculateGreenFrameCoordinates = function calculateGreenFrameCoordinates() {
|
|
101
104
|
var wrapperWidth = cameraWrapperLayout.width;
|
|
102
105
|
var wrapperHeight = cameraWrapperLayout.height;
|
|
@@ -105,10 +108,9 @@ function CustomCamera(_ref) {
|
|
|
105
108
|
return null;
|
|
106
109
|
}
|
|
107
110
|
|
|
108
|
-
// ✅
|
|
109
|
-
|
|
110
|
-
var
|
|
111
|
-
var frameHeight = wrapperHeight * 0.80; // 80% height
|
|
111
|
+
// ✅ Calculate green frame as percentage of WRAPPER
|
|
112
|
+
var frameWidth = wrapperWidth * 0.85; // 85% of wrapper width
|
|
113
|
+
var frameHeight = wrapperHeight * 0.70; // 70% of wrapper height
|
|
112
114
|
var frameX = (wrapperWidth - frameWidth) / 2; // Centered horizontally
|
|
113
115
|
var frameY = (wrapperHeight - frameHeight) / 2; // Centered vertically
|
|
114
116
|
|
|
@@ -122,8 +124,9 @@ function CustomCamera(_ref) {
|
|
|
122
124
|
// ✅ Store percentages for easier mapping later
|
|
123
125
|
percentX: frameX / wrapperWidth * 100,
|
|
124
126
|
percentY: frameY / wrapperHeight * 100,
|
|
125
|
-
percentWidth:
|
|
126
|
-
|
|
127
|
+
percentWidth: 85,
|
|
128
|
+
// 85% of wrapper width
|
|
129
|
+
percentHeight: 70 // 70% of wrapper height
|
|
127
130
|
};
|
|
128
131
|
console.log("✅ Green frame coordinates calculated:", frameCoords);
|
|
129
132
|
return frameCoords;
|
|
@@ -139,12 +142,12 @@ function CustomCamera(_ref) {
|
|
|
139
142
|
}, [cameraWrapperLayout]);
|
|
140
143
|
var takePicture = /*#__PURE__*/function () {
|
|
141
144
|
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
|
|
142
|
-
var photo,
|
|
145
|
+
var captureOptions, photo, capturedAspectRatio, greenFrameCoords, _t;
|
|
143
146
|
return _regenerator().w(function (_context2) {
|
|
144
147
|
while (1) switch (_context2.p = _context2.n) {
|
|
145
148
|
case 0:
|
|
146
149
|
if (!cameraRef.current) {
|
|
147
|
-
_context2.n =
|
|
150
|
+
_context2.n = 7;
|
|
148
151
|
break;
|
|
149
152
|
}
|
|
150
153
|
_context2.p = 1;
|
|
@@ -157,54 +160,87 @@ function CustomCamera(_ref) {
|
|
|
157
160
|
_context2.n = 2;
|
|
158
161
|
return waitForRender(2);
|
|
159
162
|
case 2:
|
|
160
|
-
|
|
161
|
-
|
|
163
|
+
// ✅ OPTIMIZED: Capture with maximum quality and native camera ratio
|
|
164
|
+
// Platform-specific optimizations for best quality
|
|
165
|
+
captureOptions = _objectSpread(_objectSpread({
|
|
166
|
+
// Maximum quality (0-1, 1 = best quality, no compression)
|
|
162
167
|
quality: 1,
|
|
163
|
-
//
|
|
168
|
+
// Disable shutter sound for better UX
|
|
164
169
|
shutterSound: false,
|
|
165
|
-
//
|
|
166
|
-
//
|
|
170
|
+
// ✅ CRITICAL: skipProcessing preserves original resolution and avoids interpolation
|
|
171
|
+
// This ensures pixel-perfect quality and prevents premature resizing
|
|
167
172
|
skipProcessing: true,
|
|
168
|
-
//
|
|
169
|
-
// L'orientation sera gérée dans ImageCropper si nécessaire via la fonction de rotation
|
|
173
|
+
// Include EXIF metadata (orientation, camera settings, etc.)
|
|
170
174
|
exif: true
|
|
175
|
+
}, _reactNative.Platform.OS === 'ios' && {
|
|
176
|
+
// iOS: Use native capture format (typically 4:3 or 16:9 depending on device)
|
|
177
|
+
// No additional processing to preserve quality
|
|
178
|
+
}), _reactNative.Platform.OS === 'android' && {
|
|
179
|
+
// Android: Ensure maximum resolution capture
|
|
180
|
+
// skipProcessing already handles this, but we can add Android-specific options if needed
|
|
181
|
+
});
|
|
182
|
+
console.log("📸 Capturing photo with maximum quality settings:", {
|
|
183
|
+
platform: _reactNative.Platform.OS,
|
|
184
|
+
options: captureOptions,
|
|
185
|
+
wrapperSize: {
|
|
186
|
+
width: cameraWrapperLayout.width,
|
|
187
|
+
height: cameraWrapperLayout.height
|
|
188
|
+
}
|
|
171
189
|
});
|
|
190
|
+
_context2.n = 3;
|
|
191
|
+
return cameraRef.current.takePictureAsync(captureOptions);
|
|
172
192
|
case 3:
|
|
173
193
|
photo = _context2.v;
|
|
174
|
-
|
|
194
|
+
if (!(!photo.width || !photo.height || photo.width === 0 || photo.height === 0)) {
|
|
195
|
+
_context2.n = 4;
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
throw new Error("Invalid photo dimensions received from camera");
|
|
199
|
+
case 4:
|
|
200
|
+
capturedAspectRatio = photo.width / photo.height;
|
|
201
|
+
console.log("✅ Photo captured with maximum quality:", {
|
|
175
202
|
uri: photo.uri,
|
|
176
203
|
width: photo.width,
|
|
177
204
|
height: photo.height,
|
|
178
|
-
|
|
205
|
+
aspectRatio: capturedAspectRatio.toFixed(3),
|
|
206
|
+
expectedRatio: "~1.33 (4:3) or ~1.78 (16:9)",
|
|
207
|
+
exif: photo.exif ? "present" : "missing",
|
|
208
|
+
fileSize: photo.uri ? "available" : "unknown"
|
|
179
209
|
});
|
|
180
210
|
|
|
181
211
|
// ✅ CRITICAL FIX: Use the same green frame coordinates that are used for rendering
|
|
182
212
|
// Fallback to recalculation if, for some reason, state is not yet set
|
|
183
|
-
greenFrameCoords = greenFrame || calculateGreenFrameCoordinates();
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
213
|
+
greenFrameCoords = greenFrame || calculateGreenFrameCoordinates();
|
|
214
|
+
if (greenFrameCoords) {
|
|
215
|
+
_context2.n = 5;
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
throw new Error("Green frame coordinates not available");
|
|
219
|
+
case 5:
|
|
220
|
+
// ✅ Send photo URI and frame data to ImageCropper
|
|
221
|
+
// The photo maintains its native resolution and aspect ratio
|
|
222
|
+
// ImageCropper will handle display and cropping while preserving quality
|
|
223
|
+
onPhotoCaptured(photo.uri, {
|
|
189
224
|
greenFrame: greenFrameCoords,
|
|
190
225
|
capturedImageSize: {
|
|
191
226
|
width: photo.width,
|
|
192
|
-
height: photo.height
|
|
227
|
+
height: photo.height,
|
|
228
|
+
aspectRatio: capturedAspectRatio
|
|
193
229
|
}
|
|
194
230
|
});
|
|
195
231
|
setLoadingBeforeCapture(false);
|
|
196
|
-
_context2.n =
|
|
232
|
+
_context2.n = 7;
|
|
197
233
|
break;
|
|
198
|
-
case
|
|
199
|
-
_context2.p =
|
|
234
|
+
case 6:
|
|
235
|
+
_context2.p = 6;
|
|
200
236
|
_t = _context2.v;
|
|
201
|
-
console.error("Error capturing photo:", _t);
|
|
237
|
+
console.error("❌ Error capturing photo:", _t);
|
|
202
238
|
setLoadingBeforeCapture(false);
|
|
203
|
-
_reactNative.Alert.alert("Erreur", "Impossible de capturer la photo. Veuillez
|
|
204
|
-
case
|
|
239
|
+
_reactNative.Alert.alert("Erreur", "Impossible de capturer la photo: ".concat(_t.message || "Erreur inconnue", ". Veuillez r\xE9essayer."));
|
|
240
|
+
case 7:
|
|
205
241
|
return _context2.a(2);
|
|
206
242
|
}
|
|
207
|
-
}, _callee2, null, [[1,
|
|
243
|
+
}, _callee2, null, [[1, 6]]);
|
|
208
244
|
}));
|
|
209
245
|
return function takePicture() {
|
|
210
246
|
return _ref3.apply(this, arguments);
|
|
@@ -230,8 +266,12 @@ function CustomCamera(_ref) {
|
|
|
230
266
|
facing: "back",
|
|
231
267
|
ref: cameraRef,
|
|
232
268
|
onCameraReady: function onCameraReady() {
|
|
233
|
-
|
|
269
|
+
setIsReady(true);
|
|
270
|
+
console.log("✅ Camera ready - Maximum quality capture enabled");
|
|
234
271
|
}
|
|
272
|
+
// ✅ Ensure camera uses native aspect ratio (typically 4:3 for most devices)
|
|
273
|
+
// The wrapper constrains the view, but capture uses full sensor resolution
|
|
274
|
+
// This ensures preview matches what will be captured
|
|
235
275
|
}), loadingBeforeCapture && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_reactNative.View, {
|
|
236
276
|
style: styles.loadingOverlay
|
|
237
277
|
}, /*#__PURE__*/_react["default"].createElement(_reactNative.Image, {
|